UIFlow 2.0.1 HTTP GET and parse JSON



  • Hi team,

    I'm trying to complete the simplest of all possible projects, and for the life of me after two days of troubleshooting I simply can't figure it out.

    Device: Core2
    OS: Mac OS 14.2.1
    Software: UIFlow v2.0.1

    I'm trying to HTTP GET a local JSON endpoint with some data.

    I started off trying to program this with the visual interface, but found that I quickly had to switch to python because of the missing 'urequests' lib (there's another thread about that on this forum).

    Using the 'requests' library, I found that I can perform the GET request and actually get a 200 status OK back. However, when using the response.json() call, the program hangs with no error and no output.

    If I run the same requests in python3 on my desktop environment, it all works.

    Here's where I got to:

    import os, sys, io
    import M5
    from M5 import *
    import network
    import requests
    
    title0 = None
    statTitle = None
    resTitle = None
    stat = None
    res = None
    # http_req = None
    wlan = None
    
    
    status = None
    
    def setup():
      global title0, statTitle, resTitle, stat, res, http_req, wlan, status
    
      M5.begin()
      Widgets.fillScreen(0x222222)
      title0 = Widgets.Title("Powermonitor", 3, 0xffffff, 0x0000FF, Widgets.FONTS.DejaVu18)
      statTitle = Widgets.Label("Status:", 2, 28, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu18)
      resTitle = Widgets.Label("Response:", 2, 57, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu18)
      stat = Widgets.Label("...", 110, 29, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu18)
      res = Widgets.Label("...", 111, 57, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu18)
    
      stat.setText(str('Fetching'))
      http_req = requests.get('http://192.168.10.22/api/v1/data')
      status = http_req.status_code
      stat.setText(str(status))
      print(str(http_req.status_code))
      print(str(http_req.reason))
      print(str(http_req.encoding))
      # print(str(http_req.raw))
      # print(str(http_req.text()))
      data = http_req.json()
      print(str(data))
      # print(str(http_req.json()))
      # http_req.close()
      # print(dir(responseJson))
      # print(responseJson())
      # res.setText(str(http_req.json()))
    
    
    def loop():
      global title0, statTitle, resTitle, stat, res, http_req, wlan, status
      M5.update()
    
    
    if __name__ == '__main__':
      try:
        setup()
        while True:
          loop()
      except (Exception, KeyboardInterrupt) as e:
        try:
          from utility import print_error_msg
          print_error_msg(e)
        except ImportError:
          print("please update to latest firmware")```


  • Are you sure its hanging and not taking ages to get a response?



  • Yes, the endpoint responds almost instantly. Also the status code immediately comes back as as '200'.