Page 1 of 1

Last device battery level (reading)

Posted: December 18th, 2018, 5:15 pm
by htuser
Dear all,
I'm setting up a function able to inform enumerators when devices batteries run lower than 15%. I know that theses informations are stored in device_state_event table and battery level column...but i'm unable to select the newest (latest) record (reading) from this table...
Does it the select (min) or the select (max)?
Also, please can you add timestamp in this table? Or can you advise us how to link (join) this table with the ones containing timestamp?

Thanks in advance for your support!

Re: Last device battery level (reading)

Posted: December 19th, 2018, 4:59 am
by Gregory Martin
The IDs increment, so you can get the latest value with this:
SELECT battery_level FROM device_state_event ORDER BY id DESC LIMIT 1;
Every paradata event table links to the main "event" table, so you can get the timestamp and battery level with this:
SELECT time, battery_level FROM device_state_event JOIN event ON event.id = device_state_event.id ORDER BY event.id DESC LIMIT 1;

Re: Last device battery level (reading)

Posted: December 19th, 2018, 7:25 am
by htuser
Thanks Greg!