Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

BUG: created_at value is different if it's ?include
Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
Please be positive and constructive with your questions and comments.

BUG: created_at value is different if it's ?include

by cjdshaw on Tue Aug 25, 2020 10:51 am

A bit of background: I like my graph data to all read out neatly in a single hover-box when I mouse-over it. If you submit datum points for several feeds a few seconds apart, this doesn't happen since they all have slightly different created_at values. My solution is to take the created_at returned by the first submission, then use it to force subsequent submissions to have the same created_at. The upshot is that the created_at value of most of my data is slightly earlier than when it was actually uploaded.

If I do:
curl -s "http://io.adafruit.com/api/v2/<username>/feeds/<feedkey>/data?x-aio-key=<APIKEY>
the data that comes out has the neat created_at that I provided (lots of lines excluded from this snippet)
Code: Select all | TOGGLE FULL SIZE
[
  {
    "value": "5.00",
    "created_at": "2020-08-25T14:35:00Z",
  },
  {
    "value": "5.00",
    "created_at": "2020-08-25T14:30:00Z",
  },
  {
    "value": "5.00",
    "created_at": "2020-08-25T14:25:00Z",
  }
]


but if I use the include, e.g.
curl -s "http://io.adafruit.com/api/v2/<username>/feeds/<feedkey>/data?x-aio-key=<APIKEY>&include=created_at
I get messy values with seconds, probably the actual time they were created
Code: Select all | TOGGLE FULL SIZE
[
  {
    "created_at": "2020-08-25T14:35:26Z"
  },
  {
    "created_at": "2020-08-25T14:30:26Z"
  },
  {
    "created_at": "2020-08-25T14:25:26Z"
  }
]


Is this a bug or am I missing something?

cjdshaw
 
Posts: 32
Joined: Mon May 08, 2017 4:04 pm

Re: BUG: created_at value is different if it's ?include

by jwcooper on Wed Aug 26, 2020 12:17 pm

Interesting, I'm not sure I can reproduce this one yet. If I test this on a new feed, the results are the same if I include the created_at or not.

Here is without the include:
Code: Select all | TOGGLE FULL SIZE
[{"id":"id","value":"2","feed_id":1439888,"created_at":"2020-08-26T16:06:46Z","created_epoch":1598458006,"expiration":"2020-10-25T16:06:46Z"},{"id":"id","value":"1","feed_id":1439888,"created_at":"2020-08-26T16:06:00Z","created_epoch":1598457960,"expiration":"2020-10-25T16:06:00Z"}]


Here is with the include:
Code: Select all | TOGGLE FULL SIZE
[{"created_at":"2020-08-26T16:06:46Z"},{"created_at":"2020-08-26T16:06:00Z"}]


The timestamps match between the different calls.

You could also try sending your data as a single group. That will also sync the created_at timestamp. You can pass a timestamp, or just let the system manage the created_at (and sync it among all feeds in that single group call).

Code: Select all | TOGGLE FULL SIZE
POST https://io.adafruit.com/username/groups/group-name/data


You then just pass in an array of feeds, such as:
Code: Select all | TOGGLE FULL SIZE
{ feeds: [ { key: string, value: string }, ... ], created_at: string (optional), location: { lat: number, lon: number, ele: number } (optional)}

jwcooper
 
Posts: 692
Joined: Tue May 01, 2012 9:08 pm

Re: BUG: created_at value is different if it's ?include

by cjdshaw on Wed Aug 26, 2020 12:39 pm

jwcooper wrote:Interesting, I'm not sure I can reproduce this one yet. If I test this on a new feed, the results are the same if I include the created_at or not.


When you created that feed data, did you supply a created_at value? The fact that the created_at and expiration values have the same time make me think not. I should have been clearer. My exact repro steps are:
Code: Select all | TOGGLE FULL SIZE
AIO_APIKEY=xxxxx
AIO_FEEDKEY=xxxxx
AIO_USERNAME=xxxxx

curl -s -F "value=1" -F "created_at=2020-08-26T16:26:00Z" "http://io.adafruit.com/api/v2/$AIO_USERNAME/feeds/$AIO_FEEDKEY/data?x-aio-key=$AIO_APIKEY"
{"id":"0EH6SYEYC0NXAF75ZA66T4RR3W","value":"1","feed_id":1438066,"feed_key":"xxxxx","created_at":"2020-08-26T16:26:00Z","created_epoch":1598459160,"expiration":"2020-09-25T16:26:18Z"}

curl -s "http://io.adafruit.com/api/v2/$AIO_USERNAME/feeds/$AIO_FEEDKEY/data?x-aio-key=$AIO_APIKEY&limit=1"
[{"id":"0EH6SYEYC0NXAF75ZA66T4RR3W","value":"1","feed_id":1438066,"feed_key":"xxxxx","created_at":"2020-08-26T16:26:00Z","created_epoch":1598459160,"expiration":"2020-09-25T16:26:18Z"}]

curl -s "http://io.adafruit.com/api/v2/$AIO_USERNAME/feeds/$AIO_FEEDKEY/data?x-aio-key=$AIO_APIKEY&limit=1&include=created_at"
[{"created_at":"2020-08-26T16:26:18Z"}]


So in the first and second call, created_at is correctly reported as 2020-08-26T16:26:00Z, which is the value I supplied
In the third call though, it's given as 2020-08-26T16:26:18Z which was the time it was actually created


As you say, I could accumulate all the data and upload it as a batch, but I'm on an ESP8266 so I'm trying to keep all my data structures small. Also, I'm having some stability issues, so at least this way, if the watchdog reboots the device, I don't lose any data I've acquired so far

cjdshaw
 
Posts: 32
Joined: Mon May 08, 2017 4:04 pm

Re: BUG: created_at value is different if it's ?include

by jwcooper on Wed Aug 26, 2020 2:50 pm

Understood. We're taking a look at this, and will try and re-create your issue.

Thank you for the steps to reproduce the issue, it's very helpful.

jwcooper
 
Posts: 692
Joined: Tue May 01, 2012 9:08 pm

Re: BUG: created_at value is different if it's ?include

by cjdshaw on Wed Aug 26, 2020 3:48 pm

jwcooper wrote:Understood. We're taking a look at this, and will try and re-create your issue.

Thank you for the steps to reproduce the issue, it's very helpful.


Thanks. It's not a showstopper for me, but I thought it odd

cjdshaw
 
Posts: 32
Joined: Mon May 08, 2017 4:04 pm

Please be positive and constructive with your questions and comments.