diff --git a/lambda/ham_listener_put/__init__.py b/lambda/ham_listener_put/__init__.py index fb9c061..1a3767e 100644 --- a/lambda/ham_listener_put/__init__.py +++ b/lambda/ham_listener_put/__init__.py @@ -16,6 +16,8 @@ import es # Setup SNS +TOPIC = config_handler.get("SNS","TOPIC") + def set_connection_header(request, operation_name, **kwargs): request.headers['Connection'] = 'keep-alive' @@ -28,7 +30,7 @@ def post(payload): f.write(json.dumps(payload).encode('utf-8')) payload = base64.b64encode(compressed.getvalue()).decode("utf-8") sns.publish( - TopicArn=config_handler.get("SNS","TOPIC"), + TopicArn=TOPIC, Message=payload ) diff --git a/lambda/ham_put_api/__init__.py b/lambda/ham_put_api/__init__.py index fad5f1b..cdb251c 100644 --- a/lambda/ham_put_api/__init__.py +++ b/lambda/ham_put_api/__init__.py @@ -13,6 +13,8 @@ def set_connection_header(request, operation_name, **kwargs): sns = boto3.client("sns",region_name="us-east-1") sns.meta.events.register('request-created.sns', set_connection_header) +TOPIC = config_handler.get("HAM_SNS","TOPIC") + def check_fields_are_number(field, telemetry): if type(telemetry[field]) != float and type(telemetry[field]) != int: return (False, f"{field} should not be a float") @@ -47,7 +49,7 @@ def telemetry_hide_filter(telemetry): def post(payload): sns.publish( - TopicArn=config_handler.get("HAM_SNS","TOPIC"), + TopicArn=TOPIC, Message=json.dumps(payload) ) diff --git a/lambda/sns_to_mqtt/__init__.py b/lambda/sns_to_mqtt/__init__.py index 4ce626a..61cd426 100644 --- a/lambda/sns_to_mqtt/__init__.py +++ b/lambda/sns_to_mqtt/__init__.py @@ -13,6 +13,10 @@ import sys import uuid import config_handler +MQTT_ID = config_handler.get("MQTT","ID") +MQTT_PREFIX = config_handler.get("MQTT","PREFIX") +MQTT_BATCH = config_handler.get("MQTT","BATCH") + client = mqtt.Client(transport="websockets") connected_flag = False @@ -120,18 +124,18 @@ def lambda_handler(event, context): body = json.dumps(payload) - serial = payload[config_handler.get("MQTT","ID")] + serial = payload[MQTT_ID] while not connected_flag: time.sleep(0.01) # wait until connected client.publish( - topic=f'{config_handler.get("MQTT","PREFIX")}/{serial}', + topic=f'{MQTT_PREFIX}/{serial}', payload=body, qos=0, retain=False ) if serial not in cache: # low bandwidth feeds with just the first packet client.publish( - topic=f'{config_handler.get("MQTT","PREFIX")}-new/{serial}', + topic=f'{MQTT_PREFIX}-new/{serial}', payload=body, qos=0, retain=False @@ -141,7 +145,7 @@ def lambda_handler(event, context): while len(cache) > MAX_CACHE: del cache[next(iter(cache))] client.publish( - topic=config_handler.get("MQTT","BATCH"), + topic=MQTT_BATCH, payload=json.dumps(payloads), qos=0, retain=False diff --git a/lambda/sonde_api_to_iot_core/__init__.py b/lambda/sonde_api_to_iot_core/__init__.py index 5557812..d5ed63a 100644 --- a/lambda/sonde_api_to_iot_core/__init__.py +++ b/lambda/sonde_api_to_iot_core/__init__.py @@ -22,6 +22,8 @@ import config_handler logs = boto3.client('logs') sequenceToken = None +TOPIC = config_handler.get("SNS","TOPIC") + def set_connection_header(request, operation_name, **kwargs): request.headers['Connection'] = 'keep-alive' @@ -368,7 +370,7 @@ def post(payload): f.write(json.dumps(payload).encode('utf-8')) payload = base64.b64encode(compressed.getvalue()).decode("utf-8") sns.publish( - TopicArn=config_handler.get("SNS","TOPIC"), + TopicArn=TOPIC, Message=payload ) diff --git a/lambda/station_api_to_iot_core/__init__.py b/lambda/station_api_to_iot_core/__init__.py index fa28e37..afc720a 100644 --- a/lambda/station_api_to_iot_core/__init__.py +++ b/lambda/station_api_to_iot_core/__init__.py @@ -14,6 +14,8 @@ CALLSIGN_BLOCK_LIST = ["CHANGEME_RDZTTGO"] import es +TOPIC = config_handler.get("SNS","TOPIC") + # Setup SNS def set_connection_header(request, operation_name, **kwargs): @@ -28,7 +30,7 @@ def post(payload): f.write(json.dumps(payload).encode('utf-8')) payload = base64.b64encode(compressed.getvalue()).decode("utf-8") sns.publish( - TopicArn=config_handler.get("SNS","TOPIC"), + TopicArn=TOPIC, Message=payload ) diff --git a/lambda/ttn_helium/__init__.py b/lambda/ttn_helium/__init__.py index 5fe53d4..3dae54c 100644 --- a/lambda/ttn_helium/__init__.py +++ b/lambda/ttn_helium/__init__.py @@ -7,6 +7,8 @@ from email.utils import parsedate import os import config_handler +TOPIC = config_handler.get("HAM_SNS","TOPIC") + HELIUM_GW_VERSION = "2023.10.14" # Mappings between input (Helium) field names, and field names fed into SondeHub-Amateur @@ -47,7 +49,7 @@ sns.meta.events.register('request-created.sns', set_connection_header) def post(payload): sns.publish( - TopicArn=config_handler.get("HAM_SNS","TOPIC"), + TopicArn=TOPIC, Message=json.dumps(payload) )