Skip to content

Commit f22ad11

Browse files
author
DV
committed
Release v1.2
1 parent ae3029a commit f22ad11

File tree

5 files changed

+247
-55
lines changed

5 files changed

+247
-55
lines changed

NodeManagerTemplate/NodeManager.cpp

Lines changed: 113 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ const char* WAKEUP = "WAKEUP";
2121
// set the vcc and ground pin the sensor is connected to
2222
void PowerManager::setPowerPins(int ground_pin, int vcc_pin, long wait = 10) {
2323
#if DEBUG == 1
24-
Serial.print("POWER V=");
25-
Serial.print(vcc_pin);
26-
Serial.print(" G=");
27-
Serial.println(ground_pin);
24+
Serial.print("POWER G=");
25+
Serial.print(ground_pin);
26+
Serial.print(" V=");
27+
Serial.println(vcc_pin);
2828
#endif
2929
// configure the vcc pin as output and initialize to low (power off)
3030
_vcc_pin = vcc_pin;
@@ -619,7 +619,7 @@ void SensorDHT::onReceive(const MyMessage & message) {
619619
*/
620620
#if MODULE_SHT21 == 1
621621
// contructor
622-
SensorSHT21::SensorSHT21(int child_id, int sensor_type): Sensor(child_id, -1) {
622+
SensorSHT21::SensorSHT21(int child_id, int sensor_type): Sensor(child_id,A2) {
623623
// store the sensor type (0: temperature, 1: humidity)
624624
_sensor_type = sensor_type;
625625
if (_sensor_type == 0) {
@@ -681,6 +681,15 @@ void SensorSHT21::onReceive(const MyMessage & message) {
681681
}
682682
#endif
683683

684+
/*
685+
* SensorHTU21D
686+
*/
687+
#if MODULE_SHT21 == 1
688+
// constructor
689+
SensorHTU21D::SensorHTU21D(int child_id, int pin): SensorSHT21(child_id, pin) {
690+
}
691+
#endif
692+
684693
/*
685694
* SensorSwitch
686695
*/
@@ -795,8 +804,81 @@ void SensorDs18b20::onLoop() {
795804
void SensorDs18b20::onReceive(const MyMessage & message) {
796805
onLoop();
797806
}
807+
#endif
808+
809+
/*
810+
SensorBH1750
811+
*/
812+
#if MODULE_BH1750 == 1
813+
// contructor
814+
SensorBH1750::SensorBH1750(int child_id): Sensor(child_id,A4) {
815+
setPresentation(S_LIGHT_LEVEL);
816+
setType(V_LEVEL);
817+
_lightSensor = new BH1750();
818+
}
819+
820+
// what do to during setup
821+
void SensorBH1750::onBefore() {
822+
_lightSensor->begin();
823+
}
824+
825+
// what do to during loop
826+
void SensorBH1750::onLoop() {
827+
// request the light level
828+
_value_int = _lightSensor->readLightLevel();
829+
#if DEBUG == 1
830+
Serial.print("BH1 I=");
831+
Serial.print(_child_id);
832+
Serial.print(" L=");
833+
Serial.println(_value_int);
834+
#endif
835+
}
836+
837+
// what do to as the main task when receiving a message
838+
void SensorBH1750::onReceive(const MyMessage & message) {
839+
onLoop();
840+
}
841+
#endif
842+
843+
/*
844+
SensorMLX90614
845+
*/
846+
#if MODULE_MLX90614 == 1
847+
// contructor
848+
SensorMLX90614::SensorMLX90614(int child_id, Adafruit_MLX90614* mlx, int sensor_type): Sensor(child_id,A4) {
849+
// store the sensor type (0: ambient, 1: object)
850+
_sensor_type = sensor_type;
851+
_mlx = mlx;
852+
// set presentation and type
853+
setPresentation(S_TEMP);
854+
setType(V_TEMP);
855+
setValueType(TYPE_FLOAT);
856+
}
798857

858+
// what do to during setup
859+
void SensorMLX90614::onBefore() {
860+
// initialize the library
861+
_mlx->begin();
862+
}
863+
864+
// what do to during loop
865+
void SensorMLX90614::onLoop() {
866+
float temperature = _sensor_type == 0 ? _mlx->readAmbientTempC() : _mlx->readObjectTempC();
867+
// convert it
868+
if (! getControllerConfig().isMetric) temperature = temperature * 1.8 + 32;
869+
#if DEBUG == 1
870+
Serial.print("MLX I=");
871+
Serial.print(_child_id);
872+
Serial.print(" T=");
873+
Serial.println(temperature);
874+
#endif
875+
if (! isnan(temperature)) _value_float = temperature;
876+
}
799877

878+
// what do to as the main task when receiving a message
879+
void SensorMLX90614::onReceive(const MyMessage & message) {
880+
onLoop();
881+
}
800882
#endif
801883

802884
/*******************************************
@@ -915,6 +997,11 @@ int NodeManager::registerSensor(int sensor_type, int pin = -1, int child_id = -1
915997
child_id = _getAvailableChildId();
916998
registerSensor(new SensorSHT21(child_id,1));
917999
}
1000+
else if (sensor_type == SENSOR_HTU21D) {
1001+
registerSensor(new SensorHTU21D(child_id,0));
1002+
child_id = _getAvailableChildId();
1003+
registerSensor(new SensorHTU21D(child_id,1));
1004+
}
9181005
#endif
9191006
#if MODULE_SWITCH == 1
9201007
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
9441031
}
9451032
}
9461033
#endif
1034+
#if MODULE_BH1750 == 1
1035+
else if (sensor_type == SENSOR_BH1750) {
1036+
return registerSensor(new SensorBH1750(child_id));
1037+
}
1038+
#endif
1039+
#if MODULE_MLX90614 == 1
1040+
else if (sensor_type == SENSOR_MLX90614) {
1041+
Serial.println("1");
1042+
Adafruit_MLX90614* mlx = new Adafruit_MLX90614();
1043+
Serial.println("2");
1044+
registerSensor(new SensorMLX90614(child_id,mlx,0));
1045+
Serial.println("3");
1046+
child_id = _getAvailableChildId();
1047+
registerSensor(new SensorMLX90614(child_id,mlx,1));
1048+
}
1049+
#endif
9471050
else {
9481051
#if DEBUG == 1
9491052
Serial.print("INVALID ");
@@ -965,6 +1068,8 @@ int NodeManager::registerSensor(Sensor* sensor) {
9651068
Serial.print(" T=");
9661069
Serial.println(sensor->getType());
9671070
#endif
1071+
// set auto power pin
1072+
sensor->setAutoPowerPins(_auto_power_pins);
9681073
// add the sensor to the array of registered sensors
9691074
_sensors[sensor->getChildId()] = sensor;
9701075
// return the child_id
@@ -1114,7 +1219,7 @@ void NodeManager::loop() {
11141219
// dispacth inbound messages
11151220
void NodeManager::receive(const MyMessage &message) {
11161221
#if DEBUG == 1
1117-
Serial.print("RECV F=");
1222+
Serial.print("RECV S=");
11181223
Serial.print(message.sender);
11191224
Serial.print(" I=");
11201225
Serial.print(message.sensor);
@@ -1133,13 +1238,13 @@ void NodeManager::receive(const MyMessage &message) {
11331238
else if (message.getCommand() == C_REQ && _sensors[message.sensor] != 0) {
11341239
#if POWER_MANAGER == 1
11351240
// turn on the pin powering all the sensors
1136-
powerOn();
1241+
if (_auto_power_pins) powerOn();
11371242
#endif
11381243
// call the sensor's receive()
11391244
_sensors[message.sensor]->receive(message);
11401245
#if POWER_MANAGER == 1
11411246
// turn off the pin powering all the sensors
1142-
powerOff();
1247+
if (_auto_power_pins) powerOff();
11431248
#endif
11441249
}
11451250
}

NodeManagerTemplate/NodeManager.h

Lines changed: 70 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
#define EEPROM_SLEEP_UNIT 4
4242

4343
// define NodeManager version
44-
#define VERSION 1.1
44+
#define VERSION 1.2
4545

4646
/************************************
4747
* Include user defined configuration settings
@@ -109,7 +109,7 @@
109109
#ifndef MODULE_DIGITAL_OUTPUT
110110
#define MODULE_DIGITAL_OUTPUT 0
111111
#endif
112-
// Enable this module to use one of the following sensors: SENSOR_SHT21
112+
// Enable this module to use one of the following sensors: SENSOR_SHT21, SENSOR_HTU21D
113113
#ifndef MODULE_SHT21
114114
#define MODULE_SHT21 0
115115
#endif
@@ -125,7 +125,14 @@
125125
#ifndef MODULE_DS18B20
126126
#define MODULE_DS18B20 0
127127
#endif
128-
128+
// Enable this module to use one of the following sensors: SENSOR_BH1750
129+
#ifndef MODULE_BH1750
130+
#define MODULE_BH1750 0
131+
#endif
132+
// Enable this module to use one of the following sensors: SENSOR_MLX90614
133+
#ifndef MODULE_MLX90614
134+
#define MODULE_MLX90614 0
135+
#endif
129136

130137
/***********************************
131138
Sensors types
@@ -158,6 +165,7 @@
158165
#if MODULE_SHT21 == 1
159166
// SHT21 sensor, return temperature/humidity based on the attached SHT21 sensor
160167
#define SENSOR_SHT21 10
168+
#define SENSOR_HTU21D 15
161169
#endif
162170
#if MODULE_SWITCH == 1
163171
// Generic switch, wake up the board when a pin changes status
@@ -171,7 +179,16 @@
171179
// DS18B20 sensor, return the temperature based on the attached sensor
172180
#define SENSOR_DS18B20 14
173181
#endif
182+
#if MODULE_BH1750 == 1
183+
// BH1750 sensor, return light in lux
184+
#define SENSOR_BH1750 16
185+
#endif
186+
#if MODULE_MLX90614 == 1
187+
// MLX90614 sensor, contactless temperature sensor
188+
#define SENSOR_MLX90614 17
189+
#endif
174190

191+
// last Id: 17
175192
/***********************************
176193
Libraries
177194
*/
@@ -188,15 +205,18 @@
188205
#include <Wire.h>
189206
#include <Sodaq_SHT2x.h>
190207
#endif
191-
#if MODULE_SHT21 == 1
192-
#include <Wire.h>
193-
#include <Sodaq_SHT2x.h>
194-
#endif
195208
#if MODULE_DS18B20 == 1
196209
#include <OneWire.h>
197210
#include <DallasTemperature.h>
198211
#endif
199-
212+
#if MODULE_BH1750 == 1
213+
#include <BH1750.h>
214+
#include <Wire.h>
215+
#endif
216+
#if MODULE_MLX90614 == 1
217+
#include <Wire.h>
218+
#include <Adafruit_MLX90614.h>
219+
#endif
200220

201221
/**************************************
202222
Classes
@@ -438,7 +458,7 @@ class SensorDHT: public Sensor {
438458
#endif
439459

440460
/*
441-
SensorSHT21
461+
SensorSHT21: temperature and humidity sensor
442462
*/
443463
#if MODULE_SHT21 == 1
444464
class SensorSHT21: public Sensor {
@@ -452,6 +472,15 @@ class SensorSHT21: public Sensor {
452472
float _offset = 0;
453473
int _sensor_type = 0;
454474
};
475+
476+
/*
477+
SensorHTU21D: temperature and humidity sensor
478+
*/
479+
480+
class SensorHTU21D: public SensorSHT21 {
481+
public:
482+
SensorHTU21D(int child_id, int pin);
483+
};
455484
#endif
456485

457486
/*
@@ -511,6 +540,38 @@ class SensorDs18b20: public Sensor {
511540
};
512541
#endif
513542

543+
/*
544+
SensorBH1750
545+
*/
546+
#if MODULE_BH1750 == 1
547+
class SensorBH1750: public Sensor {
548+
public:
549+
SensorBH1750(int child_id);
550+
// define what to do at each stage of the sketch
551+
void onBefore();
552+
void onLoop();
553+
void onReceive(const MyMessage & message);
554+
protected:
555+
BH1750* _lightSensor;
556+
};
557+
#endif
558+
559+
/*
560+
SensorMLX90614
561+
*/
562+
#if MODULE_MLX90614 == 1
563+
class SensorMLX90614: public Sensor {
564+
public:
565+
SensorMLX90614(int child_id, Adafruit_MLX90614* mlx, int sensor_type);
566+
// define what to do at each stage of the sketch
567+
void onBefore();
568+
void onLoop();
569+
void onReceive(const MyMessage & message);
570+
protected:
571+
Adafruit_MLX90614* _mlx;
572+
int _sensor_type;
573+
};
574+
#endif
514575

515576
/***************************************
516577
NodeManager: manages all the aspects of the node

NodeManagerTemplate/NodeManagerTemplate.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ void before() {
2828
Serial.begin(9600);
2929
/*
3030
* Register below your sensors
31-
*/
32-
31+
*/
32+
3333

3434
/*
3535
* Register above your sensors
36-
*/
36+
*/
3737
nodeManager.before();
3838
}
3939

0 commit comments

Comments
 (0)