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.

dda
  • 6,030
  • 2
  • 25
  • 34
HiIamAndre
  • 21
  • 1

1 Answers1

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.

B45i
  • 2,368
  • 2
  • 23
  • 33