last_entry_id

1 view (last 30 days)
Jaye Hicks
Jaye Hicks on 12 Oct 2020
Commented: Craig Larson on 19 Dec 2021
ThingSpeak auto assigns an unique identifier to each new inbound record for a given channel. Within the record the identifier is named 'last_entry_id.' Each auto assigned id is auto increment by one over the previous id. What is the largest numeric value that last_entry_id will reach? If there is an upper bound, what will happen when it is reached? Will a roll over occur such that last_entry_id is reset to 0 or 1?
Thanks in advance for the information.
  1 Comment
Craig Larson
Craig Larson on 19 Dec 2021
@Jay Hicks: May I ask how you obtain the 'last_entry_id' in your code? I have a need for this data element also. My sensor is writing data and estimated time to Thingspeak in a bulk-uploading of 20 data records inorder to save on battery life of the ESP8266 transmitter. Sometimes there are timestamp overlaps, and sometimes there are gaps due to the estimated time. When there are overlaps the data is no longer in order of the 'entry_id'. I can see the 'entry_id' values in worksheets exported from Thingspeak. But I'm trying to use Matlab code to sort this out from inside Thingspeak using a custom App only I don't know how to access 'entry_id'. Thanks in advance.

Sign in to comment.

Answers (2)

Christopher Stapels
Christopher Stapels on 14 Oct 2020
Can you describe why you need the last_entry_id?
It is not recommended to be used for the reasons you mention (rollover, finite upper bound.)
  1 Comment
Jaye Hicks
Jaye Hicks on 14 Oct 2020
I have developed custom code to process incoming sensor data. The data is pulled by my code from a thingspeak endpoint. In my design I thought to leverage last_entry_id in three different ways.
First, I read a block of data going back in time slightly further than I need to and then cycle through the data, starting with the oldest, ignoring records until the incoming last_entry_id is larger than the largest last_entry_id that I stored off, in a database, from the last time that I pulled a block of sensor data. Are you suggesting that this is not advised or is some how not viable?
The second and the third ways that my design uses last_entry_id involves detecting gaps. I raise warning / error log messages if I detect a numeric gap either across data pulls or within a block of data from a single pull. Specifically, as I process a new block of pulled sensor data does the first last_entry_id begin at a value that is one more than the value that I stored off (from the previous data pull)? And during the processing of individual records within a single data pull, are there any numbers skipped in the 'increment by one' progression of last_entry_id? Are you suggesting that this is not advised or is some how not viable?

Sign in to comment.


Christopher Stapels
Christopher Stapels on 21 Oct 2020
I suggest that this is not the most viable method. There could be unexpected ways that last_entry_id does not always behave as you would like. I would reccomend that you use timestamp comparisons to detect missing data and to cycle through the recently read data. They may be slightly harder to write, but I think they will be more robust. In MATLAB, you can convert timestamps into numeric representations for fast comparison. You can use datenum() on a timestamp to get a number of days since a set time, or compare datetimes to get durations.

Communities

More Answers in the  ThingSpeak Community

Categories

Find more on ThingSpeak in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!