Hi everybody, I’m new in using openremote platform. I’ve built an asset with different sensor entities, and now I’m trying to send data to the asset. I’ve read the /swagger/ API and I successfully send the data using a terminal with curl:
curl -i -X PUT
-H “Content-Type:application/json”
-H “Accept:application/json”
-d
‘[
{
“ref”: {
“id”: “XXX123YYY456ZZZ”,
“name”: “temperature”
},
“value”: “32”
},
{
“ref”: {
“id”: “XXX123YYY456ZZZ”,
“name”: “battery”
},
“value”: “80”
}
]’
‘https://my_site.click/api/master/asset/attributes’
Now I’m trying to make a PUT request using Python, I’ve tried in several way, but I always receive some error. This is one of the way that return a 500 Internal Error
import request
import json
url = “https://my_site.click/api/master/asset/attributes”
data = ‘{“ref”: {“id”: “XXX123YYY456ZZZ”, “name”: “temperature”},“value”: “12” }’
headers = {‘Content-type’: ‘application/json’, ‘Accept’: ‘application/json’}
r = requests.put(url, data=json.dumps(data), headers=headers)
r.status_code
500
Watching the server log file the error raised is about the deserialization of the String. Can anyone help me to explain how to use python to send data to my asset using request or socket? Also some example files are welcome. Thanks a lot,
vinz.