main.py: telemetry: simple telemetry transfer

in order to transfer telemetry to the server a command must be sent:

cmd: telemetry
wlan_ssid: ssid for wlan
wlan_password (optional): wlan password
telemetry_server: server base URL where to send telemetry data

currently, we send the MAC address of the microcontroller as well as the
installed version, read from the version file
This commit is contained in:
Arne Zachlod 2025-03-10 17:08:19 +01:00
parent 4de729985b
commit fc6a55187a

24
main.py
View file

@ -22,7 +22,7 @@ from machine import WDT
from machine import reset
from sdcard import SDCard
DEBUG = False
DEBUG = True
# set True for debug output
BUF_POS = 0
@ -188,6 +188,9 @@ def exec_cmd(json_cmd):
exec_uota(cmd)
elif cmd['cmd'] == "reset":
exec_reset(cmd)
elif cmd['cmd'] == "telemetry":
exec_telemetry(cmd)
def exec_rtc(cmd):
global RTC0
@ -284,6 +287,25 @@ def exec_uota(cmd):
uota.install_new_firmware()
reset()
def exec_telemetry(cmd):
# options:
# wlan_ssid
# wlan_password - optional
# telemetry_server
prepare_lowmem()
setup_wdt(300)
network_connect(cmd)
import requests
f = open('version', 'r')
VERSION = f.read().strip()
from machine import unique_id
MACADDR = unique_id().hex()
debug(f"MACADDR: {MACADDR}")
URL = cmd['telemetry_server'] + '/' + VERSION + '/' + MACADDR
debug(f"telemetry URL: {URL}")
r = requests.request("GET", URL, timeout=60)
reset()
def control():
"""main control loop"""
if UART0.any():