smartcitizen-kit-21 icon indicating copy to clipboard operation
smartcitizen-kit-21 copied to clipboard

If battery is not read, sensor data is not stored

Open oscgonfer opened this issue 3 months ago • 1 comments

Due to current implementation of the sensor list, the battery sensor always takes priority in the readings. In a situation where there is ONLY one sensor enabled at a certain interval, with all the other sensors (including battery) at a different and larger interval, the sensor in question is read but not stored. For instance:

Enabled
----------
Temperature -> every 4 int (60 sec) 
Humidity -> every 4 int (60 sec) 
Battery -> every 1 int (15 sec) 
SD card -> every 4 int (60 sec) 
WiFi RSSI -> every 12 int (180 sec) 
Light -> every 4 int (60 sec) 
Noise dBA -> every 1 int (15 sec) 
MPL Barometric pressure -> every 4 int (60 sec) 
SEN5X PM 1.0 -> every 12 int (180 sec) 
SEN5X PM 2.5 -> every 12 int (180 sec) 
SEN5X PM 4.0 -> every 12 int (180 sec) 
SEN5X PM 10.0 -> every 12 int (180 sec) 
SEN5X PN 0.5 -> every 12 int (180 sec) 
SEN5X PN 1.0 -> every 12 int (180 sec) 
SEN5X PN 2.5 -> every 12 int (180 sec) 
SEN5X PN 4.0 -> every 12 int (180 sec) 
SEN5X PN 10.0 -> every 12 int (180 sec) 
SEN5X Typical Particle Size -> every 12 int (180 sec) 
AS7331 UVA -> every 4 int (60 sec) 
AS7331 UVB -> every 4 int (60 sec) 
AS7331 UVC -> every 4 int (60 sec) 

In this situation, if the battery was not read at the same time as the noise dBA, noise would not be stored anywhere. This is because the SCKList class only sees one sensor enabled:

https://github.com/fablabbcn/smartcitizen-kit-2x/blob/master/sam/src/SckList.cpp#L703-L731

But the list of sensors with priorities:

https://github.com/fablabbcn/smartcitizen-kit-2x/blob/master/lib/Sensors/Sensors.cpp#L73-L89

Has always Battery and whatever else is enabled:

https://github.com/fablabbcn/smartcitizen-kit-2x/blob/49b152fa4a6e463bb01d49c4d816b2ea46f17be3/sam/src/SckBase.cpp#L1806-L1829

This makes it impossible to not read the battery all the time (not really an issue). However, long-story-short if one sensor is enabled at a lower interval than all the rest, the battery has to be read at the same interval as that sensor.

oscgonfer avatar Oct 17 '25 12:10 oscgonfer