Debugging HTTP requests
-
I've been trying to make a simple HTTP request with my Atom Matrix.
I want to implement:A single Button Click sends a HTTP request and shows me the success or error state via the Matrix LEDs
But my problem is that the request seems to fail consistently and I couldn't print any information about the actual request. It seems as if it fails before or while executing the request. I was able to print the exception thrown:
[Errno 12] ENOMEM
Which looks like the Atom ran out of memory. But I'm confused why? The whole code snippet is already pretty small and barely does anything.from m5stack import * from m5ui import * from uiflow import * import wifiCfg import urequests gc.collect() rgb.set_screen([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]) def buttonA_wasPressed(): # global params wifiCfg.autoConnect(lcdShow=False) if wifiCfg.wlan_sta.isconnected(): try: print(urequests.request) req = urequests.request(method='GET', url='https://dummyjson.com/products/1', headers={}) print(req.text) print("stuff never get executed") # Show some green lights indicating success state rgb.set_screen([0x03ff33,0,0,0,0,0x03ff33,0,0,0x00ff33,0,0,0x03ff33,0x00bd26,0x00ff33,0,0,0x03ff33,0x00ff33,0x00ff33,0x03ff33,0,0,0x03ff33,0x03ff33,0x03ff33]) gc.collect() req.close() except Exception as e: print('Failed') print(str(e)) # Show some red lights indicating error state rgb.set_screen([0,0,0,0,0,0,0,0,0xff0000,0,0,0xff0000,0x9e0000,0xff0000,0,0,0xff0000,0xff0000,0xff0000,0xff0000,0,0,0xff0000,0xff0000,0xff0000]) pass btnA.wasPressed(buttonA_wasPressed)This is the log after pushing the button on my Atom Matrix
<function request at 0x3ffe7220> Failed [Errno 12] ENOMEM<function request at 0x3ffe7220>proves that (some) request function is loaded
[Errno 12] ENOMEMis the exception printed in the except blockThe Issue is clearly related to the request because if I remove the request, the success case is executed (green light etc.)
... try: print(urequests.request) #req = urequests.request(method='GET', url='https://dummyjson.com/products/1', headers={}) #print(req.text) print("stuff never get executed") # Show some green lights indicating success state rgb.set_screen([0x03ff33,0,0,0,0,0x03ff33,0,0,0x00ff33,0,0,0x03ff33,0x00bd26,0x00ff33,0,0,0x03ff33,0x00ff33,0x00ff33,0x03ff33,0,0,0x03ff33,0x03ff33,0x03ff33]) gc.collect() #req.close() ...Context:
- I flashed the device with UIFlow_Matrix v1.12.9 (latest)
- I'm using Arduino Lab for Micropython to upload and execute code on the Atom Matrix because I found it to be the most reliable connection over USB and giving me a fast response through the console.
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