Post method ESP32

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
andermutu99
Posts: 18
Joined: Thu Sep 27, 2018 10:19 am

Post method ESP32

Post by andermutu99 » Mon Nov 05, 2018 10:22 am

Dear Community;

I am trying to upload data to Adafruit.io using post method of urequests library. I have tried to options. I both I have ensured I am connected to wifi. The first method is this:

Code: Select all

import urequests as requests
import json

url = "https://io.adafruit.com/api/v2/username/feeds/battery/data?X-AIO-Key=XXXXXXX"

data = {
    "value": "88"
}

r = requests.post(url, data=data)
results = r.json()
print (results)
And I am getting this error:
TypeError: object with buffer protocol required
The second option is the following:

Code: Select all

import urequests as requests
import json
import ujson

url = "https://io.adafruit.com/api/v2/andermutu99/feeds/battery/data?X-AIO-Key=3fe2f3eb5e694346b3f9e709b3128182"

data = {
    "value": "88"
}

data = ujson.dumps(data)
r = requests.post(url, data=data)
results = r.json()
print (results)
With this method I am not getting any error with MicroPython, but I the data is not correctly formatted and Adafruit does not recognize it.
{'error': 'request failed - failed to save data to feed battery. param is missing or the value is empty: datum'}
The first method works perfectly in my PC running in Python 2.7.

Please any help or suggestion is highly appreciated.

Thanks a lot,

Ander.

andermutu99
Posts: 18
Joined: Thu Sep 27, 2018 10:19 am

Re: Post method ESP32

Post by andermutu99 » Mon Nov 05, 2018 2:26 pm

Hi,

I have tried a new method that I have seen searching the Web, but it does not work.

Code: Select all

r = requests.post(URL, json =dict(value = “88“)) 
I get again this error message from Adafruit :
{'error': 'request failed - failed to save data to feed battery. param is missing or the value is empty: datum'}
Please any help is very useful for me.

Thanks in advance.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Post method ESP32

Post by pythoncoder » Mon Nov 05, 2018 6:09 pm

See my comment here.
Peter Hinch
Index to my micropython libraries.

Post Reply