From fc6a55187a4c118e95f0ec4169b009194860114b Mon Sep 17 00:00:00 2001 From: Arne Zachlod Date: Mon, 10 Mar 2025 17:08:19 +0100 Subject: [PATCH] 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 --- main.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index c49aaa9..e59a205 100755 --- a/main.py +++ b/main.py @@ -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():