You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: NodeManager.h
+18-9Lines changed: 18 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -7,6 +7,8 @@
7
7
8
8
#include<Arduino.h>
9
9
10
+
// define NodeManager version
11
+
#defineVERSION"1.4-dev1"
10
12
11
13
/***********************************
12
14
Constants
@@ -40,9 +42,6 @@
40
42
#defineEEPROM_SLEEP_TIME_MINOR3
41
43
#defineEEPROM_SLEEP_UNIT4
42
44
43
-
// define NodeManager version
44
-
#defineVERSION1.4
45
-
46
45
/************************************
47
46
* Include user defined configuration settings
48
47
*/
@@ -247,15 +246,15 @@ class PowerManager {
247
246
public:
248
247
PowerManager() {};
249
248
// to save battery the sensor can be optionally connected to two pins which will act as vcc and ground and activated on demand
250
-
voidsetPowerPins(int ground_pin, int vcc_pin, long wait = 50);
249
+
voidsetPowerPins(int ground_pin, int vcc_pin, int wait_time = 50);
251
250
voidpowerOn();
252
251
voidpowerOff();
253
252
floatgetVcc();
253
+
boolisConfigured();
254
254
private:
255
255
int _vcc_pin = -1;
256
256
int _ground_pin = -1;
257
257
long _wait = 0;
258
-
bool_hasPowerManager();
259
258
};
260
259
261
260
@@ -295,7 +294,7 @@ class Sensor {
295
294
voidsetSleepBetweenSend(int value);
296
295
#if POWER_MANAGER == 1
297
296
// to save battery the sensor can be optionally connected to two pins which will act as vcc and ground and activated on demand
298
-
voidsetPowerPins(int ground_pin, int vcc_pin, long wait = 50);
297
+
voidsetPowerPins(int ground_pin, int vcc_pin, int wait_time = 50);
299
298
// if enabled the pins will be automatically powered on while awake and off during sleeping (default: true)
300
299
voidsetAutoPowerPins(bool value);
301
300
// manually turn the power on
@@ -637,10 +636,17 @@ class SensorDs18b20: public Sensor {
637
636
voidonSetup();
638
637
voidonLoop();
639
638
voidonReceive(const MyMessage & message);
639
+
// return the sensors' device address
640
+
DeviceAddress* getDeviceAddress();
641
+
// returns the sensor's resolution in bits
642
+
intgetResolution();
643
+
// set the sensor's resolution in bits
644
+
voidsetResolution(int value);
640
645
protected:
641
646
float _offset = 0;
642
647
int _index;
643
648
DallasTemperature* _sensors;
649
+
DeviceAddress _device_address;
644
650
};
645
651
#endif
646
652
@@ -722,7 +728,7 @@ class NodeManager {
722
728
voidsetBatteryPin(int value);
723
729
// if setBatteryInternalVcc() is set to false, the volts per bit ratio used to calculate the battery voltage (default: 0.003363075)
724
730
voidsetBatteryVoltsPerBit(float value);
725
-
// If true, wake up by an interrupt counts as a valid cycle for battery reports otherwise only uninterrupted sleep cycles would contribute (default: false)
731
+
// If true, wake up by an interrupt counts as a valid cycle for battery reports otherwise only uninterrupted sleep cycles would contribute (default: true)
726
732
voidsetBatteryReportWithInterrupt(bool value);
727
733
#endif
728
734
#if SLEEP_MANAGER == 1
@@ -746,9 +752,12 @@ class NodeManager {
746
752
intregisterSensor(Sensor* sensor);
747
753
// return a sensor by its index
748
754
Sensor* get(int sensor_index);
755
+
Sensor* getSensor(int sensor_index);
756
+
// assign a different child id to a sensor
757
+
boolrenameSensor(int old_child_id, int new_child_id);
749
758
#if POWER_MANAGER == 1
750
759
// to save battery the sensor can be optionally connected to two pins which will act as vcc and ground and activated on demand
751
-
voidsetPowerPins(int ground_pin, int vcc_pin, long wait = 50);
760
+
voidsetPowerPins(int ground_pin, int vcc_pin, int wait_time = 50);
752
761
// if enabled the pins will be automatically powered on while awake and off during sleeping (default: true)
Copy file name to clipboardExpand all lines: README.md
+21-8Lines changed: 21 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -134,7 +134,7 @@ Node Manager comes with a reasonable default configuration. If you want/need to
134
134
void setBatteryPin(int value);
135
135
// if setBatteryInternalVcc() is set to false, the volts per bit ratio used to calculate the battery voltage (default: 0.003363075)
136
136
void setBatteryVoltsPerBit(float value);
137
-
// If true, wake up by an interrupt counts as a valid cycle for battery reports otherwise only uninterrupted sleep cycles would contribute (default: false)
137
+
// If true, wake up by an interrupt counts as a valid cycle for battery reports otherwise only uninterrupted sleep cycles would contribute (default: true)
138
138
void setBatteryReportWithInterrupt(bool value);
139
139
#endif
140
140
#if SLEEP_MANAGER == 1
@@ -158,6 +158,9 @@ Node Manager comes with a reasonable default configuration. If you want/need to
158
158
int registerSensor(Sensor* sensor);
159
159
// return a sensor by its index
160
160
Sensor* get(int sensor_index);
161
+
Sensor* getSensor(int sensor_index);
162
+
// assign a different child id to a sensor
163
+
bool renameSensor(int old_child_id, int new_child_id);
161
164
#if POWER_MANAGER == 1
162
165
// to save battery the sensor can be optionally connected to two pins which will act as vcc and ground and activated on demand
163
166
void setPowerPins(int ground_pin, int vcc_pin, long wait = 0);
Each built-in sensor class comes with reasonable default settings. In case you want/need to customize any of those settings, after having registered the sensor, you can retrieve it back and call set functions common to all the sensors or specific for a given class.
236
239
237
-
To do so, use `nodeManager.get(child_id)` which will return a pointer to the sensor. Remeber to cast it to the right class before calling their functions. For example:
240
+
To do so, use `nodeManager.getSensor(child_id)` which will return a pointer to the sensor. Remeber to cast it to the right class before calling their functions. For example:
Register a rain sensor connected to A0. This will be powered with via pins 4 (ground) and 5 (vcc) just before reading its value at each cycle, it will be presented as S_RAIN. sending V_RAINRATE messages, the output will be a percentage (calculated between 200 and 1024) and the value will be reversed (so that no rain will be 0%):
514
527
515
528
~~~c
516
529
int rain = nodeManager.registerSensor(SENSOR_ANALOG_INPUT,A0);
The following sketch can be used to report the rain level and the soil moisture based on two sensors connected to the board's analog pins (A1 and A2). In this case we are customizing the out-of-the-box SENSOR_ANALOG_INPUT sensor type since we just need to measure an analog input but we also want to provide the correct type and presentation for each sensor.
768
-
We register the sensors first with registerSensor() which returns the child id assigned to the sensor. We then retrieve the sensor's reference by calling get() so we can invoke the sensor-specific functions, like setPresentation() and setType().
781
+
We register the sensors first with registerSensor() which returns the child id assigned to the sensor. We then retrieve the sensor's reference by calling getSensor() so we can invoke the sensor-specific functions, like setPresentation() and setType().
769
782
In this example, the two sensors are not directly connected to the battery's ground and vcc but, to save additional power, are powered through two arduino's pins. By using e.g. setPowerPins(4,5,300), NodeManger will assume pin 4 is ground and pin 5 is vcc for that specific sensor so it will turn on the power just before reading the analog input (and waiting 300ms for the sensor to initialize) and back off before going to sleep.
770
783
For both the sensors we want a percentage output and with setRangeMin() and setRangeMax() we define the boundaries for calculating the percentage (if we read e.g. 200 when the rain sensor is completely into the water, we know for sure it will not go below this value which will represent the new lower boundary).
771
784
Finally, since both the sensors reports low when wet and high when dry but we need the opposite, we set setReverse() so to have 0% reported when there is no rain/moisture, 100% on the opposite situation.
@@ -809,8 +822,8 @@ void before() {
809
822
int rain = nodeManager.registerSensor(SENSOR_ANALOG_INPUT,A1);
810
823
int soil = nodeManager.registerSensor(SENSOR_ANALOG_INPUT,A2);
0 commit comments