NodeManager: plugin for a rapid development of battery-powered sensors
-
It sounds absolutely terrific ! :+1:
Thank you very much !
-
I just started playing with this and must say FANTASTIC! This makes things almost too simple.
I found a few small things´(bugs?)
- You refer to the sourforge page for the latest releases (nit pick)
- Baud in the config.h is default set to 9800, shouldn't this be 9600? However, setting it to whatever doesn't help, only 4800 outputs anything, this could be something on my setup as well ...
Again, thanks!
@Efflon thanks for reporting these two issues, I'll track them down with https://github.com/mysensors/NodeManager/issues/34 and https://github.com/mysensors/NodeManager/issues/33 and fix asap!
Thank you all for your comments! -
@Efflon thanks for reporting these two issues, I'll track them down with https://github.com/mysensors/NodeManager/issues/34 and https://github.com/mysensors/NodeManager/issues/33 and fix asap!
Thank you all for your comments!@user2684 Excellent!
A question, I'm doing a simple door sensornodeManager.setBatteryMin(1.8); nodeManager.setBatteryMax(3.2); nodeManager.setBatteryReportCycles(1); int door = nodeManager.registerSensor(SENSOR_DOOR,3); ((SensorDoor*)nodeManager.get(door))->setDebounce(500); nodeManager.setSleep(SLEEP,1,HOURS);Now, the node is constantly sending. It seems as if every wake-up triggers a sending, and a wakeup from the debounce sleep, then battery reporting etc.. Removing the debounce helps and lets the node sleep.
AWAKE SEND D=0 I=200 C=1 T=48 S=AWAKE I=0 F=0.00 BATT V=3.16 P=97 SEND D=0 I=201 C=0 T=38 S= I=0 F=3.16 SWITCH I=1 P=3 V=0 SEND D=0 I=1 C=1 T=16 S= N=0 F=0.00 SLEEP 60s SEND D=0 I=200 C=1 T=48 S=SLEEPING I=0 F=0.00 [here i "open" the door] WAKE P=3, M=1 AWAKE SEND D=0 I=200 C=1 T=48 S=AWAKE I=0 F=0.00 BATT V=3.16 P=97 SEND D=0 I=201 C=0 T=38 S= I=0 F=3.16 SWITCH I=1 P=3 V=1 SEND D=0 I=1 C=1 T=16 S= N=1 F=0.00 SLEEP 60s SEND D=0 I=200 C=1 T=48 S=SLEEPING I=0 F=0.00 [just a second wait] WAKE P=3, M=1 AWAKE SEND D=0 I=200 C=1 T=48 S=AWAKE I=0 F=0.00 BATT V=3.16 P=97 SEND D=0 I=201 C=0 T=38 S= I=0 F=3.16 SWITCH I=1 P=3 V=1 SEND D=0 I=1 C=1 T=16 S= N=1 F=0.00 SLEEP 60s [repeated until closing "door"]Edit:
I changed the sleep to a wait and now the behavior is correct (this line).
// what do to during loop void SensorSwitch::onLoop() { // wait to ensure the the input is not floating if (_debounce > 0) wait(_debounce); // read the value of the pin int value = digitalRead(_pin);MY I=8 M=1 SEND D=0 I=200 C=0 T=48 S=STARTED I=0 F=0.00 SWITCH I=1 P=3 V=0 SEND D=0 I=1 C=0 T=16 S= N=0 F=0.00 SLEEP 60s SEND D=0 I=200 C=1 T=48 S=SLEEPING I=0 F=0.00 [open] WAKE P=3, M=1 AWAKE SEND D=0 I=200 C=1 T=48 S=AWAKE I=0 F=0.00 BATT V=3.16 P=97 SEND D=0 I=201 C=0 T=38 S= I=0 F=3.16 SWITCH I=1 P=3 V=1 SEND D=0 I=1 C=1 T=16 S= N=1 F=0.00 SLEEP 60s SEND D=0 I=200 C=1 T=48 S=SLEEPING I=0 F=0.00 [close] WAKE P=3, M=1 AWAKE SEND D=0 I=200 C=1 T=48 S=AWAKE I=0 F=0.00 BATT V=3.16 P=97 SEND D=0 I=201 C=0 T=38 S= I=0 F=3.16 SWITCH I=1 P=3 V=0 SEND D=0 I=1 C=1 T=16 S= N=0 F=0.00 SLEEP 60s SEND D=0 I=200 C=1 T=48 S=SLEEPING I=0 F=0.00 -
Thanks for the hit @Efflon! I accidentally fixed that sleep() in the v1.4 dev branch this afternoon because of another issue. Is everything else now behaving correctly?
I have a concern regarding battery level reports when operating with interrupts: right now I do not distinguish between a cycle because a full sleep has completed from a cycle interrupted by an interrupt like in this case. This may cause a lot more battery reports, depending on how often the sensor triggers. To avoid this unexpected behavior, in the dev branch the default behavior is now the opposite: waking up from an interrupt does not count as a cycle. The drawback though is that if the sensor triggers continuously, it will never report the battery to the controller since unable to complete a full sleeping cycle. This is why I've added the following so allow the user to pick up the policy he likes the most:
// If true, wake up by an interrupt counts as a valid cycle for battery reports otherwise only uninterrupted sleep cycles would contribute (default: false) void setBatteryReportWithInterrupt(bool value);In case you want to give this a try, the dev branch is available at https://github.com/mysensors/NodeManager/tree/v1.4-dev. You just need to replace the existing NodeManager.cpp and NodeManager.h files, you can keep both your sketch and your config.h.
Thanks -
Thanks for the hit @Efflon! I accidentally fixed that sleep() in the v1.4 dev branch this afternoon because of another issue. Is everything else now behaving correctly?
I have a concern regarding battery level reports when operating with interrupts: right now I do not distinguish between a cycle because a full sleep has completed from a cycle interrupted by an interrupt like in this case. This may cause a lot more battery reports, depending on how often the sensor triggers. To avoid this unexpected behavior, in the dev branch the default behavior is now the opposite: waking up from an interrupt does not count as a cycle. The drawback though is that if the sensor triggers continuously, it will never report the battery to the controller since unable to complete a full sleeping cycle. This is why I've added the following so allow the user to pick up the policy he likes the most:
// If true, wake up by an interrupt counts as a valid cycle for battery reports otherwise only uninterrupted sleep cycles would contribute (default: false) void setBatteryReportWithInterrupt(bool value);In case you want to give this a try, the dev branch is available at https://github.com/mysensors/NodeManager/tree/v1.4-dev. You just need to replace the existing NodeManager.cpp and NodeManager.h files, you can keep both your sketch and your config.h.
Thanks@user2684 said in NodeManager: plugin for a rapid development of battery-powered sensors:
behavior, in the dev branch the default behavior is now the opposite: waking up from an interrupt does not count as a cycle. The drawback though is that if the sensor triggers continuously, it will never report the battery to the controller since unable to complete a full sleep
This is tricky. Myself uses the battery report as a heartbeat on top of checking the battery level, thus I only need the info once or twice a day. Not sending on wake-up is good since it will preserve battery. I guess a combination the right sleeping time and cycle count could end up quite ok. For a front door sensor, 4h sleep and 2 cycle count would report battery level after the night and then maybe one more time, max 3 times per day, which is more than enough. I'll test the dev branch after some sleep :smile:
Btw, great work!! and yes, using wait works just fine, no other issues so far.
-
Hello everyone, you can send commands to the node by domoticz even if the node is in sleep forever? Or the node must always have a sleep delay?
@mar.conte if it's sleeping, it will not receive anything until wake-up. If you change the sleep mode to wait,
nodeManager.setSleepMode(WAIT); [or] nodeManager.setSleep(WAIT,1,HOURS);the sensor will be awake all the time (and drain your battery).
-
@user2684 said in NodeManager: plugin for a rapid development of battery-powered sensors:
behavior, in the dev branch the default behavior is now the opposite: waking up from an interrupt does not count as a cycle. The drawback though is that if the sensor triggers continuously, it will never report the battery to the controller since unable to complete a full sleep
This is tricky. Myself uses the battery report as a heartbeat on top of checking the battery level, thus I only need the info once or twice a day. Not sending on wake-up is good since it will preserve battery. I guess a combination the right sleeping time and cycle count could end up quite ok. For a front door sensor, 4h sleep and 2 cycle count would report battery level after the night and then maybe one more time, max 3 times per day, which is more than enough. I'll test the dev branch after some sleep :smile:
Btw, great work!! and yes, using wait works just fine, no other issues so far.
@Efflon glad to see you found out the right balance for you needs. Based on what you are saying I probably want change the default value of setBatteryReportWithInterrupt() back to true, in this way the new version will present the same behavior as the old one but can be changed at any time by the user. Of course if anybody has a different view, please let me know.
-
@mar.conte if it's sleeping, it will not receive anything until wake-up. If you change the sleep mode to wait,
nodeManager.setSleepMode(WAIT); [or] nodeManager.setSleep(WAIT,1,HOURS);the sensor will be awake all the time (and drain your battery).
@Efflon @mar-conte, if the sensor is powered by batteries, I'll leverage smart sleep which NodeManager is using by default. Smart sleep is btw the reason why I moved into MySensors: since all of my sensors are battery powered, I needed a way to send commands also in this situation.
There is no overhead for the sensor in terms of code (it just needs to wake up periodically to receive commands) and on the controller side the implementation is very simple: once the controller knows the node is a sleeping one, it will queue the commands and send them once the node is awake next (when using smart sleep, a heartbeat is reported once the node is awake and just before going to sleep again).
I'm using this since a while for my boiler controller without issue: the node controls a (latching) relay and goes through a 5 minutes sleeping cycle with the controller (I'm using my https://www.mysensors.org/controller/myhouse) queuing the on/off command. This will introduce a little delay (1-5 minutes in my case) but can be adapted with a shorter/longer sleeping cycle.
-
@Efflon @mar-conte, if the sensor is powered by batteries, I'll leverage smart sleep which NodeManager is using by default. Smart sleep is btw the reason why I moved into MySensors: since all of my sensors are battery powered, I needed a way to send commands also in this situation.
There is no overhead for the sensor in terms of code (it just needs to wake up periodically to receive commands) and on the controller side the implementation is very simple: once the controller knows the node is a sleeping one, it will queue the commands and send them once the node is awake next (when using smart sleep, a heartbeat is reported once the node is awake and just before going to sleep again).
I'm using this since a while for my boiler controller without issue: the node controls a (latching) relay and goes through a 5 minutes sleeping cycle with the controller (I'm using my https://www.mysensors.org/controller/myhouse) queuing the on/off command. This will introduce a little delay (1-5 minutes in my case) but can be adapted with a shorter/longer sleeping cycle.
-
@user2684
a really interesting project, however I would use NodeManager to query each time the battery status of my pir sensor; I would like to know how I can send from domoticz commands to query my node !! thank you@mar.conte if you want to query the battery level on-demand, you can by sending to NodeManager's service child id (by default 200) a REQ V_CUSTOM message with BATTERY as a payload.Of course the node must be awake to respond or the controller must support smart sleep. Or as @gohan says, just have the node reporting the battery level
-
@mar.conte if you want to query the battery level on-demand, you can by sending to NodeManager's service child id (by default 200) a REQ V_CUSTOM message with BATTERY as a payload.Of course the node must be awake to respond or the controller must support smart sleep. Or as @gohan says, just have the node reporting the battery level
-
Hi,
first of all, thanks to user2684 for his great job.
I wonder if it would possible adding a feature in nodeManager, where after a wake up from interrupt, only the onLoop method of the sensor attached to that pin is executed. onLoop of sensors not attached to interrupt are executed only after a full sleep cycle. (of course, this requires that after a wakeup from interrupt, the node come to sleep only for (sleepTime - elapsedTimeBeforeWakeup) )In my case, I have a sketch for a node with a temperature and door sensor. Temperature is sent each 60 minutes, while door status only on interrupt.
-
Hi,
first of all, thanks to user2684 for his great job.
I wonder if it would possible adding a feature in nodeManager, where after a wake up from interrupt, only the onLoop method of the sensor attached to that pin is executed. onLoop of sensors not attached to interrupt are executed only after a full sleep cycle. (of course, this requires that after a wakeup from interrupt, the node come to sleep only for (sleepTime - elapsedTimeBeforeWakeup) )In my case, I have a sketch for a node with a temperature and door sensor. Temperature is sent each 60 minutes, while door status only on interrupt.
@rhaymo you're right, combining sensors waking up from an interrupt and sensors reporting periodically does not work properly with NodeManager right now. I've opened this enhancement request: https://github.com/mysensors/NodeManager/issues/41.
It may be not trivial to implement so it will not be part of the next release which is almost ready but I'll work on it just after since looks like a key requirement for many projects.
Thanks! -
Hi, being a newbie in this wonderful MySensors world, I found myself excited about the flexibility of the overall platform but also somehow implementing the same common functionalities across my sensors over and over again. I decided then to spend some reasonable amount of time to expand the idea behind MyExtention (https://forum.mysensors.org/topic/6062/myextension) into something I have called NodeManager (I know, I'm bad with names!).
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. It should help who is new to MySensors to get up to speed quicker and for those already into the matter to delegate to NodeManager common and boring tasks so to focus on more interesting scenarios.
NodeManager main features are:
- Manage all the aspects of a sleeping cycle by leveraging smart sleep
- Allow configuring the sleep mode and the sleep duration remotely
- Allow waking up a sleeping node remotely at the end of a sleeping cycle
- Allow powering on each connected sensor only while the node is awake to save battery
- Report battery level periodically and automatically
- Calculate battery level without requiring an additional pin and the resistors
- Report battery voltage through a built-in sensor
- Can report battery level on demand
- Allow rebooting the board remotely
- Provide out-of-the-box sensors personalities and automatically execute their main task at each cycle
Specifically on this last point, the idea behind providing built-in the functionalities of most common sensors is to simplify the development especially for somebody new to it.
E.g. if I connect a thermistor to one of the pin, I just need a single line to have it working, as it was leveraging some sort of embedded firmware:nodeManager.registerSensor(SENSOR_THERMISTOR,A2);The following built-in sensors are available:
- SENSOR_ANALOG_INPUT Generic analog sensor, return a pin's analog value or its percentage
- SENSOR_LDR LDR sensor, return the light level of an attached light resistor in percentage
- SENSOR_THERMISTOR Thermistor sensor, return the temperature based on the attached thermistor
- SENSOR_DIGITAL_INPUT Generic digital sensor, return a pin's digital value
- SENSOR_DIGITAL_OUTPUT Generic digital output sensor, allows setting the digital output of a pin to the requested value
- SENSOR_RELAY Relay sensor, allows activating the relay
- SENSOR_LATCHING_RELAY Latching Relay sensor, allows activating the relay with a pulse
- SENSOR_DHT11 DHT11 sensor, return temperature/humidity based on the attached DHT sensor
- SENSOR_DHT22 DHT22 sensor, return temperature/humidity based on the attached DHT sensor
- SENSOR_SHT21 SHT21 sensor, return temperature/humidity based on the attached SHT21 sensor
- 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_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
I put the package on Sourceforce so to avoid leaving here piece of code which may become obsolete in a short time.
The project is here: https://sourceforge.net/projects/mynodemanager
I've also tried to document everything the best as I could on https://sourceforge.net/p/mynodemanager/wikiThanks
-
Hi User2684,
As promised i took NodeManager for a spin. It functions well but i have an issue with powering a DHT22 from the digital pins. It just does not show any temp/hum. If i use the power from the battery it functions well.
Any clue what this could be?
I used setPowerPins6,7,10000 to be sure the DHT22 has enough time to start up. If i use my multimeter between pins 6,7 i see the voltage going to 3.something volts and to 0 when the 10000 miliseconds are gone.
My config is as following;
// before void before() { // setup the serial port baud rate Serial.begin(MY_BAUD_RATE); /* * Register below your sensors */ nodeManager.setSleep(SLEEP,1,MINUTES); nodeManager.registerSensor(SENSOR_DHT22,3); nodeManager.setPowerPins(6,7,10000); /* * Register above your sensors */ nodeManager.before(); } -
Hi User2684,
As promised i took NodeManager for a spin. It functions well but i have an issue with powering a DHT22 from the digital pins. It just does not show any temp/hum. If i use the power from the battery it functions well.
Any clue what this could be?
I used setPowerPins6,7,10000 to be sure the DHT22 has enough time to start up. If i use my multimeter between pins 6,7 i see the voltage going to 3.something volts and to 0 when the 10000 miliseconds are gone.
My config is as following;
// before void before() { // setup the serial port baud rate Serial.begin(MY_BAUD_RATE); /* * Register below your sensors */ nodeManager.setSleep(SLEEP,1,MINUTES); nodeManager.registerSensor(SENSOR_DHT22,3); nodeManager.setPowerPins(6,7,10000); /* * Register above your sensors */ nodeManager.before(); } -
@Robbie_ I've NOT checked anything but I think that probably better:
- power up DHT
- wait a little to "dht startup"
- register sensor
@bilbolodz
So like this?nodeManager.setPowerPins(6,7,10000);
nodeManager.registerSensor(SENSOR_DHT22,3);
nodeManager.setSleep(SLEEP,1,MINUTES); -
@bilbolodz
So like this?nodeManager.setPowerPins(6,7,10000);
nodeManager.registerSensor(SENSOR_DHT22,3);
nodeManager.setSleep(SLEEP,1,MINUTES);