Allright here goes;
First lets try to get the file, put this in your raspberry command line(doh)
sudo curl https://api.opensensemap.org/boxes/596e0dd38ecc8900101c2936
Output;
{"_id":"596e0dd38ecc8900101c2936","createdAt":"2017-07-18T13:32:03.732Z","updatedAt":"2017-08-01T14:23:23.668Z","name":"Test2","boxType":"fixed","grouptag":"Bad_Hersfeld","exposure":"outdoor","model":"homeWifiFeinstaub","sensors":[{"title":"Temperatur","unit":"°C","sensorType":"HDC1008","icon":"osem-thermometer","_id":"596e0dd38ecc8900101c2937","lastMeasurement":{"value":"27.67","createdAt":"2017-08-01T14:23:23.664Z"}},{"title":"rel. Luftfeuchte","unit":"%","sensorType":"HDC1008","icon":"osem-humidity","_id":"596e0dd38ecc8900101c2938","lastMeasurement":{"value":"53.16","createdAt":"2017-08-01T14:23:23.664Z"}},{"title":"Luftdruck","unit":"hPa","sensorType":"BMP280","icon":"osem-barometer","_id":"596e0dd38ecc8900101c2939","lastMeasurement":{"value":"987.86","createdAt":"2017-08-01T14:23:23.664Z"}},{"title":"Beleuchtungsstärke","unit":"lx","sensorType":"TSL45315","icon":"osem-brightness","_id":"596e0dd38ecc8900101c293a","lastMeasurement":{"value":"740.00","createdAt":"2017-08-01T14:23:23.664Z"}},{"title":"UV-Intensität","unit":"μW/cm²","sensorType":"VEML6070","icon":"osem-brightness","_id":"596e0dd38ecc8900101c293b","lastMeasurement":{"value":"11.25","createdAt":"2017-08-01T14:23:23.664Z"}},{"title":"PM10","unit":"µg/m³","sensorType":"SDS 011","icon":"osem-cloud","_id":"596e0dd38ecc8900101c293c","lastMeasurement":{"value":"6.00","createdAt":"2017-08-01T14:23:23.664Z"}},{"title":"PM2.5","unit":"µg/m³","sensorType":"SDS 011","icon":"osem-cloud","_id":"596e0dd38ecc8900101c293d","lastMeasurement":{"value":"3.10","createdAt":"2017-08-01T14:23:23.664Z"}},{"_id":"597083342e9396000fd09586","icon":"osem-volume-up","sensorType":"mic","unit":"db","title":"Umgebungslautstärke"}],"loc":[{"geometry":{"coordinates":[9.675063,50.870084],"type":"Point"},"type":"feature"}],"description":"TestSenseBOX"}
Oh snap, thats not exactly parsable, is it?
Lets change that. Note the JQ command;
sudo curl https://api.opensensemap.org/boxes/596e0dd38ecc8900101c2936 | jq '.'
Output;
{
"_id": "596e0dd38ecc8900101c2936",
"createdAt": "2017-07-18T13:32:03.732Z",
"updatedAt": "2017-08-01T14:23:23.668Z",
"name": "Test2",
"boxType": "fixed",
"grouptag": "Bad_Hersfeld",
"exposure": "outdoor",
"model": "homeWifiFeinstaub",
"sensors": [ /// THIS IS OUR SUBCATEGORY
{
"title": "Temperatur",
"unit": "°C",
"sensorType": "HDC1008",
"icon": "osem-thermometer",
"_id": "596e0dd38ecc8900101c2937",
"lastMeasurement": {
"value": "27.67",
"createdAt": "2017-08-01T14:23:23.664Z"
}
},
{
"title": "rel. Luftfeuchte",
"unit": "%",
"sensorType": "HDC1008",
"icon": "osem-humidity",
"_id": "596e0dd38ecc8900101c2938",
"lastMeasurement": {
"value": "53.16",
"createdAt": "2017-08-01T14:23:23.664Z"
}
},
{
"title": "Luftdruck",
"unit": "hPa",
"sensorType": "BMP280",
"icon": "osem-barometer",
"_id": "596e0dd38ecc8900101c2939",
"lastMeasurement": {
"value": "987.86",
"createdAt": "2017-08-01T14:23:23.664Z"
}
},
{
"title": "Beleuchtungsstärke",
"unit": "lx",
"sensorType": "TSL45315",
"icon": "osem-brightness",
"_id": "596e0dd38ecc8900101c293a",
"lastMeasurement": {
"value": "740.00",
"createdAt": "2017-08-01T14:23:23.664Z"
}
},
{
"title": "UV-Intensität",
"unit": "μW/cm²",
"sensorType": "VEML6070",
"icon": "osem-brightness",
"_id": "596e0dd38ecc8900101c293b",
"lastMeasurement": {
"value": "11.25",
"createdAt": "2017-08-01T14:23:23.664Z"
}
},
{
"title": "PM10",
"unit": "µg/m³",
"sensorType": "SDS 011",
"icon": "osem-cloud",
"_id": "596e0dd38ecc8900101c293c",
"lastMeasurement": {
"value": "6.00",
"createdAt": "2017-08-01T14:23:23.664Z"
}
},
{
"title": "PM2.5",
"unit": "µg/m³",
"sensorType": "SDS 011",
"icon": "osem-cloud",
"_id": "596e0dd38ecc8900101c293d",
"lastMeasurement": {
"value": "3.10",
"createdAt": "2017-08-01T14:23:23.664Z"
}
},
{
"_id": "597083342e9396000fd09586",
"icon": "osem-volume-up",
"sensorType": "mic",
"unit": "db",
"title": "Umgebungslautstärke"
}
],
"loc": [
{
"geometry": {
"coordinates": [
9.675063,
50.870084
],
"type": "Point"
},
"type": "feature"
}
],
"description": "TestSenseBOX"
}
Ah, thats betters. As you can see, sensors has subcategories, ill just asume you want those. Now, instead of using jq ‘.’, we select the sensors like so:
sudo curl https://api.opensensemap.org/boxes/596e0dd38ecc8900101c2936 | jq '.sensors'
Output;
[ //<<-- start of array
{
"title": "Temperatur",
"unit": "°C",
"sensorType": "HDC1008",
"icon": "osem-thermometer",
"_id": "596e0dd38ecc8900101c2937",
"lastMeasurement": {
"value": "27.67",
"createdAt": "2017-08-01T14:23:23.664Z"
}
},
{
"title": "rel. Luftfeuchte",
"unit": "%",
"sensorType": "HDC1008",
"icon": "osem-humidity",
"_id": "596e0dd38ecc8900101c2938",
"lastMeasurement": {
"value": "53.16",
"createdAt": "2017-08-01T14:23:23.664Z"
}
},
{
"title": "Luftdruck",
"unit": "hPa",
"sensorType": "BMP280",
"icon": "osem-barometer",
"_id": "596e0dd38ecc8900101c2939",
"lastMeasurement": {
"value": "987.86",
"createdAt": "2017-08-01T14:23:23.664Z"
}
},
{
"title": "Beleuchtungsstärke",
"unit": "lx",
"sensorType": "TSL45315",
"icon": "osem-brightness",
"_id": "596e0dd38ecc8900101c293a",
"lastMeasurement": {
"value": "740.00",
"createdAt": "2017-08-01T14:23:23.664Z"
}
},
{
"title": "UV-Intensität",
"unit": "μW/cm²",
"sensorType": "VEML6070",
"icon": "osem-brightness",
"_id": "596e0dd38ecc8900101c293b",
"lastMeasurement": {
"value": "11.25",
"createdAt": "2017-08-01T14:23:23.664Z"
}
},
{
"title": "PM10",
"unit": "µg/m³",
"sensorType": "SDS 011",
"icon": "osem-cloud",
"_id": "596e0dd38ecc8900101c293c",
"lastMeasurement": {
"value": "6.00",
"createdAt": "2017-08-01T14:23:23.664Z"
}
},
{
"title": "PM2.5",
"unit": "µg/m³",
"sensorType": "SDS 011",
"icon": "osem-cloud",
"_id": "596e0dd38ecc8900101c293d",
"lastMeasurement": {
"value": "3.10",
"createdAt": "2017-08-01T14:23:23.664Z"
}
},
{
"_id": "597083342e9396000fd09586",
"icon": "osem-volume-up",
"sensorType": "mic",
"unit": "db",
"title": "Umgebungslautstärke"
}
] //<<-- end of array
Ok, but now, There are no more main categories so how the hell do we select temperature or humidty?
We divide it. The first one, temperature is always 0, so execute this;
sudo curl https://api.opensensemap.org/boxes/596e0dd38ecc8900101c2936 | jq '.sensors[0]'
Output;
{
"title": "Temperatur",
"unit": "°C",
"sensorType": "HDC1008",
"icon": "osem-thermometer",
"_id": "596e0dd38ecc8900101c2937",
"lastMeasurement": {
"value": "27.67",
"createdAt": "2017-08-01T14:23:23.664Z"
}
}
Okay, so now we have entered the temperature section of the json file, now we simply select our data:
sudo curl -s https://api.opensensemap.org/boxes/596e0dd38ecc8900101c2936 | jq -r '.sensors[0].lastMeasurement.value'
Output;
27.67
Please note i have added the -r to remove the “” from the output. I also added the -s tag to the curl command to only output jq
Now, if you want the second category value just change the 0 to 1, 2 etc
sudo curl -s https://api.opensensemap.org/boxes/596e0dd38ecc8900101c2936 | jq -r '.sensors[1].lastMeasurement.value'
Output(humidity):
53.16
I hope i was clear on how to use the lovely json parser JQ!!
Easy part; create a shellsensor device called Temperature and as command do;
sudo curl -s https://api.opensensemap.org/boxes/596e0dd38ecc8900101c2936 | jq -r '.sensors[0].lastMeasurement.value'
Voila!