Skip to content

Commit

Permalink
add health message
Browse files Browse the repository at this point in the history
  • Loading branch information
Seth10001 committed Jul 14, 2024
1 parent 5350b4a commit 5d80508
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
4 changes: 4 additions & 0 deletions telemetry-collector/ecosystem.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
}
13 changes: 13 additions & 0 deletions telemetry-collector/src/python/is_alive.py
Original file line number Diff line number Diff line change
@@ -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)
6 changes: 0 additions & 6 deletions telemetry-collector/src/python/local_uart.py

This file was deleted.

18 changes: 18 additions & 0 deletions telemetry-collector/src/python/udp.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 5d80508

Please sign in to comment.