-
Notifications
You must be signed in to change notification settings - Fork 20
Bugfix/sen5x voc state #88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Remove the fork as adafruit has refurbished it and we do not need a fork for this anymore. They can now pass a Wire object to the begin.
* Fixes size for VOC state accounting for CRC * Adds checks for model version clash
If continuous mode is activated most SEN5X readings went wrong because the already read values weren't returned but get_reading() returned an error state. By checking if update() failed because of no new values available in continuous mode (SEN54 and SEN55) we can return the stored values safely.
… into bugfix/sen5x-voc-state
|
I'm quite convinced this version won't work. The format of the state bytes are the same for reading and writing, so you have to insert the CRC bytes again when you send the state to the sensor. The previous version where you stored the CRC bytes together with the state probably worked as the state was sent in exactly the same format as it was received. For me the saving of the VOC state isn't that important because I have a Kit 2.3 which comes with a battery so the sensor won't ever be without power (if SEN55 sensors are activated of course, so the software is in continuous mode), the VOC state doesn't have to be saved. |
Issue is (I think) that when sending the VOCState buffer back, the CRC is re-added on the smartcitizen-kit-2x/sam/src/SckUrban.cpp Lines 2476 to 2493 in 803d3f2
Which leads me to think that what we are sending back to the VOC state is wrong, hence this PR.
Sure. Just keep in mind that the device however resets every night (in CET) for a sanity reset. This can be disabled in the shell. Ideally, the VOC state is saved before every reset, but I am not fully confident this works at the moment. |
|
You're right, I'm wrong. I didn't consider the I uploaded the code with this branch applied and wait to see how it performs. |
|
I guess the call to vocStateFromSensor() in idle() should be eliminated because if the VOC sensor is active we're always in continuous mode so that call is never reached. If VOC sensor isn't active we don't need to save the state. |
|
I think we are now onto something (see data from comparison here: https://api.smartcitizen.me/ui/experiments/29/)
The importance to recover well the voc index state can be seen at the midnight reset. I'll set two devices with bugfix |
That's now the tricky part. Either we get it periodically (still to figure out how), or on |
Periodically isn't that hard, just save the time of the last save and check the time difference at every |
|
I was wrong again, we don't have to leave measurement mode to read the VOC state from the sensor, that seems to be necessary only for writing it back, although I couldn't find the reason for that in the datasheet. |
|
Hey, so the approach currently implemented on the latest commit (8dce8f3) is more or less as you mention, but with some slight differences:
The particularity is the "incorrect shutdown" process, which would lose the latest vocState. This is a downside but it doesnt matter so much. We could have the vocstate stored into EEPROM after every read, but we have limited read/writes, and we don't want to kill it. |
Why does it have to be not too old? If a user switches the device off for the night for example, why shouldn't we use the saved VOC state once the device is turned on in the morning?
Why is it read that often? Why not reading it just before we reset/go to sleep?
Could you give more information on that? Do you mean the shutoff by long pressing the button? EEPROM has limited writes but that number is very hight (>100'000). Why do you think the device will be turned off that often? |
"Short" isn't a defined time period. Given that the sensor needs 12 hours of continuous operation to even establish a VOC state I would say that every time frame that is less than that is "short".
It cannot be in off state because the VOC sensor requires continuous mode and the storage of the VOC state may be and probably should be coupled to that mode.
I don't understand why you insist on saving the VOC state even when the VOC sensor is inactive. If you have to handle the case where the sensor is turned on and off you add complexity without a need. The VOC state is only needed if the VOC index is used and in that case the continuous mode is used where the device will not be turned off. |
That's incorrect. Sensor requires roughly 1h to give good Voc state. Actually, non-zero VOC states (who knows if valid or not) are returned after very few minutes of sensor operation. See the issue in the manufacturer repository I opened a while back and their answer
Yes it can. You can disable the sensor manually, and ultimately the idea is to save battery by not having the sensor constantly powered.
I don't understand the "insist on saving the VOC state even if the sensor is inactive". The voc state will be queried, and then saved if it returns a valid response. There's no need to handle anything complex, I don't know where that comes from. As per the Sen54-55 you are right. For whatever reason I got that mixed up. |
Sure you can disable the sensor but in that case you don't need the VOC state to be saved over resets/power offs. If the user is not interested in the VOC index value (sensor disabled) it doesn't matter what value is read from the sensor and if that value makes sense.
I understood that but as mentioned above I see no need to save the state if the user don't need the VOC index value. |
|
Further work on this:
On the bright side of things, the Battery Enhanced by a very long-shot VOC index (still one value is 0 after recovering, but it comes back to a "reasonable" spot - no way to judge though) |






Fixes #87