Skip to content

Instantly share code, notes, and snippets.

@noerw
Created May 23, 2017 08:36
Show Gist options
  • Save noerw/1864f3bb2852c60ec7bddde417059f39 to your computer and use it in GitHub Desktop.
Save noerw/1864f3bb2852c60ec7bddde417059f39 to your computer and use it in GitHub Desktop.
curl commands for the opensensemap API. requires jq
#!/bin/bash
OSEM_API=https://api.osem.vo1d.space
#OSEM_API=http://localhost:8000
# register user
OSEM_TOKEN=$(curl -H "content-type: application/json" $OSEM_API/users/register -d '{"name":"firstname","email":"[email protected]","password":"12345678"}' | jq .token | tr -d '"')
# user login
OSEM_TOKEN=$(curl -H "content-type: application/json" $OSEM_API/users/sign-in -d '{"email":"[email protected]","password":"12345678"}' | jq .token | tr -d '"')
# update user language
curl -H "content-type: application/json" -H "Authorization: Bearer $OSEM_TOKEN" -XPUT $OSEM_API/users/me -d '{"language": "de_DE"}'
# update user credentials
curl -H "content-type: application/json" -H "Authorization: Bearer $OSEM_TOKEN" -XPUT $OSEM_API/users/me -d '{"email": "[email protected]", "currentPassword":"12345678"}'
# new box, location latlng object
boxresult=$(curl -H "content-type: application/json" -H "Authorization: Bearer $OSEM_TOKEN" -XPOST $OSEM_API/boxes -d '{"name":"senseBox","model":"homeEthernet","boxType":"fixed","exposure":"indoor","location":{"lat":12,"lng":32,"height":-34.83263387480783},"mqtt":{"enabled":false,"url":"","topic":"","messageFormat":"","decodeOptions":"","connectionOptions":""}}')
# new box, location array
curl -H "content-type: application/json" -H "Authorization: Bearer $OSEM_TOKEN" -XPOST $OSEM_API/boxes -d '{"name":"senseBox","model":"homeEthernet","boxType":"fixed","exposure":"indoor","location":[12,32,-34.83263387480783],"mqtt":{"enabled":false,"url":"","topic":"","messageFormat":"","decodeOptions":"","connectionOptions":""}}'
# new box, old location geojson
boxresult=$(curl -H "content-type: application/json" -H "Authorization: Bearer $OSEM_TOKEN" -XPOST $OSEM_API/boxes -d '{"name":"senseBox","model":"homeEthernet","boxType":"fixed","exposure":"indoor","loc":[{"type":"Feature","geometry":{"coordinates":[-52.00130614651124,-34.83263387480783],"type":"Point"}}],"mqtt":{"enabled":false,"url":"","topic":"","messageFormat":"","decodeOptions":"","connectionOptions":""}}')
OSEM_BOX=$(echo $boxresult | jq .data._id | tr -d '"')
OSEM_SENSOR=$(echo $boxresult | jq .data.sensors[1]._id | tr -d '"')
echo "$OSEM_API/boxes/$OSEM_BOX/data/$OSEM_SENSOR"
# get box sketch
curl -H "content-type: application/json" -H "Authorization: Bearer $OSEM_TOKEN" -XGET $OSEM_API/boxes/$OSEM_BOX/script
# update box location latlng object
curl -H "content-type: application/json" -H "Authorization: Bearer $OSEM_TOKEN" -XPUT $OSEM_API/boxes/$OSEM_BOX -d '{"location": {"lat":13.3,"lng":34.4,"height":22}}'
# update box location array
curl -H "content-type: application/json" -H "Authorization: Bearer $OSEM_TOKEN" -XPUT $OSEM_API/boxes/$OSEM_BOX -d '{"location": [1,2,3], "name":"wubbalubbadub dub!"}'
# update box NAME
curl -H "content-type: application/json" -H "Authorization: Bearer $OSEM_TOKEN" -XPUT $OSEM_API/boxes/$OSEM_BOX -d '{"name": "blablubb"}'
# delete box
curl -H "Authorization: Bearer $OSEM_TOKEN" -XDELETE $OSEM_API/boxes/
# post measurement
curl -H "content-type: application/json" -H "Authorization: Bearer $OSEM_TOKEN" -XPOST $OSEM_API/boxes/$OSEM_BOX/$OSEM_SENSOR -d '{"value":"33"}'
# post measurement with location array
curl -H "content-type: application/json" -H "Authorization: Bearer $OSEM_TOKEN" -XPOST $OSEM_API/boxes/$OSEM_BOX/$OSEM_SENSOR -d '{"value":"33", "location":[3,2]}'
# post measurement with latlng obj
curl -H "content-type: application/json" -H "Authorization: Bearer $OSEM_TOKEN" -XPOST $OSEM_API/boxes/$OSEM_BOX/$OSEM_SENSOR -d '{"value":"33", "location":{"lat":-2,"lng":-5,"height": -103}, "createdAt": "2017-05-13T17:37:56.918Z"}'
# post new measurements measurement array
curl -H "content-type: application/json" -H "Authorization: Bearer $OSEM_TOKEN" -XPOST $OSEM_API/boxes/$OSEM_BOX/data -d '[
{"sensor_id": "'$OSEM_SENSOR'", "value": 1},
{"sensor_id": "'$OSEM_SENSOR'", "value": 2},
{"sensor_id": "'$OSEM_SENSOR'", "value": 3},
{"sensor_id": "'$OSEM_SENSOR'", "value": 4},
{"sensor_id": "'$OSEM_SENSOR'", "value": 5},
{"sensor_id": "'$OSEM_SENSOR'", "value": 6},
{"sensor_id": "'$OSEM_SENSOR'", "value": 7, "location": [7,7,7] },
{"sensor_id": "'$OSEM_SENSOR'", "value": 8},
{"sensor_id": "'$OSEM_SENSOR'", "value": 8.1},
{"sensor_id": "'$OSEM_SENSOR'", "value": 8.2},
{"sensor_id": "'$OSEM_SENSOR'", "value": 8.3},
{"sensor_id": "'$OSEM_SENSOR'", "value": 8.4},
{"sensor_id": "'$OSEM_SENSOR'", "value": 8.5},
{"sensor_id": "'$OSEM_SENSOR'", "value": 9, "location": [9,9,9] },
{"sensor_id": "'$OSEM_SENSOR'", "value": 9.3 },
{"sensor_id": "'$OSEM_SENSOR'", "value": 9.6 },
{"sensor_id": "'$OSEM_SENSOR'", "value": 10, "location": [10,10,10] },
{"sensor_id": "'$OSEM_SENSOR'", "value": 11},
{"sensor_id": "'$OSEM_SENSOR'", "value": 12}
]'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment