NOTICE: This forum has been archived (i.e. registration and posting is disabled).

Please go to the new forum at https://forum.kylegabriel.com

Measurement API alw...
 
Notifications
Clear all

[Solved] Measurement API always returning null values


ceepritch
(@ceepritch)
Active Member
Joined: 2 months ago
Posts: 9
Topic starter  

I believe I'm doing everything correctly based upon the error responses when any param is changed but I'm always getting null values when querying the measurement api. This is either over REST directly or by using the API Page hosted by Mycodo. Any pointers from someone would be handy.

Here's an example of a request that isn't working for me but I have tried every input device and channel combination possible:

curl -X GET "https://192.168.1.211/api/measurements/last/5131a884-8ab0-43fe-bb1f-4050f2bb4438/C/0/60" -H "accept: application/vnd.mycodo.v1+json"

And the response is always:

{
  "time": null,
  "value": null
}

I have confirmed that these devices are capturing measurements and you can see their current values when looking at live/async graphs. I can even query this non-API URL for example and get data back:

/async/{device_id}/input/{unique_id}/{epoch}/{channel}

Quote
ceepritch
(@ceepritch)
Active Member
Joined: 2 months ago
Posts: 9
Topic starter  

Additionally I should mention that I'm running from Master at the moment so my next port of call will be to downgrade to see if this resolves the issue. I've checked the mycodo_db directly using the Influx CLI too and confirmed measurements are all there as expected.

This post was modified 2 months ago 2 times by ceepritch

ReplyQuote
Kyle Gabriel
(@kylegabriel)
Member Admin
Joined: 6 years ago
Posts: 612
 

I don't see an API key being used in your curl command. Have you generated a key and you're using a different curl command than you specified? 

Mycodo Developer


ReplyQuote
ceepritch
(@ceepritch)
Active Member
Joined: 2 months ago
Posts: 9
Topic starter  

@kylegabriel

Thanks for the super quick response Kyle!

Yeah, that's just copied and pasted from the Swagger page. I'm actually using REST from a React application/testing in the browser console. All other requests come through fine for example here's the response from:

/api/settings/device_measurements
Spoiler
Response
{
  "device measurement settings": [
    {
      "channel": 0,
      "conversion_id": null,
      "device_id": "aa6926e9-7009-4846-a4ae-9b51a27d9149",
      "device_type": null,
      "id": 1,
      "invert_scale": false,
      "is_enabled": true,
      "measurement": "temperature",
      "measurement_type": "",
      "name": "On Board Temp",
      "rescaled_measurement": "",
      "rescaled_unit": "",
      "scale_from_max": null,
      "scale_from_min": null,
      "scale_to_max": null,
      "scale_to_min": null,
      "unique_id": "5131a884-8ab0-43fe-bb1f-4050f2bb4438",
      "unit": "C"
    },
    {
      "channel": 1,
      "conversion_id": null,
      "device_id": "aa6926e9-7009-4846-a4ae-9b51a27d9149",
      "device_type": null,
      "id": 2,
      "invert_scale": false,
      "is_enabled": true,
      "measurement": "humidity",
      "measurement_type": "",
      "name": "On Board Humidity",
      "rescaled_measurement": "",
      "rescaled_unit": "",
      "scale_from_max": null,
      "scale_from_min": null,
      "scale_to_max": null,
      "scale_to_min": null,
      "unique_id": "8efe5229-87cf-442c-8dab-f3c193159826",
      "unit": "percent"
    },
    {
      "channel": 2,
      "conversion_id": null,
      "device_id": "aa6926e9-7009-4846-a4ae-9b51a27d9149",
      "device_type": null,
      "id": 3,
      "invert_scale": false,
      "is_enabled": true,
      "measurement": "light",
      "measurement_type": "",
      "name": "On Board Light",
      "rescaled_measurement": "",
      "rescaled_unit": "",
      "scale_from_max": null,
      "scale_from_min": null,
      "scale_to_max": null,
      "scale_to_min": null,
      "unique_id": "0bb5bf37-9afd-45db-adda-7d1b81816778",
      "unit": "lux"
    },
    {
      "channel": 3,
      "conversion_id": null,
      "device_id": "aa6926e9-7009-4846-a4ae-9b51a27d9149",
      "device_type": null,
      "id": 4,
      "invert_scale": false,
      "is_enabled": true,
      "measurement": "temperature",
      "measurement_type": "",
      "name": "Off Board Temp",
      "rescaled_measurement": "",
      "rescaled_unit": "",
      "scale_from_max": null,
      "scale_from_min": null,
      "scale_to_max": null,
      "scale_to_min": null,
      "unique_id": "f5f283e1-a38c-433c-ac9c-e4ae7410e7e4",
      "unit": "C"
    },
    {
      "channel": 4,
      "conversion_id": null,
      "device_id": "aa6926e9-7009-4846-a4ae-9b51a27d9149",
      "device_type": null,
      "id": 5,
      "invert_scale": false,
      "is_enabled": true,
      "measurement": "pressure",
      "measurement_type": "",
      "name": "On Board Pressure",
      "rescaled_measurement": "",
      "rescaled_unit": "",
      "scale_from_max": null,
      "scale_from_min": null,
      "scale_to_max": null,
      "scale_to_min": null,
      "unique_id": "e029a012-8aea-4b19-be9c-8886b61ecedb",
      "unit": "Pa"
    },
    {
      "channel": 5,
      "conversion_id": null,
      "device_id": "aa6926e9-7009-4846-a4ae-9b51a27d9149",
      "device_type": null,
      "id": 6,
      "invert_scale": false,
      "is_enabled": true,
      "measurement": "temperature",
      "measurement_type": "",
      "name": "Pressure Based Temp",
      "rescaled_measurement": "",
      "rescaled_unit": "",
      "scale_from_max": null,
      "scale_from_min": null,
      "scale_to_max": null,
      "scale_to_min": null,
      "unique_id": "84d131db-8b59-4d04-8317-637fb5abefc6",
      "unit": "C"
    },
    {
      "channel": 0,
      "conversion_id": null,
      "device_id": "16be6d27-580c-47d6-86d2-3434649b2643",
      "device_type": null,
      "id": 7,
      "invert_scale": false,
      "is_enabled": true,
      "measurement": "moisture",
      "measurement_type": "",
      "name": "Soil Moisture",
      "rescaled_measurement": "",
      "rescaled_unit": "",
      "scale_from_max": null,
      "scale_from_min": null,
      "scale_to_max": null,
      "scale_to_min": null,
      "unique_id": "d0dea51c-387a-4836-ae45-d370012a0997",
      "unit": "unitless"
    },
    {
      "channel": 1,
      "conversion_id": null,
      "device_id": "16be6d27-580c-47d6-86d2-3434649b2643",
      "device_type": null,
      "id": 8,
      "invert_scale": false,
      "is_enabled": true,
      "measurement": "humidity",
      "measurement_type": "",
      "name": "Soil Saturation",
      "rescaled_measurement": "",
      "rescaled_unit": "",
      "scale_from_max": null,
      "scale_from_min": null,
      "scale_to_max": null,
      "scale_to_min": null,
      "unique_id": "ef2cdbf9-221c-4473-b4d3-7b325dfe9242",
      "unit": "percent"
    },
    {
      "channel": 2,
      "conversion_id": null,
      "device_id": "16be6d27-580c-47d6-86d2-3434649b2643",
      "device_type": null,
      "id": 9,
      "invert_scale": false,
      "is_enabled": true,
      "measurement": "state",
      "measurement_type": "",
      "name": "Pump Status (On/Off)",
      "rescaled_measurement": "",
      "rescaled_unit": "",
      "scale_from_max": null,
      "scale_from_min": null,
      "scale_to_max": null,
      "scale_to_min": null,
      "unique_id": "fd0b0c46-320a-49b0-a0e6-304b0fd88ca2",
      "unit": "unitless"
    }
  ]
}
This post was modified 2 months ago 2 times by ceepritch

ReplyQuote
Kyle Gabriel
(@kylegabriel)
Member Admin
Joined: 6 years ago
Posts: 612
 

I'll look into it and get back to you.

Mycodo Developer


ReplyQuote
ceepritch
(@ceepritch)
Active Member
Joined: 2 months ago
Posts: 9
Topic starter  

@kylegabriel

Cheers, no rush or anything. I've got plenty of other things to do for this Calendar widget I'm building. Just need the API for automated measurements attached to an event.


ReplyQuote
Kyle Gabriel
(@kylegabriel)
Member Admin
Joined: 6 years ago
Posts: 612
 

It's working just fine for me.

pi@tango:~/Mycodo/mycodo $ curl -k -X GET "https://192.168.0.9/api/measurements/last/3ca3da6e-aa23-4144-bea3-323da90c529e/F/0/999" -H  "accept: application/vnd.mycodo.v1+json" -H  "X-API-KEY: MYAPIKEYXYZ"
{"time":"2021-03-03T22:41:13.675276+00:00","value":120.8984}

Mycodo Developer


ReplyQuote
ceepritch
(@ceepritch)
Active Member
Joined: 2 months ago
Posts: 9
Topic starter  

@kylegabriel

Cheers for confirming it's not something in the code-base, it's definitely something I'm doing wrong/have broken then. I'll investigate further and figure out what's going on. I'll post here when I figure it out.


ReplyQuote
ceepritch
(@ceepritch)
Active Member
Joined: 2 months ago
Posts: 9
Topic starter  

@kylegabriel

Figured it out in the end! Apologies for wasting your time as it was totally my fault. After logging the query generated by influx.py I realised that the 'unique_id' listed on the API page is actually the 'device_id' of the measurement and not the 'unique_id' of the measurement itself. Everything's working great now cheers.


ReplyQuote
Kyle Gabriel
(@kylegabriel)
Member Admin
Joined: 6 years ago
Posts: 612
 

No problem. The measurement device_id is the Input's unique_id, so you can go to the Input page and click the button with the device name (the one that has a pop-up of the UUID when you mouse over) of an Input to copy the ID to the clipboard. You're referencing the Input itself, then specifying the particular channel (integer) of that input for each measurement.

Mycodo Developer


ReplyQuote
ceepritch
(@ceepritch)
Active Member
Joined: 2 months ago
Posts: 9
Topic starter  

@kylegabriel

Yep I can see that now, thanks for the handy tip on finding them. I'll be sure to make a post of this calendar custom widget once I wrap up. Should only take another week or so. I'm finding it's a nice way of visualising a history of measurements/timelapses and upcoming scheduled functions.


aka and Kyle Gabriel liked
ReplyQuote
Kyle Gabriel
(@kylegabriel)
Member Admin
Joined: 6 years ago
Posts: 612
 

Sounds interesting. Looking forward to seeing it!

Mycodo Developer


ReplyQuote