Read Feed Data Actions - Failing

Hi

When using the following command i constantly get the following error;
http://emonpi/feed/data.json?id=0&start=1635083272&end=1635083332&interval=10

success false
message request end time before start time

It seems to throw an error, despite the pi having data for that period??

Any ideas??

Welcome back - long time, no see.

No ideas, but something to check:

I have data covering that period, and I get exactly the same error. But if I put an earlier start time, viz start=1635082972&end=1635083325&interval=10 it succeeds but returns an empty array.

Yet a single value &time=1635021610 works fine for me, as does CSV export:
.../csvexport.json?id=1&start=1635083272&end=1635083332&interval=10&timeformat=1=
(I don’t have a Feed 0)

I wonder if the code has been changed, but not the documentation - which is not unheard-of.

My PHP isn’t up to tracking through the code to find the problem.

Ha!
This post by @TrystanLea had the times in milliseconds - I’ve only just spotted it.

http://localhost/emoncms/feed/data.json?id=195&start=1609598790000&end=1609598791000&interval=1

AND THEN…

/feed/data.json?id=1&start=1635083272000&end=1635083332000&interval=10 gives me data :smiley:

[[1635083272000,150],[1635083282000,149],[1635083292000,149],[1635083302000,148],[1635083312000,149],[1635083322000,148],[1635083332000,148],[1635083342000,148]]

My hunch was right, the code has been changed, but not the documentation; or vice versa.

@TrystanLea: the Feed API Help needs updating.

The cause of the error message is in the function get_data(…) in PHPFina.php:

It’s assumed that the incoming data is in milliseconds, and it’s converted to seconds, but if it’s already seconds and the difference is small, the subsequent check for end > start fails because the two are equal (the difference was in the 3 least significant digits). And when the difference became enough, it returned an empty array because there’s no data in January, 1970 - which is when start=1635083

        $start = intval($start/1000);
        $end = intval($end/1000);
        $interval= (int) $interval;

        // Minimum interval
        if ($interval<1) $interval = 1;
        // End must be larger than start
        if ($end<=$start) return array('success'=>false, 'message'=>"request end time before start time");

But the underlying problem is quite simply, the documentation is inaccurate:

All the references I’ve seen to the Unix Timestamp specify it as a count of seconds, not milliseconds.

Yes I agree this has been a bit confusing! I actually have a new version of the Feed API documentation currently in the master branch ready to merge into stable soon. It gives clearer examples of how to use the different API end points.

I’m also working towards (in a later update) removing all use of milliseconds as it’s not really relevant, we don’t record anything at that resolution! and also extending the option to use a date time strings to specify times via the api. So this will get better.