2017-09-22 8 views

答えて

1

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ステータスコードを含みます。

関連する問題