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:
parent
4de729985b
commit
fc6a55187a
1 changed files with 23 additions and 1 deletions
24
main.py
24
main.py
|
|
@ -22,7 +22,7 @@ from machine import WDT
|
||||||
from machine import reset
|
from machine import reset
|
||||||
from sdcard import SDCard
|
from sdcard import SDCard
|
||||||
|
|
||||||
DEBUG = False
|
DEBUG = True
|
||||||
# set True for debug output
|
# set True for debug output
|
||||||
|
|
||||||
BUF_POS = 0
|
BUF_POS = 0
|
||||||
|
|
@ -188,6 +188,9 @@ def exec_cmd(json_cmd):
|
||||||
exec_uota(cmd)
|
exec_uota(cmd)
|
||||||
elif cmd['cmd'] == "reset":
|
elif cmd['cmd'] == "reset":
|
||||||
exec_reset(cmd)
|
exec_reset(cmd)
|
||||||
|
elif cmd['cmd'] == "telemetry":
|
||||||
|
exec_telemetry(cmd)
|
||||||
|
|
||||||
|
|
||||||
def exec_rtc(cmd):
|
def exec_rtc(cmd):
|
||||||
global RTC0
|
global RTC0
|
||||||
|
|
@ -284,6 +287,25 @@ def exec_uota(cmd):
|
||||||
uota.install_new_firmware()
|
uota.install_new_firmware()
|
||||||
reset()
|
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():
|
def control():
|
||||||
"""main control loop"""
|
"""main control loop"""
|
||||||
if UART0.any():
|
if UART0.any():
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue