我有一个 ESP8266,我必须使用 MicroPython。ubidots 没有 MicroPython 库,所以我必须使用 HTTP 请求。有谁知道如何开始?顺便说一句,我正在使用 Esplorer.jar 进行编程。谢谢。
1 回答
2
您可以使用 urequests 库发送 HTTP 请求。根据 ubidots 文档,数据可以发送为:
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.
这可以转换为 MicroPython,
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)
响应包含每个变量的 HTTP 状态代码。
于 2017-10-18T13:45:31.617 回答