MySensors Library & Examples  2.3.2
PassiveNode.ino
1 /*
2  * The MySensors Arduino library handles the wireless radio link and protocol
3  * between your home built sensors/actuators and HA controller of choice.
4  * The sensors forms a self healing radio network with optional repeaters. Each
5  * repeater and gateway builds a routing tables in EEPROM which keeps track of the
6  * network topology allowing messages to be routed to nodes.
7  *
8  * Created by Henrik Ekblad <[email protected]>
9  * Copyright (C) 2013-2019 Sensnology AB
10  * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors
11  *
12  * Documentation: http://www.mysensors.org
13  * Support Forum: http://forum.mysensors.org
14  *
15  * This program is free software; you can redistribute it and/or
16  * modify it under the terms of the GNU General Public License
17  * version 2 as published by the Free Software Foundation.
18  *
19  *******************************
20  *
21  * REVISION HISTORY
22  * Version 1.0 - tekka
23  *
24  * DESCRIPTION
25  * Passive node example: This is a passive & independent reporting node
26  *
27  */
28 
29 // Enable debug prints
30 #define MY_DEBUG
31 
32 // Enable passive mode
33 #define MY_PASSIVE_NODE
34 
35 // Passive mode requires static node ID
36 #define MY_NODE_ID 100
37 
38 // Enable and select radio type attached
39 #define MY_RADIO_RF24
40 //#define MY_RADIO_NRF5_ESB
41 //#define MY_RADIO_RFM69
42 //#define MY_RADIO_RFM95
43 
44 #include <MySensors.h>
45 
46 #define CHILD_ID 0 // Id of the sensor child
47 
48 // Initialize general message
49 MyMessage msg(CHILD_ID, V_TEMP);
50 
51 void setup()
52 {
53 }
54 
56 {
57  // Send the sketch version information to the gateway and controller
58  sendSketchInfo("Passive node", "1.0");
59 
60  // Register all sensors to gw (they will be created as child devices)
61  present(CHILD_ID, S_TEMP);
62 }
63 
64 void loop()
65 {
66  // generate some random data
67  send(msg.set(25.0+random(0,30)/10.0,2));
68  sleep(2000);
69 }
MyMessage is used to create, manipulate, send and read MySensors messages.
Definition: MyMessage.h:289
bool sendSketchInfo(const char *name, const char *version, const bool requestEcho=false)
API declaration for MySensors.
bool send(MyMessage &msg, const bool requestEcho=false)
bool present(const uint8_t sensorId, const mysensors_sensor_t sensorType, const char *description="", const bool requestEcho=false)
void setup()
Called after node initialises but before main loop.
Definition: PassiveNode.ino:51
int8_t sleep(const uint32_t sleepingMS, const bool smartSleep=false)
void presentation()
Node presentation.
Definition: PassiveNode.ino:55
MyMessage & set(const void *payload, const size_t length)
Set entire payload.
void loop()
Main loop.
Definition: PassiveNode.ino:64