Commit f22ad111 authored by DV's avatar DV
Browse files

Release v1.2

parent ae3029ac
...@@ -21,10 +21,10 @@ const char* WAKEUP = "WAKEUP"; ...@@ -21,10 +21,10 @@ const char* WAKEUP = "WAKEUP";
// set the vcc and ground pin the sensor is connected to // set the vcc and ground pin the sensor is connected to
void PowerManager::setPowerPins(int ground_pin, int vcc_pin, long wait = 10) { void PowerManager::setPowerPins(int ground_pin, int vcc_pin, long wait = 10) {
#if DEBUG == 1 #if DEBUG == 1
Serial.print("POWER V="); Serial.print("POWER G=");
Serial.print(vcc_pin); Serial.print(ground_pin);
Serial.print(" G="); Serial.print(" V=");
Serial.println(ground_pin); Serial.println(vcc_pin);
#endif #endif
// configure the vcc pin as output and initialize to low (power off) // configure the vcc pin as output and initialize to low (power off)
_vcc_pin = vcc_pin; _vcc_pin = vcc_pin;
...@@ -619,7 +619,7 @@ void SensorDHT::onReceive(const MyMessage & message) { ...@@ -619,7 +619,7 @@ void SensorDHT::onReceive(const MyMessage & message) {
*/ */
#if MODULE_SHT21 == 1 #if MODULE_SHT21 == 1
// contructor // contructor
SensorSHT21::SensorSHT21(int child_id, int sensor_type): Sensor(child_id, -1) { SensorSHT21::SensorSHT21(int child_id, int sensor_type): Sensor(child_id,A2) {
// store the sensor type (0: temperature, 1: humidity) // store the sensor type (0: temperature, 1: humidity)
_sensor_type = sensor_type; _sensor_type = sensor_type;
if (_sensor_type == 0) { if (_sensor_type == 0) {
...@@ -681,6 +681,15 @@ void SensorSHT21::onReceive(const MyMessage & message) { ...@@ -681,6 +681,15 @@ void SensorSHT21::onReceive(const MyMessage & message) {
} }
#endif #endif
/*
* SensorHTU21D
*/
#if MODULE_SHT21 == 1
// constructor
SensorHTU21D::SensorHTU21D(int child_id, int pin): SensorSHT21(child_id, pin) {
}
#endif
/* /*
* SensorSwitch * SensorSwitch
*/ */
...@@ -795,8 +804,81 @@ void SensorDs18b20::onLoop() { ...@@ -795,8 +804,81 @@ void SensorDs18b20::onLoop() {
void SensorDs18b20::onReceive(const MyMessage & message) { void SensorDs18b20::onReceive(const MyMessage & message) {
onLoop(); onLoop();
} }
#endif
/*
SensorBH1750
*/
#if MODULE_BH1750 == 1
// contructor
SensorBH1750::SensorBH1750(int child_id): Sensor(child_id,A4) {
setPresentation(S_LIGHT_LEVEL);
setType(V_LEVEL);
_lightSensor = new BH1750();
}
// what do to during setup
void SensorBH1750::onBefore() {
_lightSensor->begin();
}
// what do to during loop
void SensorBH1750::onLoop() {
// request the light level
_value_int = _lightSensor->readLightLevel();
#if DEBUG == 1
Serial.print("BH1 I=");
Serial.print(_child_id);
Serial.print(" L=");
Serial.println(_value_int);
#endif
}
// what do to as the main task when receiving a message
void SensorBH1750::onReceive(const MyMessage & message) {
onLoop();
}
#endif
/*
SensorMLX90614
*/
#if MODULE_MLX90614 == 1
// contructor
SensorMLX90614::SensorMLX90614(int child_id, Adafruit_MLX90614* mlx, int sensor_type): Sensor(child_id,A4) {
// store the sensor type (0: ambient, 1: object)
_sensor_type = sensor_type;
_mlx = mlx;
// set presentation and type
setPresentation(S_TEMP);
setType(V_TEMP);
setValueType(TYPE_FLOAT);
}
// what do to during setup
void SensorMLX90614::onBefore() {
// initialize the library
_mlx->begin();
}
// what do to during loop
void SensorMLX90614::onLoop() {
float temperature = _sensor_type == 0 ? _mlx->readAmbientTempC() : _mlx->readObjectTempC();
// convert it
if (! getControllerConfig().isMetric) temperature = temperature * 1.8 + 32;
#if DEBUG == 1
Serial.print("MLX I=");
Serial.print(_child_id);
Serial.print(" T=");
Serial.println(temperature);
#endif
if (! isnan(temperature)) _value_float = temperature;
}
// what do to as the main task when receiving a message
void SensorMLX90614::onReceive(const MyMessage & message) {
onLoop();
}
#endif #endif
/******************************************* /*******************************************
...@@ -915,6 +997,11 @@ int NodeManager::registerSensor(int sensor_type, int pin = -1, int child_id = -1 ...@@ -915,6 +997,11 @@ int NodeManager::registerSensor(int sensor_type, int pin = -1, int child_id = -1
child_id = _getAvailableChildId(); child_id = _getAvailableChildId();
registerSensor(new SensorSHT21(child_id,1)); registerSensor(new SensorSHT21(child_id,1));
} }
else if (sensor_type == SENSOR_HTU21D) {
registerSensor(new SensorHTU21D(child_id,0));
child_id = _getAvailableChildId();
registerSensor(new SensorHTU21D(child_id,1));
}
#endif #endif
#if MODULE_SWITCH == 1 #if MODULE_SWITCH == 1
else if (sensor_type == SENSOR_SWITCH || sensor_type == SENSOR_DOOR || sensor_type == SENSOR_MOTION) { else if (sensor_type == SENSOR_SWITCH || sensor_type == SENSOR_DOOR || sensor_type == SENSOR_MOTION) {
...@@ -944,6 +1031,22 @@ int NodeManager::registerSensor(int sensor_type, int pin = -1, int child_id = -1 ...@@ -944,6 +1031,22 @@ int NodeManager::registerSensor(int sensor_type, int pin = -1, int child_id = -1
} }
} }
#endif #endif
#if MODULE_BH1750 == 1
else if (sensor_type == SENSOR_BH1750) {
return registerSensor(new SensorBH1750(child_id));
}
#endif
#if MODULE_MLX90614 == 1
else if (sensor_type == SENSOR_MLX90614) {
Serial.println("1");
Adafruit_MLX90614* mlx = new Adafruit_MLX90614();
Serial.println("2");
registerSensor(new SensorMLX90614(child_id,mlx,0));
Serial.println("3");
child_id = _getAvailableChildId();
registerSensor(new SensorMLX90614(child_id,mlx,1));
}
#endif
else { else {
#if DEBUG == 1 #if DEBUG == 1
Serial.print("INVALID "); Serial.print("INVALID ");
...@@ -965,6 +1068,8 @@ int NodeManager::registerSensor(Sensor* sensor) { ...@@ -965,6 +1068,8 @@ int NodeManager::registerSensor(Sensor* sensor) {
Serial.print(" T="); Serial.print(" T=");
Serial.println(sensor->getType()); Serial.println(sensor->getType());
#endif #endif
// set auto power pin
sensor->setAutoPowerPins(_auto_power_pins);
// add the sensor to the array of registered sensors // add the sensor to the array of registered sensors
_sensors[sensor->getChildId()] = sensor; _sensors[sensor->getChildId()] = sensor;
// return the child_id // return the child_id
...@@ -1114,7 +1219,7 @@ void NodeManager::loop() { ...@@ -1114,7 +1219,7 @@ void NodeManager::loop() {
// dispacth inbound messages // dispacth inbound messages
void NodeManager::receive(const MyMessage &message) { void NodeManager::receive(const MyMessage &message) {
#if DEBUG == 1 #if DEBUG == 1
Serial.print("RECV F="); Serial.print("RECV S=");
Serial.print(message.sender); Serial.print(message.sender);
Serial.print(" I="); Serial.print(" I=");
Serial.print(message.sensor); Serial.print(message.sensor);
...@@ -1133,13 +1238,13 @@ void NodeManager::receive(const MyMessage &message) { ...@@ -1133,13 +1238,13 @@ void NodeManager::receive(const MyMessage &message) {
else if (message.getCommand() == C_REQ && _sensors[message.sensor] != 0) { else if (message.getCommand() == C_REQ && _sensors[message.sensor] != 0) {
#if POWER_MANAGER == 1 #if POWER_MANAGER == 1
// turn on the pin powering all the sensors // turn on the pin powering all the sensors
powerOn(); if (_auto_power_pins) powerOn();
#endif #endif
// call the sensor's receive() // call the sensor's receive()
_sensors[message.sensor]->receive(message); _sensors[message.sensor]->receive(message);
#if POWER_MANAGER == 1 #if POWER_MANAGER == 1
// turn off the pin powering all the sensors // turn off the pin powering all the sensors
powerOff(); if (_auto_power_pins) powerOff();
#endif #endif
} }
} }
......
...@@ -41,7 +41,7 @@ ...@@ -41,7 +41,7 @@
#define EEPROM_SLEEP_UNIT 4 #define EEPROM_SLEEP_UNIT 4
// define NodeManager version // define NodeManager version
#define VERSION 1.1 #define VERSION 1.2
/************************************ /************************************
* Include user defined configuration settings * Include user defined configuration settings
...@@ -109,7 +109,7 @@ ...@@ -109,7 +109,7 @@
#ifndef MODULE_DIGITAL_OUTPUT #ifndef MODULE_DIGITAL_OUTPUT
#define MODULE_DIGITAL_OUTPUT 0 #define MODULE_DIGITAL_OUTPUT 0
#endif #endif
// Enable this module to use one of the following sensors: SENSOR_SHT21 // Enable this module to use one of the following sensors: SENSOR_SHT21, SENSOR_HTU21D
#ifndef MODULE_SHT21 #ifndef MODULE_SHT21
#define MODULE_SHT21 0 #define MODULE_SHT21 0
#endif #endif
...@@ -125,7 +125,14 @@ ...@@ -125,7 +125,14 @@
#ifndef MODULE_DS18B20 #ifndef MODULE_DS18B20
#define MODULE_DS18B20 0 #define MODULE_DS18B20 0
#endif #endif
// Enable this module to use one of the following sensors: SENSOR_BH1750
#ifndef MODULE_BH1750
#define MODULE_BH1750 0
#endif
// Enable this module to use one of the following sensors: SENSOR_MLX90614
#ifndef MODULE_MLX90614
#define MODULE_MLX90614 0
#endif
/*********************************** /***********************************
Sensors types Sensors types
...@@ -158,6 +165,7 @@ ...@@ -158,6 +165,7 @@
#if MODULE_SHT21 == 1 #if MODULE_SHT21 == 1
// SHT21 sensor, return temperature/humidity based on the attached SHT21 sensor // SHT21 sensor, return temperature/humidity based on the attached SHT21 sensor
#define SENSOR_SHT21 10 #define SENSOR_SHT21 10
#define SENSOR_HTU21D 15
#endif #endif
#if MODULE_SWITCH == 1 #if MODULE_SWITCH == 1
// Generic switch, wake up the board when a pin changes status // Generic switch, wake up the board when a pin changes status
...@@ -171,7 +179,16 @@ ...@@ -171,7 +179,16 @@
// DS18B20 sensor, return the temperature based on the attached sensor // DS18B20 sensor, return the temperature based on the attached sensor
#define SENSOR_DS18B20 14 #define SENSOR_DS18B20 14
#endif #endif
#if MODULE_BH1750 == 1
// BH1750 sensor, return light in lux
#define SENSOR_BH1750 16
#endif
#if MODULE_MLX90614 == 1
// MLX90614 sensor, contactless temperature sensor
#define SENSOR_MLX90614 17
#endif
// last Id: 17
/*********************************** /***********************************
Libraries Libraries
*/ */
...@@ -188,15 +205,18 @@ ...@@ -188,15 +205,18 @@
#include <Wire.h> #include <Wire.h>
#include <Sodaq_SHT2x.h> #include <Sodaq_SHT2x.h>
#endif #endif
#if MODULE_SHT21 == 1
#include <Wire.h>
#include <Sodaq_SHT2x.h>
#endif
#if MODULE_DS18B20 == 1 #if MODULE_DS18B20 == 1
#include <OneWire.h> #include <OneWire.h>
#include <DallasTemperature.h> #include <DallasTemperature.h>
#endif #endif
#if MODULE_BH1750 == 1
#include <BH1750.h>
#include <Wire.h>
#endif
#if MODULE_MLX90614 == 1
#include <Wire.h>
#include <Adafruit_MLX90614.h>
#endif
/************************************** /**************************************
Classes Classes
...@@ -438,7 +458,7 @@ class SensorDHT: public Sensor { ...@@ -438,7 +458,7 @@ class SensorDHT: public Sensor {
#endif #endif
/* /*
SensorSHT21 SensorSHT21: temperature and humidity sensor
*/ */
#if MODULE_SHT21 == 1 #if MODULE_SHT21 == 1
class SensorSHT21: public Sensor { class SensorSHT21: public Sensor {
...@@ -452,6 +472,15 @@ class SensorSHT21: public Sensor { ...@@ -452,6 +472,15 @@ class SensorSHT21: public Sensor {
float _offset = 0; float _offset = 0;
int _sensor_type = 0; int _sensor_type = 0;
}; };
/*
SensorHTU21D: temperature and humidity sensor
*/
class SensorHTU21D: public SensorSHT21 {
public:
SensorHTU21D(int child_id, int pin);
};
#endif #endif
/* /*
...@@ -511,6 +540,38 @@ class SensorDs18b20: public Sensor { ...@@ -511,6 +540,38 @@ class SensorDs18b20: public Sensor {
}; };
#endif #endif
/*
SensorBH1750
*/
#if MODULE_BH1750 == 1
class SensorBH1750: public Sensor {
public:
SensorBH1750(int child_id);
// define what to do at each stage of the sketch
void onBefore();
void onLoop();
void onReceive(const MyMessage & message);
protected:
BH1750* _lightSensor;
};
#endif
/*
SensorMLX90614
*/
#if MODULE_MLX90614 == 1
class SensorMLX90614: public Sensor {
public:
SensorMLX90614(int child_id, Adafruit_MLX90614* mlx, int sensor_type);
// define what to do at each stage of the sketch
void onBefore();
void onLoop();
void onReceive(const MyMessage & message);
protected:
Adafruit_MLX90614* _mlx;
int _sensor_type;
};
#endif
/*************************************** /***************************************
NodeManager: manages all the aspects of the node NodeManager: manages all the aspects of the node
......
...@@ -28,12 +28,12 @@ void before() { ...@@ -28,12 +28,12 @@ void before() {
Serial.begin(9600); Serial.begin(9600);
/* /*
* Register below your sensors * Register below your sensors
*/ */
/* /*
* Register above your sensors * Register above your sensors
*/ */
nodeManager.before(); nodeManager.before();
} }
......
Welcome to NodeManager (v1.1) [NodeManager]
# Introduction # Introduction
...@@ -40,7 +40,21 @@ Please note NodeManager cannot be used as an arduino library since requires acce ...@@ -40,7 +40,21 @@ Please note NodeManager cannot be used as an arduino library since requires acce
NodeManager configuration includes compile-time configuration directives (which can be set in config.h), runtime global and per-sensor configuration settings (which can be set in your sketch) and settings that can be customized remotely (via a special child id). NodeManager configuration includes compile-time configuration directives (which can be set in config.h), runtime global and per-sensor configuration settings (which can be set in your sketch) and settings that can be customized remotely (via a special child id).
## Setup MySensors ## Setup MySensors
Since NodeManager has to communicate with the MySensors gateway on your behalf, it has to know how to do it. Place on top of the `config.h` file all the MySensors typical directives you are used to set on top of your sketch so both your sketch AND NodeManager will be able to share the same configuration. Since NodeManager has to communicate with the MySensors gateway on your behalf, it has to know how to do it. Place on top of the `config.h` file all the MySensors typical directives you are used to set on top of your sketch so both your sketch AND NodeManager will be able to share the same configuration. For example:
~~~c
//#define MY_DEBUG
#define MY_NODE_ID 100
#define MY_RADIO_NRF24
//#define MY_RF24_ENABLE_ENCRYPTION
//#define MY_RF24_CHANNEL 76
//#define MY_RADIO_RFM69
//#define MY_RFM69_FREQUENCY RF69_868MHZ
//#define MY_IS_RFM69HW
//#define MY_RFM69_ENABLE_ENCRYPTION
//#define MY_RFM69_NETWORKID 100
~~~
## Enable/Disable NodeManager's modules ## Enable/Disable NodeManager's modules
...@@ -80,8 +94,24 @@ Those NodeManager's directives in the `config.h` file control which module/libra ...@@ -80,8 +94,24 @@ Those NodeManager's directives in the `config.h` file control which module/libra
#define MODULE_SWITCH 0 #define MODULE_SWITCH 0
// Enable this module to use one of the following sensors: SENSOR_DS18B20 // Enable this module to use one of the following sensors: SENSOR_DS18B20
#define MODULE_DS18B20 0 #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
~~~ ~~~
## Installing the dependencies
Some of the modules above rely on third party libraries. Those libraries are not included within NodeManager and have to be installed from the Arduino IDE Library Manager (Sketch -> Include Library -> Manager Libraries). You need to install the library ONLY if the module is enabled:
Module | Required Library
------------- | -------------
MODULE_SHT21 | https://github.com/SodaqMoja/Sodaq_SHT2x
MODULE_DHT | https://github.com/adafruit/DHT-sensor-library
MODULE_DS18B20 | https://github.com/milesburton/Arduino-Temperature-Control-Library
MODULE_BH1750 | https://github.com/claws/BH1750
MODULE_MLX90614 | https://github.com/adafruit/Adafruit-MLX90614-Library
## Configure NodeManager ## Configure NodeManager
Node Manager comes with a reasonable default configuration. If you want/need to change its settings, this can be done in your sketch, inside the `before()` function and just before registering your sensors. The following methods are exposed for your convenience: Node Manager comes with a reasonable default configuration. If you want/need to change its settings, this can be done in your sketch, inside the `before()` function and just before registering your sensors. The following methods are exposed for your convenience:
...@@ -157,6 +187,9 @@ SENSOR_SWITCH | Generic switch, wake up the board when a pin changes status ...@@ -157,6 +187,9 @@ SENSOR_SWITCH | Generic switch, wake up the board when a pin changes status
SENSOR_DOOR | Door sensor, wake up the board and report when an attached magnetic sensor has been opened/closed SENSOR_DOOR | Door sensor, wake up the board and report when an attached magnetic sensor has been opened/closed
SENSOR_MOTION | Motion sensor, wake up the board and report when an attached PIR has triggered SENSOR_MOTION | Motion sensor, wake up the board and report when an attached PIR has triggered
SENSOR_DS18B20 | DS18B20 sensor, return the temperature based on the attached sensor SENSOR_DS18B20 | DS18B20 sensor, return the temperature based on the attached sensor
SENSOR_HTU21D | HTU21D sensor, return temperature/humidity based on the attached HTU21D sensor
SENSOR_BH1750 | BH1750 sensor, return light level in lux
SENSOR_MLX90614 | MLX90614 contactless temperature sensor, return ambient and object temperature
To register a sensor simply call the NodeManager instance with the sensory type and the pin the sensor is conncted to. For example: To register a sensor simply call the NodeManager instance with the sensory type and the pin the sensor is conncted to. For example:
~~~c ~~~c
...@@ -377,75 +410,61 @@ A NodeManager object must be created and called from within your sketch during ` ...@@ -377,75 +410,61 @@ A NodeManager object must be created and called from within your sketch during `
* Invoke `Sensor::loop()` which will execute the sensor main taks and eventually call `Sensor::onReceive()` * Invoke `Sensor::loop()` which will execute the sensor main taks and eventually call `Sensor::onReceive()`
# Examples # Examples
All the examples below takes place within the before() function in the main sketch, just below the "Register below your sensors" comment.
Enable reboot pin, connect pin 4 to RST to enable rebooting the board with the REBOOT message: Enable reboot pin, connect pin 4 to RST to enable rebooting the board with the REBOOT message:
~~~c ~~~c
void before() {
nodeManager.setRebootPin(4); nodeManager.setRebootPin(4);
nodeManager.before();
}
~~~ ~~~
Set battery minimum and maxium voltage. This will be used to calculate the level percentage: Set battery minimum and maxium voltage. This will be used to calculate the level percentage:
~~~c ~~~c
void before() {
nodeManager.setBatteryMin(1.8); nodeManager.setBatteryMin(1.8);
nodeManager.setBatteryMin(3.2); nodeManager.setBatteryMin(3.2);
nodeManager.before();
}
~~~ ~~~
Instruct the board to sleep for 10 minutes at each cycle: Instruct the board to sleep for 10 minutes at each cycle:
~~~c ~~~c
void before() {
nodeManager.setSleep(SLEEP,10,MINUTES); nodeManager.setSleep(SLEEP,10,MINUTES);
nodeManager.before();
}
~~~ ~~~
Configure a wake up pin. When pin 3 is connected to ground, the board will stop sleeping: Configure a wake up pin. When pin 3 is connected to ground, the board will stop sleeping:
~~~c ~~~c
void before() {
nodeManager.setSleepInterruptPin(3); nodeManager.setSleepInterruptPin(3);
nodeManager.before();
}
~~~ ~~~
Use the arduino pins to power on and off the attached sensors. All the sensors' vcc and ground are connected to pin 6 (ground) and 7 (vcc). NodeManager will enable the vcc pin every time just before loop() and wait for 100ms for the power to settle before running loop() of each sensor: Use the arduino pins to power on and off the attached sensors. All the sensors' vcc and ground are connected to pin 6 (ground) and 7 (vcc). NodeManager will enable the vcc pin every time just before loop() and wait for 100ms for the power to settle before running loop() of each sensor:
~~~c ~~~c
void before() {
nodeManager.setPowerPins(6,7,100); nodeManager.setPowerPins(6,7,100);
nodeManager.before();
}
~~~ ~~~
Register a thermistor sensor attached to pin A2. NodeManager will then send the temperature to the controller at the end of each sleeping cycle: Register a thermistor sensor attached to pin A2. NodeManager will then send the temperature to the controller at the end of each sleeping cycle:
~~~c ~~~c
void before() {
nodeManager.registerSensor(SENSOR_THERMISTOR,A2); nodeManager.registerSensor(SENSOR_THERMISTOR,A2);
nodeManager.before(); ~~~
}
Register a SHT21 temperature/humidity sensor; since using i2c for communicating with the sensor, the pins used are implicit (A4 and A5). NodeManager will then send the temperature and the humidity to the controller at the end of each sleeping cycle:
~~~c
nodeManager.registerSensor(SENSOR_SHT21);
~~~ ~~~
Register a LDR sensor attached to pin A1 and send to the gateway the average of 3 samples: Register a LDR sensor attached to pin A1 and send to the gateway the average of 3 samples:
~~~c ~~~c
void before() {
int sensor_ldr = n