Added Nodemanger to temp_hum_sensor
This commit is contained in:
parent
a495f9a520
commit
525d8a323e
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
NodeManager is intended to take care on your behalf of all those common tasks a MySensors node has to accomplish, speeding up the development cycle of your projects.
|
||||
|
||||
NodeManager includes the following main components:
|
||||
- Sleep manager: allows managing automatically the complexity behind battery-powered sensors spending most of their time sleeping
|
||||
- Power manager: allows powering on your sensors only while the node is awake
|
||||
- Battery manager: provides common functionalities to read and report the battery level
|
||||
- Remote configuration: allows configuring remotely the node without the need to have physical access to it
|
||||
- Built-in personalities: for the most common sensors, provide embedded code so to allow their configuration with a single line
|
||||
|
||||
Documentation available on: https://github.com/mysensors/NodeManager
|
||||
*/
|
||||
|
||||
|
||||
// load user settings
|
||||
#include "config.h"
|
||||
// include supporting libraries
|
||||
#ifdef MY_GATEWAY_ESP8266
|
||||
#include <ESP8266WiFi.h>
|
||||
#endif
|
||||
// load MySensors library
|
||||
#include <MySensors.h>
|
||||
// load NodeManager library
|
||||
#include "NodeManager.h"
|
||||
|
||||
// create a NodeManager instance
|
||||
NodeManager nodeManager;
|
||||
|
||||
// before
|
||||
void before() {
|
||||
// setup the serial port baud rate
|
||||
Serial.begin(MY_BAUD_RATE);
|
||||
/*
|
||||
* Register below your sensors
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Register above your sensors
|
||||
*/
|
||||
nodeManager.before();
|
||||
}
|
||||
|
||||
// presentation
|
||||
void presentation() {
|
||||
// call NodeManager presentation routine
|
||||
nodeManager.presentation();
|
||||
}
|
||||
|
||||
// setup
|
||||
void setup() {
|
||||
// call NodeManager setup routine
|
||||
nodeManager.setup();
|
||||
}
|
||||
|
||||
// loop
|
||||
void loop() {
|
||||
// call NodeManager loop routine
|
||||
nodeManager.loop();
|
||||
|
||||
}
|
||||
|
||||
// receive
|
||||
void receive(const MyMessage &message) {
|
||||
// call NodeManager receive routine
|
||||
nodeManager.receive(message);
|
||||
}
|
||||
|
||||
// receiveTime
|
||||
void receiveTime(unsigned long ts) {
|
||||
// call NodeManager receiveTime routine
|
||||
nodeManager.receiveTime(ts);
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,134 @@
|
|||
#ifndef config_h
|
||||
#define config_h
|
||||
|
||||
/**********************************
|
||||
* Sketch configuration
|
||||
*/
|
||||
|
||||
#define SKETCH_NAME "NodeManager"
|
||||
#define SKETCH_VERSION "1.0"
|
||||
|
||||
/**********************************
|
||||
* MySensors node configuration
|
||||
*/
|
||||
|
||||
// General settings
|
||||
#define MY_BAUD_RATE 9600
|
||||
//#define MY_DEBUG
|
||||
//#define MY_NODE_ID 100
|
||||
|
||||
// NRF24 radio settings
|
||||
#define MY_RADIO_NRF24
|
||||
//#define MY_RF24_ENABLE_ENCRYPTION
|
||||
//#define MY_RF24_CHANNEL 76
|
||||
//#define MY_RF24_PA_LEVEL RF24_PA_HIGH
|
||||
//#define MY_DEBUG_VERBOSE_RF24
|
||||
|
||||
// RFM69 radio settings
|
||||
//#define MY_RADIO_RFM69
|
||||
//#define MY_RFM69_FREQUENCY RF69_868MHZ
|
||||
//#define MY_IS_RFM69HW
|
||||
//#define MY_DEBUG_VERBOSE_RFM69
|
||||
//#define MY_RFM69_NEW_DRIVER
|
||||
//#define MY_RFM69_ENABLE_ENCRYPTION
|
||||
//#define MY_RFM69_NETWORKID 100
|
||||
//#define MY_RF69_IRQ_PIN D1
|
||||
//#define MY_RF69_IRQ_NUM MY_RF69_IRQ_PIN
|
||||
//#define MY_RF69_SPI_CS D2
|
||||
|
||||
/**********************************
|
||||
* MySensors gateway configuration
|
||||
*/
|
||||
// Common gateway settings
|
||||
//#define MY_REPEATER_FEATURE
|
||||
|
||||
// Serial gateway settings
|
||||
//#define MY_GATEWAY_SERIAL
|
||||
|
||||
// Ethernet gateway settings
|
||||
//#define MY_GATEWAY_W5100
|
||||
|
||||
// ESP8266 gateway settings
|
||||
//#define MY_GATEWAY_ESP8266
|
||||
//#define MY_ESP8266_SSID ""
|
||||
//#define MY_ESP8266_PASSWORD ""
|
||||
|
||||
// Gateway networking settings
|
||||
//#define MY_IP_ADDRESS 192,168,178,87
|
||||
//#define MY_IP_GATEWAY_ADDRESS 192,168,178,1
|
||||
//#define MY_IP_SUBNET_ADDRESS 255,255,255,0
|
||||
//#define MY_PORT 5003
|
||||
//#define MY_GATEWAY_MAX_CLIENTS 2
|
||||
//#define MY_USE_UDP
|
||||
|
||||
// Gateway MQTT settings
|
||||
//#define MY_GATEWAY_MQTT_CLIENT
|
||||
//#define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 68
|
||||
//#define MY_PORT 1883
|
||||
//#define MY_MQTT_USER "username"
|
||||
//#define MY_MQTT_PASSWORD "password"
|
||||
//#define MY_MQTT_CLIENT_ID "mysensors-1"
|
||||
//#define MY_MQTT_PUBLISH_TOPIC_PREFIX "mygateway1-out"
|
||||
//#define MY_MQTT_SUBSCRIBE_TOPIC_PREFIX "mygateway1-in"
|
||||
|
||||
// Gateway inclusion mode
|
||||
//#define MY_INCLUSION_MODE_FEATURE
|
||||
//#define MY_INCLUSION_BUTTON_FEATURE
|
||||
//#define MY_INCLUSION_MODE_DURATION 60
|
||||
//#define MY_DEFAULT_LED_BLINK_PERIOD 300
|
||||
|
||||
// Gateway Leds settings
|
||||
//#define MY_DEFAULT_ERR_LED_PIN 4
|
||||
//#define MY_DEFAULT_RX_LED_PIN 5
|
||||
//#define MY_DEFAULT_TX_LED_PIN 6
|
||||
|
||||
/***********************************
|
||||
* NodeManager configuration
|
||||
*/
|
||||
|
||||
// if enabled, enable debug messages on serial port
|
||||
#define DEBUG 1
|
||||
|
||||
// if enabled, enable the capability to power on sensors with the arduino's pins to save battery while sleeping
|
||||
#define POWER_MANAGER 1
|
||||
// if enabled, will load the battery manager library to allow the battery level to be reported automatically or on demand
|
||||
#define BATTERY_MANAGER 1
|
||||
// if enabled, allow modifying the configuration remotely by interacting with the configuration child id
|
||||
#define REMOTE_CONFIGURATION 1
|
||||
// if enabled, persist the remote configuration settings on EEPROM
|
||||
#define PERSIST 0
|
||||
// if enabled, a battery sensor will be created at BATTERY_CHILD_ID and will report vcc voltage together with the battery level percentage
|
||||
#define BATTERY_SENSOR 1
|
||||
// if enabled, send a SLEEPING and AWAKE service messages just before entering and just after leaving a sleep cycle and STARTED when starting/rebooting
|
||||
#define SERVICE_MESSAGES 0
|
||||
|
||||
// Enable this module to use one of the following sensors: SENSOR_ANALOG_INPUT, SENSOR_LDR, SENSOR_THERMISTOR, SENSOR_MQ, SENSOR_ML8511, SENSOR_ACS712, SENSOR_RAIN_GAUGE
|
||||
#define MODULE_ANALOG_INPUT 1
|
||||
// Enable this module to use one of the following sensors: SENSOR_DIGITAL_INPUT
|
||||
#define MODULE_DIGITAL_INPUT 1
|
||||
// Enable this module to use one of the following sensors: SENSOR_DIGITAL_OUTPUT, SENSOR_RELAY, SENSOR_LATCHING_RELAY
|
||||
#define MODULE_DIGITAL_OUTPUT 1
|
||||
// Enable this module to use one of the following sensors: SENSOR_DHT11, SENSOR_DHT22
|
||||
#define MODULE_DHT 0
|
||||
// Enable this module to use one of the following sensors: SENSOR_SHT21
|
||||
#define MODULE_SHT21 0
|
||||
// Enable this module to use one of the following sensors: SENSOR_SWITCH, SENSOR_DOOR, SENSOR_MOTION
|
||||
#define MODULE_SWITCH 0
|
||||
// Enable this module to use one of the following sensors: SENSOR_DS18B20
|
||||
#define MODULE_DS18B20 0
|
||||
// Enable this module to use one of the following sensors: SENSOR_BH1750
|
||||
#define MODULE_BH1750 0
|
||||
// Enable this module to use one of the following sensors: SENSOR_MLX90614
|
||||
#define MODULE_MLX90614 0
|
||||
// Enable this module to use one of the following sensors: SENSOR_BME280
|
||||
#define MODULE_BME280 0
|
||||
// Enable this module to use one of the following sensors: SENSOR_SONOFF
|
||||
#define MODULE_SONOFF 0
|
||||
// Enable this module to use one of the following sensors: SENSOR_BMP085
|
||||
#define MODULE_BMP085 0
|
||||
// Enable this module to use one of the following sensors: SENSOR_HCSR04
|
||||
#define MODULE_HCSR04 0
|
||||
// Enable this module to use one of the following sensors: SENSOR_MCP9808
|
||||
#define MODULE_MCP9808 0
|
||||
#endif
|
||||
|
||||
|
|
@ -1,206 +0,0 @@
|
|||
/******************************************************************
|
||||
DHT Temperature & Humidity Sensor library for Arduino.
|
||||
|
||||
Features:
|
||||
- Support for DHT11 and DHT22/AM2302/RHT03
|
||||
- Auto detect sensor model
|
||||
- Very low memory footprint
|
||||
- Very small code
|
||||
|
||||
http://www.github.com/markruys/arduino-DHT
|
||||
|
||||
Written by Mark Ruys, mark@paracas.nl.
|
||||
|
||||
BSD license, check license.txt for more information.
|
||||
All text above must be included in any redistribution.
|
||||
|
||||
Datasheets:
|
||||
- http://www.micro4you.com/files/sensor/DHT11.pdf
|
||||
- http://www.adafruit.com/datasheets/DHT22.pdf
|
||||
- http://dlnmh9ip6v2uc.cloudfront.net/datasheets/Sensors/Weather/RHT03.pdf
|
||||
- http://meteobox.tk/files/AM2302.pdf
|
||||
|
||||
Changelog:
|
||||
2013-06-10: Initial version
|
||||
2013-06-12: Refactored code
|
||||
2013-07-01: Add a resetTimer method
|
||||
******************************************************************/
|
||||
|
||||
#include "DHT.h"
|
||||
|
||||
void DHT::setup(uint8_t pin, DHT_MODEL_t model)
|
||||
{
|
||||
DHT::pin = pin;
|
||||
DHT::model = model;
|
||||
DHT::resetTimer(); // Make sure we do read the sensor in the next readSensor()
|
||||
|
||||
if ( model == AUTO_DETECT) {
|
||||
DHT::model = DHT22;
|
||||
readSensor();
|
||||
if ( error == ERROR_TIMEOUT ) {
|
||||
DHT::model = DHT11;
|
||||
// Warning: in case we auto detect a DHT11, you should wait at least 1000 msec
|
||||
// before your first read request. Otherwise you will get a time out error.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DHT::resetTimer()
|
||||
{
|
||||
DHT::lastReadTime = millis() - 3000;
|
||||
}
|
||||
|
||||
float DHT::getHumidity()
|
||||
{
|
||||
readSensor();
|
||||
return humidity;
|
||||
}
|
||||
|
||||
float DHT::getTemperature()
|
||||
{
|
||||
readSensor();
|
||||
return temperature;
|
||||
}
|
||||
|
||||
#ifndef OPTIMIZE_SRAM_SIZE
|
||||
|
||||
const char* DHT::getStatusString()
|
||||
{
|
||||
switch ( error ) {
|
||||
case DHT::ERROR_TIMEOUT:
|
||||
return "TIMEOUT";
|
||||
|
||||
case DHT::ERROR_CHECKSUM:
|
||||
return "CHECKSUM";
|
||||
|
||||
default:
|
||||
return "OK";
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
// At the expense of 26 bytes of extra PROGMEM, we save 11 bytes of
|
||||
// SRAM by using the following method:
|
||||
|
||||
prog_char P_OK[] PROGMEM = "OK";
|
||||
prog_char P_TIMEOUT[] PROGMEM = "TIMEOUT";
|
||||
prog_char P_CHECKSUM[] PROGMEM = "CHECKSUM";
|
||||
|
||||
const char *DHT::getStatusString() {
|
||||
prog_char *c;
|
||||
switch ( error ) {
|
||||
case DHT::ERROR_CHECKSUM:
|
||||
c = P_CHECKSUM; break;
|
||||
|
||||
case DHT::ERROR_TIMEOUT:
|
||||
c = P_TIMEOUT; break;
|
||||
|
||||
default:
|
||||
c = P_OK; break;
|
||||
}
|
||||
|
||||
static char buffer[9];
|
||||
strcpy_P(buffer, c);
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void DHT::readSensor()
|
||||
{
|
||||
// Make sure we don't poll the sensor too often
|
||||
// - Max sample rate DHT11 is 1 Hz (duty cicle 1000 ms)
|
||||
// - Max sample rate DHT22 is 0.5 Hz (duty cicle 2000 ms)
|
||||
unsigned long startTime = millis();
|
||||
if ( (unsigned long)(startTime - lastReadTime) < (model == DHT11 ? 999L : 1999L) ) {
|
||||
return;
|
||||
}
|
||||
lastReadTime = startTime;
|
||||
|
||||
temperature = NAN;
|
||||
humidity = NAN;
|
||||
|
||||
// Request sample
|
||||
|
||||
digitalWrite(pin, LOW); // Send start signal
|
||||
pinMode(pin, OUTPUT);
|
||||
if ( model == DHT11 ) {
|
||||
delay(18);
|
||||
}
|
||||
else {
|
||||
// This will fail for a DHT11 - that's how we can detect such a device
|
||||
delayMicroseconds(800);
|
||||
}
|
||||
|
||||
pinMode(pin, INPUT);
|
||||
digitalWrite(pin, HIGH); // Switch bus to receive data
|
||||
|
||||
// We're going to read 83 edges:
|
||||
// - First a FALLING, RISING, and FALLING edge for the start bit
|
||||
// - Then 40 bits: RISING and then a FALLING edge per bit
|
||||
// To keep our code simple, we accept any HIGH or LOW reading if it's max 85 usecs long
|
||||
|
||||
uint16_t rawHumidity = 0;
|
||||
uint16_t rawTemperature = 0;
|
||||
uint16_t data = 0;
|
||||
|
||||
for ( int8_t i = -3 ; i < 2 * 40; i++ ) {
|
||||
byte age;
|
||||
startTime = micros();
|
||||
|
||||
do {
|
||||
age = (unsigned long)(micros() - startTime);
|
||||
if ( age > 90 ) {
|
||||
error = ERROR_TIMEOUT;
|
||||
return;
|
||||
}
|
||||
}
|
||||
while ( digitalRead(pin) == (i & 1) ? HIGH : LOW );
|
||||
|
||||
if ( i >= 0 && (i & 1) ) {
|
||||
// Now we are being fed our 40 bits
|
||||
data <<= 1;
|
||||
|
||||
// A zero max 30 usecs, a one at least 68 usecs.
|
||||
if ( age > 30 ) {
|
||||
data |= 1; // we got a one
|
||||
}
|
||||
}
|
||||
|
||||
switch ( i ) {
|
||||
case 31:
|
||||
rawHumidity = data;
|
||||
break;
|
||||
case 63:
|
||||
rawTemperature = data;
|
||||
data = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Verify checksum
|
||||
|
||||
if ( (byte)(((byte)rawHumidity) + (rawHumidity >> 8) + ((byte)rawTemperature) + (rawTemperature >> 8)) != data ) {
|
||||
error = ERROR_CHECKSUM;
|
||||
return;
|
||||
}
|
||||
|
||||
// Store readings
|
||||
|
||||
if ( model == DHT11 ) {
|
||||
humidity = rawHumidity >> 8;
|
||||
temperature = rawTemperature >> 8;
|
||||
}
|
||||
else {
|
||||
humidity = rawHumidity * 0.1;
|
||||
|
||||
if ( rawTemperature & 0x8000 ) {
|
||||
rawTemperature = -(int16_t)(rawTemperature & 0x7FFF);
|
||||
}
|
||||
temperature = ((int16_t)rawTemperature) * 0.1;
|
||||
}
|
||||
|
||||
error = ERROR_NONE;
|
||||
}
|
||||
|
|
@ -1,96 +0,0 @@
|
|||
/******************************************************************
|
||||
DHT Temperature & Humidity Sensor library for Arduino.
|
||||
|
||||
Features:
|
||||
- Support for DHT11 and DHT22/AM2302/RHT03
|
||||
- Auto detect sensor model
|
||||
- Very low memory footprint
|
||||
- Very small code
|
||||
|
||||
http://www.github.com/markruys/arduino-DHT
|
||||
|
||||
Written by Mark Ruys, mark@paracas.nl.
|
||||
|
||||
BSD license, check license.txt for more information.
|
||||
All text above must be included in any redistribution.
|
||||
|
||||
Datasheets:
|
||||
- http://www.micro4you.com/files/sensor/DHT11.pdf
|
||||
- http://www.adafruit.com/datasheets/DHT22.pdf
|
||||
- http://dlnmh9ip6v2uc.cloudfront.net/datasheets/Sensors/Weather/RHT03.pdf
|
||||
- http://meteobox.tk/files/AM2302.pdf
|
||||
|
||||
Changelog:
|
||||
2013-06-10: Initial version
|
||||
2013-06-12: Refactored code
|
||||
2013-07-01: Add a resetTimer method
|
||||
******************************************************************/
|
||||
|
||||
#ifndef dht_h
|
||||
#define dht_h
|
||||
|
||||
#if ARDUINO < 100
|
||||
#include <WProgram.h>
|
||||
#else
|
||||
#include <Arduino.h>
|
||||
#endif
|
||||
|
||||
class DHT
|
||||
{
|
||||
public:
|
||||
|
||||
typedef enum {
|
||||
AUTO_DETECT,
|
||||
DHT11,
|
||||
DHT22,
|
||||
AM2302, // Packaged DHT22
|
||||
RHT03 // Equivalent to DHT22
|
||||
}
|
||||
DHT_MODEL_t;
|
||||
|
||||
typedef enum {
|
||||
ERROR_NONE = 0,
|
||||
ERROR_TIMEOUT,
|
||||
ERROR_CHECKSUM
|
||||
}
|
||||
DHT_ERROR_t;
|
||||
|
||||
void setup(uint8_t pin, DHT_MODEL_t model=AUTO_DETECT);
|
||||
void resetTimer();
|
||||
|
||||
float getTemperature();
|
||||
float getHumidity();
|
||||
|
||||
DHT_ERROR_t getStatus() { return error; };
|
||||
const char* getStatusString();
|
||||
|
||||
DHT_MODEL_t getModel() { return model; }
|
||||
|
||||
int getMinimumSamplingPeriod() { return model == DHT11 ? 1000 : 2000; }
|
||||
|
||||
int8_t getNumberOfDecimalsTemperature() { return model == DHT11 ? 0 : 1; };
|
||||
int8_t getLowerBoundTemperature() { return model == DHT11 ? 0 : -40; };
|
||||
int8_t getUpperBoundTemperature() { return model == DHT11 ? 50 : 125; };
|
||||
|
||||
int8_t getNumberOfDecimalsHumidity() { return 0; };
|
||||
int8_t getLowerBoundHumidity() { return model == DHT11 ? 20 : 0; };
|
||||
int8_t getUpperBoundHumidity() { return model == DHT11 ? 90 : 100; };
|
||||
|
||||
static float toFahrenheit(float fromCelcius) { return 1.8 * fromCelcius + 32.0; };
|
||||
static float toCelsius(float fromFahrenheit) { return (fromFahrenheit - 32.0) / 1.8; };
|
||||
|
||||
protected:
|
||||
void readSensor();
|
||||
|
||||
float temperature;
|
||||
float humidity;
|
||||
|
||||
uint8_t pin;
|
||||
|
||||
private:
|
||||
DHT_MODEL_t model;
|
||||
DHT_ERROR_t error;
|
||||
unsigned long lastReadTime;
|
||||
};
|
||||
|
||||
#endif /*dht_h*/
|
||||
|
|
@ -1,49 +0,0 @@
|
|||
DHT
|
||||
===
|
||||
|
||||
An Arduino library for reading the DHT family of temperature and humidity sensors.
|
||||
|
||||
Written by Mark Ruys, <mark@paracas.nl>.
|
||||
|
||||
Features
|
||||
--------
|
||||
- Support for DHT11 and DHT22, AM2302, RHT03
|
||||
- Auto detect sensor model
|
||||
- Low memory footprint
|
||||
- Very small code
|
||||
|
||||
Usage
|
||||
-----
|
||||
|
||||
```
|
||||
#include "DHT.h"
|
||||
|
||||
DHT dht;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
|
||||
dht.setup(2); // data pin 2
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
delay(dht.getMinimumSamplingPeriod());
|
||||
|
||||
Serial.print(dht.getHumidity());
|
||||
Serial.print("\t");
|
||||
Serial.print(dht.getTemperature());
|
||||
}
|
||||
```
|
||||
Also check out the [example] how to read out your sensor. For all the options, see [dht.h][header].
|
||||
|
||||
Installation
|
||||
------------
|
||||
|
||||
Place the [DHT][download] library folder in your `<arduinosketchfolder>/libraries/` folder. You may need to create the `libraries` subfolder if its your first library. Restart the Arduino IDE.
|
||||
|
||||
[download]: https://github.com/markruys/arduino-DHT/archive/master.zip "Download DHT library"
|
||||
[example]: https://github.com/markruys/arduino-DHT/blob/master/examples/DHT_Test/DHT_Test.pde "Show DHT example"
|
||||
[header]: https://github.com/markruys/arduino-DHT/blob/master/DHT.h "Show header file"
|
||||
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
#include "DHT.h"
|
||||
|
||||
DHT dht;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
Serial.println();
|
||||
Serial.println("Status\tHumidity (%)\tTemperature (C)\t(F)");
|
||||
|
||||
dht.setup(2); // data pin 2
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
delay(dht.getMinimumSamplingPeriod());
|
||||
|
||||
float humidity = dht.getHumidity();
|
||||
float temperature = dht.getTemperature();
|
||||
|
||||
Serial.print(dht.getStatusString());
|
||||
Serial.print("\t");
|
||||
Serial.print(humidity, 1);
|
||||
Serial.print("\t\t");
|
||||
Serial.print(temperature, 1);
|
||||
Serial.print("\t\t");
|
||||
Serial.println(dht.toFahrenheit(temperature), 1);
|
||||
}
|
||||
|
||||
|
|
@ -1,42 +0,0 @@
|
|||
#######################################
|
||||
# Syntax Coloring Map For DHT
|
||||
#######################################
|
||||
|
||||
#######################################
|
||||
# Datatypes (KEYWORD1)
|
||||
#######################################
|
||||
|
||||
DHT KEYWORD1
|
||||
|
||||
#######################################
|
||||
# Methods and Functions (KEYWORD2)
|
||||
#######################################
|
||||
|
||||
setup KEYWORD2
|
||||
getTemperature KEYWORD2
|
||||
getHumidity KEYWORD2
|
||||
getStatus KEYWORD2
|
||||
getStatusString KEYWORD2
|
||||
getModel KEYWORD2
|
||||
getMinimumSamplingPeriod KEYWORD2
|
||||
toFahrenheit KEYWORD2
|
||||
toCelsius KEYWORD2
|
||||
|
||||
#######################################
|
||||
# Instances (KEYWORD2)
|
||||
#######################################
|
||||
|
||||
|
||||
#######################################
|
||||
# Constants (LITERAL1)
|
||||
#######################################
|
||||
|
||||
AUTO_DETECT LITERAL1
|
||||
DHT11 LITERAL1
|
||||
DHT22 LITERAL1
|
||||
AM2302 LITERAL1
|
||||
RHT03 LITERAL1
|
||||
|
||||
ERROR_NONE LITERAL1
|
||||
ERROR_TIMEOUT LITERAL1
|
||||
ERROR_CHECKSUM LITERAL1
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
Software License Agreement (BSD License)
|
||||
|
||||
Copyright (c) 2013, Mark Ruys. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the University of California, Berkeley nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,134 @@
|
|||
#ifndef config_h
|
||||
#define config_h
|
||||
|
||||
/**********************************
|
||||
* Sketch configuration
|
||||
*/
|
||||
|
||||
#define SKETCH_NAME "NodeManager"
|
||||
#define SKETCH_VERSION "1.0"
|
||||
|
||||
/**********************************
|
||||
* MySensors node configuration
|
||||
*/
|
||||
|
||||
// General settings
|
||||
#define MY_BAUD_RATE 9600
|
||||
//#define MY_DEBUG
|
||||
//#define MY_NODE_ID 100
|
||||
|
||||
// NRF24 radio settings
|
||||
#define MY_RADIO_NRF24
|
||||
//#define MY_RF24_ENABLE_ENCRYPTION
|
||||
//#define MY_RF24_CHANNEL 76
|
||||
//#define MY_RF24_PA_LEVEL RF24_PA_HIGH
|
||||
//#define MY_DEBUG_VERBOSE_RF24
|
||||
|
||||
// RFM69 radio settings
|
||||
//#define MY_RADIO_RFM69
|
||||
//#define MY_RFM69_FREQUENCY RF69_868MHZ
|
||||
//#define MY_IS_RFM69HW
|
||||
//#define MY_DEBUG_VERBOSE_RFM69
|
||||
//#define MY_RFM69_NEW_DRIVER
|
||||
//#define MY_RFM69_ENABLE_ENCRYPTION
|
||||
//#define MY_RFM69_NETWORKID 100
|
||||
//#define MY_RF69_IRQ_PIN D1
|
||||
//#define MY_RF69_IRQ_NUM MY_RF69_IRQ_PIN
|
||||
//#define MY_RF69_SPI_CS D2
|
||||
|
||||
/**********************************
|
||||
* MySensors gateway configuration
|
||||
*/
|
||||
// Common gateway settings
|
||||
//#define MY_REPEATER_FEATURE
|
||||
|
||||
// Serial gateway settings
|
||||
//#define MY_GATEWAY_SERIAL
|
||||
|
||||
// Ethernet gateway settings
|
||||
//#define MY_GATEWAY_W5100
|
||||
|
||||
// ESP8266 gateway settings
|
||||
//#define MY_GATEWAY_ESP8266
|
||||
//#define MY_ESP8266_SSID ""
|
||||
//#define MY_ESP8266_PASSWORD ""
|
||||
|
||||
// Gateway networking settings
|
||||
//#define MY_IP_ADDRESS 192,168,178,87
|
||||
//#define MY_IP_GATEWAY_ADDRESS 192,168,178,1
|
||||
//#define MY_IP_SUBNET_ADDRESS 255,255,255,0
|
||||
//#define MY_PORT 5003
|
||||
//#define MY_GATEWAY_MAX_CLIENTS 2
|
||||
//#define MY_USE_UDP
|
||||
|
||||
// Gateway MQTT settings
|
||||
//#define MY_GATEWAY_MQTT_CLIENT
|
||||
//#define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 68
|
||||
//#define MY_PORT 1883
|
||||
//#define MY_MQTT_USER "username"
|
||||
//#define MY_MQTT_PASSWORD "password"
|
||||
//#define MY_MQTT_CLIENT_ID "mysensors-1"
|
||||
//#define MY_MQTT_PUBLISH_TOPIC_PREFIX "mygateway1-out"
|
||||
//#define MY_MQTT_SUBSCRIBE_TOPIC_PREFIX "mygateway1-in"
|
||||
|
||||
// Gateway inclusion mode
|
||||
//#define MY_INCLUSION_MODE_FEATURE
|
||||
//#define MY_INCLUSION_BUTTON_FEATURE
|
||||
//#define MY_INCLUSION_MODE_DURATION 60
|
||||
//#define MY_DEFAULT_LED_BLINK_PERIOD 300
|
||||
|
||||
// Gateway Leds settings
|
||||
//#define MY_DEFAULT_ERR_LED_PIN 4
|
||||
//#define MY_DEFAULT_RX_LED_PIN 5
|
||||
//#define MY_DEFAULT_TX_LED_PIN 6
|
||||
|
||||
/***********************************
|
||||
* NodeManager configuration
|
||||
*/
|
||||
|
||||
// if enabled, enable debug messages on serial port
|
||||
#define DEBUG 1
|
||||
|
||||
// if enabled, enable the capability to power on sensors with the arduino's pins to save battery while sleeping
|
||||
#define POWER_MANAGER 1
|
||||
// if enabled, will load the battery manager library to allow the battery level to be reported automatically or on demand
|
||||
#define BATTERY_MANAGER 1
|
||||
// if enabled, allow modifying the configuration remotely by interacting with the configuration child id
|
||||
#define REMOTE_CONFIGURATION 1
|
||||
// if enabled, persist the remote configuration settings on EEPROM
|
||||
#define PERSIST 1
|
||||
// if enabled, a battery sensor will be created at BATTERY_CHILD_ID and will report vcc voltage together with the battery level percentage
|
||||
#define BATTERY_SENSOR 1
|
||||
// if enabled, send a SLEEPING and AWAKE service messages just before entering and just after leaving a sleep cycle and STARTED when starting/rebooting
|
||||
#define SERVICE_MESSAGES 0
|
||||
|
||||
// Enable this module to use one of the following sensors: SENSOR_ANALOG_INPUT, SENSOR_LDR, SENSOR_THERMISTOR, SENSOR_MQ, SENSOR_ML8511, SENSOR_ACS712, SENSOR_RAIN_GAUGE
|
||||
#define MODULE_ANALOG_INPUT 0
|
||||
// Enable this module to use one of the following sensors: SENSOR_DIGITAL_INPUT
|
||||
#define MODULE_DIGITAL_INPUT 0
|
||||
// Enable this module to use one of the following sensors: SENSOR_DIGITAL_OUTPUT, SENSOR_RELAY, SENSOR_LATCHING_RELAY
|
||||
#define MODULE_DIGITAL_OUTPUT 0
|
||||
// Enable this module to use one of the following sensors: SENSOR_DHT11, SENSOR_DHT22
|
||||
#define MODULE_DHT 1
|
||||
// Enable this module to use one of the following sensors: SENSOR_SHT21
|
||||
#define MODULE_SHT21 0
|
||||
// Enable this module to use one of the following sensors: SENSOR_SWITCH, SENSOR_DOOR, SENSOR_MOTION
|
||||
#define MODULE_SWITCH 0
|
||||
// Enable this module to use one of the following sensors: SENSOR_DS18B20
|
||||
#define MODULE_DS18B20 0
|
||||
// Enable this module to use one of the following sensors: SENSOR_BH1750
|
||||
#define MODULE_BH1750 0
|
||||
// Enable this module to use one of the following sensors: SENSOR_MLX90614
|
||||
#define MODULE_MLX90614 0
|
||||
// Enable this module to use one of the following sensors: SENSOR_BME280
|
||||
#define MODULE_BME280 0
|
||||
// Enable this module to use one of the following sensors: SENSOR_SONOFF
|
||||
#define MODULE_SONOFF 0
|
||||
// Enable this module to use one of the following sensors: SENSOR_BMP085
|
||||
#define MODULE_BMP085 0
|
||||
// Enable this module to use one of the following sensors: SENSOR_HCSR04
|
||||
#define MODULE_HCSR04 0
|
||||
// Enable this module to use one of the following sensors: SENSOR_MCP9808
|
||||
#define MODULE_MCP9808 0
|
||||
#endif
|
||||
|
||||
|
|
@ -1,142 +1,81 @@
|
|||
/**
|
||||
* The MySensors Arduino library handles the wireless radio link and protocol
|
||||
* between your home built sensors/actuators and HA controller of choice.
|
||||
* The sensors forms a self healing radio network with optional repeaters. Each
|
||||
* repeater and gateway builds a routing tables in EEPROM which keeps track of the
|
||||
* network topology allowing messages to be routed to nodes.
|
||||
*
|
||||
* Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
|
||||
* Copyright (C) 2013-2015 Sensnology AB
|
||||
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
|
||||
*
|
||||
* Documentation: http://www.mysensors.org
|
||||
* Support Forum: http://forum.mysensors.org
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
*******************************
|
||||
*
|
||||
* REVISION HISTORY
|
||||
* Version 1.0 - Henrik EKblad
|
||||
*
|
||||
* DESCRIPTION
|
||||
* This sketch provides an example how to implement a humidity/temperature
|
||||
* sensor using DHT11/DHT-22
|
||||
* http://www.mysensors.org/build/humidity
|
||||
/*
|
||||
NodeManager is intended to take care on your behalf of all those common tasks a MySensors node has to accomplish, speeding up the development cycle of your projects.
|
||||
|
||||
NodeManager includes the following main components:
|
||||
- Sleep manager: allows managing automatically the complexity behind battery-powered sensors spending most of their time sleeping
|
||||
- Power manager: allows powering on your sensors only while the node is awake
|
||||
- Battery manager: provides common functionalities to read and report the battery level
|
||||
- Remote configuration: allows configuring remotely the node without the need to have physical access to it
|
||||
- Built-in personalities: for the most common sensors, provide embedded code so to allow their configuration with a single line
|
||||
|
||||
Documentation available on: https://github.com/mysensors/NodeManager
|
||||
*/
|
||||
|
||||
// Enable debug prints
|
||||
#define MY_DEBUG
|
||||
|
||||
// Enable and select radio type attached
|
||||
#define MY_RADIO_NRF24
|
||||
#define MY_RF24_PA_LEVEL RF24_PA_LOW
|
||||
#if F_CPU == 8000000L
|
||||
#define MY_BAUD_RATE 38400
|
||||
// load user settings
|
||||
#include "config.h"
|
||||
// include supporting libraries
|
||||
#ifdef MY_GATEWAY_ESP8266
|
||||
#include <ESP8266WiFi.h>
|
||||
#endif
|
||||
|
||||
#define MY_GATEWAY_SERIAL
|
||||
//#define MY_RADIO_RFM69
|
||||
|
||||
#include <SPI.h>
|
||||
// load MySensors library
|
||||
#include <MySensors.h>
|
||||
#include <DHT.h>
|
||||
#define MY_NODE_ID 10
|
||||
#define MY_PARENT_NODE_ID 0
|
||||
#define CHILD_ID_HUM 0
|
||||
#define CHILD_ID_TEMP 1
|
||||
#define DHT_DATA_PIN 3
|
||||
// load NodeManager library
|
||||
#include "NodeManager.h"
|
||||
|
||||
static const uint64_t UPDATE_INTERVAL = 6000;
|
||||
static const uint8_t FORCE_UPDATE_N_READS = 10;
|
||||
// create a NodeManager instance
|
||||
NodeManager nodeManager;
|
||||
|
||||
DHT dht;
|
||||
float lastTemp;
|
||||
float lastHum;
|
||||
boolean metric = true;
|
||||
// before
|
||||
void before() {
|
||||
// setup the serial port baud rate
|
||||
Serial.begin(MY_BAUD_RATE);
|
||||
/*
|
||||
* Register below your sensors
|
||||
*/
|
||||
nodeManager.setSleep(SLEEP,10,MINUTES);
|
||||
nodeManager.setBatteryMin(1.8);
|
||||
nodeManager.setBatteryMax(2.4);
|
||||
nodeManager.setBatteryInternalVcc(true);
|
||||
nodeManager.setBatteryPin(A0);
|
||||
|
||||
uint8_t nNoUpdatesTemp;
|
||||
uint8_t nNoUpdatesHum;
|
||||
nodeManager.registerSensor(SENSOR_DHT11, 3);
|
||||
|
||||
MyMessage msgHum(CHILD_ID_HUM, V_HUM);
|
||||
MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
|
||||
|
||||
void setup()
|
||||
{
|
||||
dht.setup(DHT_DATA_PIN);
|
||||
|
||||
metric = getConfig().isMetric;
|
||||
if (UPDATE_INTERVAL <= dht.getMinimumSamplingPeriod()) {
|
||||
Serial.println("Warning: UPDATE_INTERVAL is smaller than supported by the sensor!");
|
||||
}
|
||||
MY_SERIALDEVICE.println(__FILE__);
|
||||
MY_SERIALDEVICE.println(MYSENSORS_LIBRARY_VERSION);
|
||||
MY_SERIALDEVICE.println(hwFreeMem());
|
||||
MY_SERIALDEVICE.println(hwCPUVoltage());
|
||||
MY_SERIALDEVICE.println(hwCPUFrequency());
|
||||
MY_SERIALDEVICE.println(F_CPU);
|
||||
MY_SERIALDEVICE.println(F("**********"));
|
||||
sleep(dht.getMinimumSamplingPeriod());
|
||||
/*
|
||||
* Register above your sensors
|
||||
*/
|
||||
nodeManager.before();
|
||||
}
|
||||
|
||||
void presentation()
|
||||
{
|
||||
// Send the Sketch Version Information to the Gateway
|
||||
sendSketchInfo("Humidity", "1.0");
|
||||
// presentation
|
||||
void presentation() {
|
||||
// call NodeManager presentation routine
|
||||
nodeManager.presentation();
|
||||
}
|
||||
|
||||
// Register all sensors to gw (they will be created as child devices)
|
||||
present(CHILD_ID_HUM, S_HUM);
|
||||
present(CHILD_ID_TEMP, S_TEMP);
|
||||
// setup
|
||||
void setup() {
|
||||
// call NodeManager setup routine
|
||||
nodeManager.setup();
|
||||
}
|
||||
|
||||
// loop
|
||||
void loop() {
|
||||
// call NodeManager loop routine
|
||||
nodeManager.loop();
|
||||
|
||||
}
|
||||
|
||||
// receive
|
||||
void receive(const MyMessage &message) {
|
||||
// call NodeManager receive routine
|
||||
nodeManager.receive(message);
|
||||
}
|
||||
|
||||
// receiveTime
|
||||
void receiveTime(unsigned long ts) {
|
||||
// call NodeManager receiveTime routine
|
||||
nodeManager.receiveTime(ts);
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
delay(dht.getMinimumSamplingPeriod());
|
||||
|
||||
float temperature = dht.getTemperature();
|
||||
if (isnan(temperature)) {
|
||||
Serial.println("Failed reading temperature from DHT");
|
||||
} else if (temperature != lastTemp ||
|
||||
nNoUpdatesTemp == FORCE_UPDATE_N_READS) {
|
||||
lastTemp = temperature;
|
||||
if (!metric) {
|
||||
temperature = dht.toFahrenheit(temperature);
|
||||
}
|
||||
|
||||
nNoUpdatesTemp = 0;
|
||||
send(msgTemp.set(temperature, 1));
|
||||
#ifdef MYDEBUG
|
||||
Serial.print("T: ");
|
||||
Serial.println(temperature);
|
||||
#endif
|
||||
|
||||
} else {
|
||||
// Increase no update counter if the temperature stayed the same
|
||||
nNoUpdatesTemp++;
|
||||
}
|
||||
|
||||
float humidity = dht.getHumidity();
|
||||
if (isnan(humidity)) {
|
||||
Serial.println("Failed reading humidity from DHT");
|
||||
} else if (humidity != lastHum || nNoUpdatesHum == FORCE_UPDATE_N_READS) {
|
||||
// Only send humidity if it changed since the last measurement or if we didn't send an update for n times
|
||||
lastHum = humidity;
|
||||
// Reset no updates counter
|
||||
nNoUpdatesHum = 0;
|
||||
send(msgHum.set(humidity, 1));
|
||||
|
||||
#ifdef MY_DEBUG
|
||||
Serial.print("H: ");
|
||||
Serial.println(humidity);
|
||||
#endif
|
||||
} else {
|
||||
// Increase no update counter if the humidity stayed the same
|
||||
nNoUpdatesHum++;
|
||||
}
|
||||
|
||||
|
||||
sleep(UPDATE_INTERVAL); //sleep a bit
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue