0

I have an ESP8266 and I have to use MicroPython. There is no MicroPython library for ubidots, so I have to use HTTP requests. Does anyone know how to get started? By the way, I am using Esplorer.jar to program. Thanks.

1 Answer 1

2

You can use urequests library to send HTTP request. As per ubidots documentation, data can be send as :

curl -X POST -H "Content-Type: application/json" -d '{"temperature": 10, "luminosity": {"value":10}, "wind_speed": [{"value": 11, "timestamp":10000}, {"value": 12, "timestamp":13000}]}' http://things.ubidots.com/api/v1.6/devices/weather-station?token=your_api_token.

this can be converted to MicroPython as,

import urequests
import json

headers = {
    'Content-Type': 'application/json',
}

data = '{"temperature": 10, "luminosity": {"value":10}, "wind_speed": [{"value": 11, "timestamp":10000}, {"value": 12, "timestamp":13000}]}'

# replace weather-station with your device name, and api-token with your api-token
r = urequests.post('http://things.ubidots.com/api/v1.6/devices/weather-station?token=your_api_token', headers=headers,  data=data).json()
print(r)

the response contain HTTP status code for each variable.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.