diff --git a/telemetry-collector/ecosystem.config.js b/telemetry-collector/ecosystem.config.js index 297ea41..5db4bc7 100644 --- a/telemetry-collector/ecosystem.config.js +++ b/telemetry-collector/ecosystem.config.js @@ -20,6 +20,10 @@ module.exports = { "EXTERNAL_UDP_HOST": "ufsolargators.org", "UART_PORT": "/tmp/uart", } + }, + { + name: "pi_health", + script: "python src/python/is_alive.py" } ] } diff --git a/telemetry-collector/src/python/is_alive.py b/telemetry-collector/src/python/is_alive.py new file mode 100644 index 0000000..aa1a230 --- /dev/null +++ b/telemetry-collector/src/python/is_alive.py @@ -0,0 +1,13 @@ +"""Basic script that sends PI diagnostic info""" + +import time +from udp import send_tlm + +DELAY_TIME = 5 + +while 1: + print("sending alive message") + send_tlm({ + "model": "pi/alive" + }) + time.sleep(5) diff --git a/telemetry-collector/src/python/local_uart.py b/telemetry-collector/src/python/local_uart.py deleted file mode 100644 index 55d5db0..0000000 --- a/telemetry-collector/src/python/local_uart.py +++ /dev/null @@ -1,6 +0,0 @@ -import uart - -while 1: - print( - uart.wait_for_transmission() - ) diff --git a/telemetry-collector/src/python/udp.py b/telemetry-collector/src/python/udp.py new file mode 100644 index 0000000..d7b68f3 --- /dev/null +++ b/telemetry-collector/src/python/udp.py @@ -0,0 +1,18 @@ +import os, socket, json + +INTERNAL_UDP_PORT = os.environ.get("INTERNAL_UDP_PORT", "8000") +INTERNAL_UDP_HOST = os.environ.get("INTERNAL_UDP_HOST", "localhost") +EXTERNAL_UDP_PORT = os.environ.get("EXTERNAL_UDP_PORT", "8000") +EXTERNAL_UDP_HOST = os.environ.get("EXTERNAL_UDP_HOST", "api.ufsolargators.org") + +sock = socket.socket(socket.AF_INET, # Internet + socket.SOCK_DGRAM) # UDP + +def send_tlm(data): + data = json.dumps(data).encode() + sock.sendto(data, (INTERNAL_UDP_HOST, int(INTERNAL_UDP_PORT))) + # Try to send to external server, but if it fails then ignore it + try: + sock.sendto(data, (EXTERNAL_UDP_HOST, int(EXTERNAL_UDP_PORT))) + except socket.error: + pass