This repository has been archived by the owner on Oct 26, 2023. It is now read-only.
Limit light level readings from MiFlora sensors #273
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
I noticed that periodically one of my MiFlora-monitored plants would report a DLI way too high, which is impossible for my plants. This turned out to be because they were getting a single illumination value that was incredibly high. I tracked it down, and it seems to be something like 400 million, which is suspiciously like 2^32 / 10, which is the maximum value from the sensor (there is a division by 10.0 in the code).
It might be that an all-1 reading has some meaning within the protocol that the library does not account for. Or it might be that the sensors have some bug that sometimes returns that value. I am not sure.
The solution in this PR is a hack, which basically just throws out any illumination value that is unrealistically high. I chose 10 times the maximum daylight value, as listed on the Wikipedia:
https://en.wikipedia.org/wiki/Lux
It should have no impact on properly-functioning sensors returning reasonable values.
So far it has prevented any additional weird values, although it has not yet been running two days.
Type of change
Please delete options that are not relevant.