Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    LoPy4 problem using HTTP requests

    Scheduled Pinned Locked Moved LoPy
    6 Posts 3 Posters 51 Views 3 Watching
    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 Offline
      Liudmila Dobriakova
      last edited by Liudmila Dobriakova

      i'm trying to send the data from my LoPy4 board through Wi-Fi connection. I can get the socket library, but it seems to have a problem connecting to my service. it is running behind a firewall, so the domain name is resolved to IP in a wrong manner. So i was wondering is using urequests will solve the issue. But I can't install urequests on my LoPy4 board. Can't import upip neather. ImportError: no module named 'upip'. What i'm doing wrong?

      D 1 Reply Last reply Reply Quote 0
      • D Offline
        Developer Pydro @Liudmila Dobriakova
        last edited by

        @Liudmila-Dobriakova download the urequest.py file and place it in the lib folder.

        Here is the urequest.py file from micropython github page: https://github.com/micropython/micropython-lib/blob/master/python-ecosys/urequests/urequests.py

        L 1 Reply Last reply Reply Quote 0
        • L Offline
          Liudmila Dobriakova @Developer Pydro
          last edited by

          @Developer-Pydro Thanx! i'll do so.
          i managed to substitute the domain name with the IP, but now I'm facing the problem to perform POST request. I need to add the payload body as a JSON string. But it looks like it arrive empty to the service.
          the request is made as follow:

          httpreq = b'POST /sensordata/insertrecords HTTP/1.1 \r\n Host:XX.XXX.XXX.XXX \r\n' + 'Accept: application/json \r\n' + 'Content-Type: application/json\r\n\r\n' + ' {\"node_id\":\"1\",\"value\":[{\"measure_time_stamp\":\"2020-10-06T09:25:43\",\"temp\":\"14\",\"humidity\":\"75\",\"ph1\":11,\"ph2\":12,\"ph3\":13}]}'
          
          

          any suggestion what is wrong with the format?

          J 1 Reply Last reply Reply Quote 0
          • J Offline
            jcaron @Liudmila Dobriakova
            last edited by

            @Liudmila-Dobriakova you have lots of extra spaces at the beginning or end of your header lines, not sure those are allowed.

            L 1 Reply Last reply Reply Quote 0
            • L Offline
              Liudmila Dobriakova @jcaron
              last edited by

              @jcaron Do u mean "\r\n" ? i tried to remove them.. at the end they are mandatory otherwise the request is not sent at all. How would u suggest modifying the string?

              J 1 Reply Last reply Reply Quote 0
              • J Offline
                jcaron @Liudmila Dobriakova
                last edited by

                @Liudmila-Dobriakova I mean the spaces before and/or after the ˋ\r\n`.

                You are probably also missing a Content-Length.

                1 Reply Last reply Reply Quote 0

                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
                • 1 / 1
                • First post
                  Last post

                Pycom on Twitter

                Pycom