Skip to content

Ported humidity (DHT) example to MySensors v2.0 and added some improvements #1

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

Merged
merged 5 commits into from
Jul 24, 2016

Conversation

mozzbozz
Copy link
Contributor

Here are the changes:

  • Renamed example from Humiditiy to DhtTemperatureAndHumiditySensor as this is what the example really is about (this example now also follows the naming scheme of DallasTemperatureSensor and MAX6875TemperatureSensor) --> I would suggest renaming the example on the mysensors.org webpage as well (there is no git repository for it, is there?)
  • Set the microcontroller to sleep for a longer period of time now by avoiding the usage of the delay()-function which was used at the beginning of the loop()-function before (for 1s with the DHT22 and 2s with the DHT11). To accomplish this, I've added a force parameter to the readSensor()-function of the DHT library - if it's set to true, the readSensors()-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 the millis()-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 avoid delaying 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)
  • Changed the return type of getMinimumSamplingPeriod() from int to unsigned 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)
  • Added 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)
  • Added 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"...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants