How to use API to get value at a given time

I have an input which takes as input my gas meter reading.  This input is only updated when the meter reading changes, so it could be several hours between updates.  The input is logged to a realtime, PHPFIWA feed.

I would like to be able to use the API to obtain the meter reading at a particular point in time.  I have been using this:

http://192.168.0.30/emoncms/feed/data.json?id=48&start=1443073600000&end...

or something similar - but this only seems to work if there happens to be an update during the start and end times. If there is no update, then I get 'false' returned.

Is there any way I can (reliably) get the reading at any particular point in time please?

Thanks for any help.

engeeaitch's picture

Re: How to use API to get value at a given time

Just been trying to solve this and noticed that a query such as:

http://192.168.0.30/emoncms/feed/data.json?id=54&start=1443278265000 returns inconsistent results- sometimes it returns [] and sometimes it returns a valid result.  Is this because I am using a PHPFIWA feed?  If I use a different feed type will I get reliable results?  Is there an alternative API call that I could use?

Thanks.

pb66's picture

Re: How to use API to get value at a given time

I would imagine the api will only return a value if there happens to be an update at that given time or when defining a narrow window, within that window.

The closest you will get to what you really want to know is the last recorded value prior to a given time and I think the only way to do what you are asking (currently) would be to specify a window ending at the "given time" and starting far enough back to guarantee at least one reading (eg "given time" minus 24hrs), then ignore all but the last value as that will be the last recorded value prior to the end time.

Paul

engeeaitch's picture

Re: How to use API to get value at a given time

Thanks for that - I've changed my input so that it updates every minute, and when looking for a value at a given time, I am looking for start=(time - 2 minutes), end=(time), dp=10 - seems to be OK.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.