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
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 2014) and the value will be reversed (so that no rain will be 0%):
475
+
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%):
472
476
473
477
~~~c
474
478
int rain = nodeManager.registerSensor(SENSOR_ANALOG_INPUT,A0);
@@ -487,4 +491,336 @@ Register a latching relay connecting to pin 6 (set) and pin 7 (unset):
The following sketch can be used to report the temperature and the light level based on a thermistor and LDR sensors attached to two analog pins of the arduino board (A1 and A2). Both the thermistor and the LDR are connected to ground on one side and to vcc via a resistor on the other so to measure the voltage drop across each of them through the analog pins. The sensor will be put to sleep after startup and will report both the measures every 10 minutes. NodeManager will take care of presenting the sensors, managing the sleep cycle, reporting the battery level every 10 cycles and report the measures in the appropriate format. This sketch requires MODULE_ANALOG_INPUT enabled in the global config.h file.
501
+
Even if the sensor is sleeping most of the time, it can be potentially woke up by sending a V_CUSTOM message with a WAKEUP payload to NodeManager service child id (200 by default) just after having reported its heartbeat. At this point the node will report AWAKE and the user can interact with it by e.g. sending REQ messages to its child IDs, changing the duration of a sleep cycle with a V_CUSTOM message to the NodeManager service child id, etc.
502
+
503
+
~~~c
504
+
/*
505
+
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.
506
+
507
+
NodeManager includes the following main components:
508
+
- Sleep manager: allows managing automatically the complexity behind battery-powered sensors spending most of their time sleeping
509
+
- Power manager: allows powering on your sensors only while the node is awake
510
+
- Battery manager: provides common functionalities to read and report the battery level
511
+
- Remote configuration: allows configuring remotely the node without the need to have physical access to it
512
+
- Built-in personalities: for the most common sensors, provide embedded code so to allow their configuration with a single line
513
+
514
+
Documentation available on: https://mynodemanager.sourceforge.io
515
+
*/
516
+
517
+
518
+
// load user settings
519
+
#include"config.h"
520
+
// load MySensors library
521
+
#include<MySensors.h>
522
+
// load NodeManager library
523
+
#include"NodeManager.h"
524
+
525
+
// create a NodeManager instance
526
+
NodeManager nodeManager;
527
+
528
+
// before
529
+
voidbefore() {
530
+
// setup the serial port baud rate
531
+
Serial.begin(MY_BAUD_RATE);
532
+
/*
533
+
* Register below your sensors
534
+
*/
535
+
nodeManager.setSleep(SLEEP,10,MINUTES);
536
+
nodeManager.registerSensor(SENSOR_THERMISTOR,A1);
537
+
nodeManager.registerSensor(SENSOR_LDR,A2);
538
+
/*
539
+
* Register above your sensors
540
+
*/
541
+
nodeManager.before();
542
+
}
543
+
544
+
// presentation
545
+
voidpresentation() {
546
+
// Send the sketch version information to the gateway and Controller
547
+
sendSketchInfo(SKETCH_NAME,SKETCH_VERSION);
548
+
// call NodeManager presentation routine
549
+
nodeManager.presentation();
550
+
551
+
}
552
+
553
+
// setup
554
+
voidsetup() {
555
+
// call NodeManager setup routine
556
+
nodeManager.setup();
557
+
}
558
+
559
+
// loop
560
+
voidloop() {
561
+
// call NodeManager loop routine
562
+
nodeManager.loop();
563
+
564
+
}
565
+
566
+
// receive
567
+
voidreceive(const MyMessage &message) {
568
+
// call NodeManager receive routine
569
+
nodeManager.receive(message);
570
+
}
571
+
~~~
572
+
573
+
## Motion Sensor
574
+
575
+
The following sketch can be used to report back to the controller when a motion sensor attached to the board's pin 3 triggers. In this example, the board will be put to sleep just after startup and will report a heartbeat every hour. NodeManager will take care of configuring an interrupt associated to the provided pin so automatically wake up when a motion is detected and report a V_TRIPPED message back. This sketch requires MODULE_SWITCH to be enabled in the global config.h file.
576
+
577
+
~~~c
578
+
/*
579
+
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.
580
+
581
+
NodeManager includes the following main components:
582
+
- Sleep manager: allows managing automatically the complexity behind battery-powered sensors spending most of their time sleeping
583
+
- Power manager: allows powering on your sensors only while the node is awake
584
+
- Battery manager: provides common functionalities to read and report the battery level
585
+
- Remote configuration: allows configuring remotely the node without the need to have physical access to it
586
+
- Built-in personalities: for the most common sensors, provide embedded code so to allow their configuration with a single line
587
+
588
+
Documentation available on: https://mynodemanager.sourceforge.io
589
+
*/
590
+
591
+
592
+
// load user settings
593
+
#include "config.h"
594
+
// load MySensors library
595
+
#include <MySensors.h>
596
+
// load NodeManager library
597
+
#include "NodeManager.h"
598
+
599
+
// create a NodeManager instance
600
+
NodeManager nodeManager;
601
+
602
+
// before
603
+
void before() {
604
+
// setup the serial port baud rate
605
+
Serial.begin(MY_BAUD_RATE);
606
+
/*
607
+
* Register below your sensors
608
+
*/
609
+
nodeManager.setSleep(SLEEP,60,MINUTES);
610
+
nodeManager.registerSensor(SENSOR_MOTION,3);
611
+
612
+
/*
613
+
* Register above your sensors
614
+
*/
615
+
nodeManager.before();
616
+
}
617
+
618
+
// presentation
619
+
void presentation() {
620
+
// Send the sketch version information to the gateway and Controller
621
+
sendSketchInfo(SKETCH_NAME,SKETCH_VERSION);
622
+
// call NodeManager presentation routine
623
+
nodeManager.presentation();
624
+
625
+
}
626
+
627
+
// setup
628
+
void setup() {
629
+
// call NodeManager setup routine
630
+
nodeManager.setup();
631
+
}
632
+
633
+
// loop
634
+
void loop() {
635
+
// call NodeManager loop routine
636
+
nodeManager.loop();
637
+
638
+
}
639
+
640
+
// receive
641
+
void receive(const MyMessage &message) {
642
+
// call NodeManager receive routine
643
+
nodeManager.receive(message);
644
+
}
645
+
~~~
646
+
647
+
## Boiler Sensor
648
+
649
+
The following sketch controls a latching relay connected to a boiler. A latching relay (requiring only a pulse to switch) has been chosen to minimize the power consumption required by a traditional relay to stay on. This relay has normally two pins, one for closing and the other for opening the controlled circuit, connected to pin 6 and 7 of the arduino board. This is why we have to register two sensors against NodeManager so to control the two funtions indipendently. Since using a SENSOR_LATCHING_RELAY type of sensor, NodeManager will take care of just sending out a single pulse only when a REQ command of type V_STATUS is sent to one or the other child id.
650
+
In this example, the board also runs at 1Mhz so it can go down to 1.8V: by setting setBatteryMin() and setBatteryMax(), the battery percentage will be calculated and reported (by default, automatically every 10 sleeping cycles) based on these custom boundaries.
651
+
The board will be put to sleep just after startup and will report back to the controller every 5 minutes. It is the controller's responsability to catch when the board reports its heartbeat (using smart sleep behind the scene) and send a command back if needed. This sketch requires MODULE_DIGITAL_OUTPUT to be enabled in the config.h file.
652
+
653
+
~~~c
654
+
/*
655
+
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.
656
+
657
+
NodeManager includes the following main components:
658
+
- Sleep manager: allows managing automatically the complexity behind battery-powered sensors spending most of their time sleeping
659
+
- Power manager: allows powering on your sensors only while the node is awake
660
+
- Battery manager: provides common functionalities to read and report the battery level
661
+
- Remote configuration: allows configuring remotely the node without the need to have physical access to it
662
+
- Built-in personalities: for the most common sensors, provide embedded code so to allow their configuration with a single line
663
+
664
+
Documentation available on: https://mynodemanager.sourceforge.io
// Send the sketch version information to the gateway and Controller
700
+
sendSketchInfo(SKETCH_NAME,SKETCH_VERSION);
701
+
// call NodeManager presentation routine
702
+
nodeManager.presentation();
703
+
704
+
}
705
+
706
+
// setup
707
+
voidsetup() {
708
+
// call NodeManager setup routine
709
+
nodeManager.setup();
710
+
}
711
+
712
+
// loop
713
+
voidloop() {
714
+
// call NodeManager loop routine
715
+
nodeManager.loop();
716
+
717
+
}
718
+
719
+
// receive
720
+
voidreceive(const MyMessage &message) {
721
+
// call NodeManager receive routine
722
+
nodeManager.receive(message);
723
+
}
724
+
~~~
725
+
726
+
727
+
## Rain and Soil Moisture Sensor
728
+
729
+
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.
730
+
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().
731
+
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.
732
+
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).
733
+
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.
734
+
735
+
736
+
~~~c
737
+
/*
738
+
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.
739
+
740
+
NodeManager includes the following main components:
741
+
- Sleep manager: allows managing automatically the complexity behind battery-powered sensors spending most of their time sleeping
742
+
- Power manager: allows powering on your sensors only while the node is awake
743
+
- Battery manager: provides common functionalities to read and report the battery level
744
+
- Remote configuration: allows configuring remotely the node without the need to have physical access to it
745
+
- Built-in personalities: for the most common sensors, provide embedded code so to allow their configuration with a single line
746
+
747
+
Documentation available on: https://mynodemanager.sourceforge.io
748
+
*/
749
+
750
+
751
+
// load user settings
752
+
#include "config.h"
753
+
// load MySensors library
754
+
#include <MySensors.h>
755
+
// load NodeManager library
756
+
#include "NodeManager.h"
757
+
758
+
// create a NodeManager instance
759
+
NodeManager nodeManager;
760
+
761
+
// before
762
+
void before() {
763
+
// setup the serial port baud rate
764
+
Serial.begin(MY_BAUD_RATE);
765
+
/*
766
+
* Register below your sensors
767
+
*/
768
+
analogReference(DEFAULT);
769
+
nodeManager.setSleep(SLEEP,10,MINUTES);
770
+
771
+
int rain = nodeManager.registerSensor(SENSOR_ANALOG_INPUT,A1);
772
+
int soil = nodeManager.registerSensor(SENSOR_ANALOG_INPUT,A2);
0 commit comments