🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Debugging HTTP requests

    Micropython
    1
    1
    973
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • L
      led.by.the.led
      last edited by

      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] ENOMEM is the exception printed in the except block

      The 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.
      1 Reply Last reply Reply Quote 0
      • First post
        Last post