Ported humidity (DHT) example to MySensors v2.0 and added some improvements #1
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.
Here are the changes:
delay()
-function which was used at the beginning of theloop()
-function before (for 1s with the DHT22 and 2s with the DHT11). To accomplish this, I've added aforce
parameter to thereadSensor()
-function of the DHT library - if it's set totrue
, thereadSensors()
-function will poll the sensor without checking the interval from the last sensor reading. The reason for this is that the microcontroller doesn't continue increasing the value returned by themillis()
-function: If the sensor is polled for the first time, then the Arduino sleeps for 10 seconds and then polls the sensor for the second time, it would work without any problems (the sensor would be capable of this) - just that the library isn't aware of the sleeping and "thinks" the sensor isn't ready for polling it again. This change means, that the example source code should be more energy efficient than the original example as we avoiddelay
ing for 1 or 2 seconds now... (the change to the DHT library shouldn't break any existing source code as it's optional to use)getMinimumSamplingPeriod()
fromint
tounsigned int
as this just makes sense (there can't be any negative sampling period) and this gets rid of compiler warnings (assuming that you compare the returned value with an unsigned int)SENSOR_TEMP_OFFSET
define (my DHT22 always shows a temperature ~ 0.3°C above the one my other thermometers are showing, so I set this define to-0.3
in my case)FORCE_UPDATE_N_READS
define - if this is set to e.g. 10, this would mean, that the sensor sends the temperature / humidity if the sensor read the same value for the 10th time (this is useful for controllers which display a timestamp of the last received value; you might be ok with "2 minutes ago", but maybe not with "15 minutes ago"...)