Serial to UART POST JSON
-
Hi All,
I have a weigh station transmitting weight data via RS232, I have connected this to UART1 pins 3 & 4 pins via TTL and I can receive ASCII string and print this using the
print("Weight POST Successful - " + str(uart1.readall()) + " g")
however when i use the same to print into a JSON payload it prints none.
Here is the code
while True:
res = urequests.post('https://My_URL', json={'Weight': str(uart1.readall())}) res.close() if (res.status_code - 200) < 100: # check that response code is in the 200 range print("Weight POST Successful - " + str(uart1.readall()) + " g") else: print('there was some error') gc.collect() pycom.heartbeat(False) -
@jimpower
Do you mean thatprint("Weight POST Successful - " + str(uart1.readall()) + " g")does not print anything
or
res = urequests.post('https://My_URL', json={'Weight': str(uart1.readall())})does not send anything? or both?
You must know that
uart1.readall()clear buffer and seconduart1.readall()read nothing (or new incomming data)
you must store data into var to use it in second printe.g.
tmp = uart1.readall() -
res = urequests.post('https://My_URL', json={'Weight': str(uart1.readall())})
sends none
print("Weight POST Successful - " + str(uart1.readall()) + " g")
prints as expected
the second print is only to see what is coming through in terminal I can remove it as its not required.
If I were to use it as you suggest would it look like this?
while True:
tmp = uart1.readall()
res = urequests.post('https://My_URL', json={'Weight': str(tmp())})
res.close()
if (res.status_code - 200) < 100: # check that response code is in the 200 range
print("Weight POST Successful - " + str(tmp()) + " g")
else:
print('there was some error')gc.collect()
pycom.heartbeat(False) -
-
I added tmp = uart1.readall() and it works thanks again I managed to do this before your reply thanks again you are always very helpful
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login