LoPy4 problem using HTTP requests
-
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?
-
@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
-
@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?
-
@Liudmila-Dobriakova you have lots of extra spaces at the beginning or end of your header lines, not sure those are allowed.
-
@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?
-
@Liudmila-Dobriakova I mean the spaces before and/or after the ˋ\r\n`.
You are probably also missing a Content-Length.
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