Last device battery level (reading)

Discussions about CSEntry
Forum rules
New release: CSPro 8.0
Post Reply
htuser
Posts: 631
Joined: December 19th, 2011, 6:26 pm
Location: Silver Spring Area, MD, USA

Last device battery level (reading)

Post 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!
G.VOLNY, a CSProuser from Haiti, since 2004
Gregory Martin
Posts: 1777
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: Last device battery level (reading)

Post 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;
htuser
Posts: 631
Joined: December 19th, 2011, 6:26 pm
Location: Silver Spring Area, MD, USA

Re: Last device battery level (reading)

Post by htuser »

Thanks Greg!
G.VOLNY, a CSProuser from Haiti, since 2004
Post Reply