Skip to content

If battery is not read, sensor data is not stored #100

@oscgonfer

Description

@oscgonfer

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:

for (uint8_t i=0; i<SENSOR_COUNT; i++) {
// Get next sensor based on priority
OneSensor *wichSensor = &sensors[sensors.sensorsPriorized(i)];
// Check if it is enabled
if (wichSensor->enabled && wichSensor->priority != 250) {
if ( (lastSensorUpdate - wichSensor->lastReadingTime) >= (wichSensor->everyNint * config.readInterval) ||
(st.dynamic && ((lastSensorUpdate - wichSensor->lastReadingTime) >= dynamicInterval))) { // Is time to read it?
wichSensor->lastReadingTime = lastSensorUpdate; // Update sensor reading time
if (!getReading(wichSensor)) {
sprintf(outBuff, "Adding %s to pending sensor list", wichSensor->title);
sckOut(PRIO_LOW);
pendingSensorsLinkedList.add(wichSensor->type); // Read it or save it for later
} else {
sprintf(outBuff, "%s: %s %s", wichSensor->title, wichSensor->reading.c_str(), wichSensor->unit);
sckOut();
}
}
}
}

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions