You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am asking because it seems to send back a 200 response with the content being ok regardless of whether I send the correct or incorrect API key.
I am working on a more robust micropython client, and have gotten to the point of actually making the API call to Emon CMS.
frommachineimportUART, Pinfromtimeimportsleep# UART configuration ---------------------------------------------------------# default timeout for uart.any() to decide if a new line is coming is 0 (ms).# increase to 1 (ms) to give emon time to send the next line.# sending output to uart1 is optional - for debugging# required to debug because if the micro-usb cable is plugged to pico# the power cannot simultaneously be connected to emon (3.3V vs 5V)uart0=UART(0, timeout=1) # pins GP0/GP1uart1=UART(1) # pins GP4/GP5defblink_led(times_to_blink):
# assumptionsled=Pin('LED', Pin.OUT)
a_brief_moment=.1# start with the led offled.value(0)
for_inrange(times_to_blink):
# turn on and waitled.toggle()
sleep(a_brief_moment)
# turn back off and waitled.toggle()
sleep(a_brief_moment)
defprocess_line():
line=read_line()
trimmed_line=line.strip()
# for now just write output to console and outgoing uartuart1.write(line)
print(trimmed_line)
# trimmed line looks something like:# MSG:540,Vrms:240.00,P1:2,P2:6,P3:6,P4:5,P5:5,P6:4,E1:3,E2:10,E3:10,E4:8,E5:8,E6:7,pulse:0# TODO: Make a correct API calldefread_line():
try:
# get input until a newline character is reached (or the uart's configured timeout_char expires)incoming_line=uart0.readline()
ifincoming_lineisNone:
# blink thrice to signal an errorblink_led(3)
return('Readline Error: No Input')
# return the line in string formatreturnincoming_line.decode('utf-8')
exceptUnicodeError:
# blink thrice to signal an errorblink_led(3)
return('Unicode Error: '+str(incoming_line))
defmain():
whileTrue:
# if one or more lines of incoming data are availableifuart0.any():
# while there is still data availablewhileuart0.any():
# process the next line of dataprocess_line()
# blink once to signal that line(s) came inblink_led(1)
else:
# blink twice to signal that nothing came inblink_led(2)
# wait a few secondssleep(2)
The text was updated successfully, but these errors were encountered:
Is this line just a sample/placeholder, or is it actually supposed to send valid requests to Emon CMS?
Link to File
I am asking because it seems to send back a 200 response with the content being
ok
regardless of whether I send the correct or incorrect API key.I am working on a more robust micropython client, and have gotten to the point of actually making the API call to Emon CMS.
The text was updated successfully, but these errors were encountered: