MySensors Library & Examples  2.3.2-36-g2e00bf6
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-2020 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 //#define MY_PJON
44 
45 #include <MySensors.h>
46 
47 #define CHILD_ID 0 // Id of the sensor child
48 
49 // Initialize general message
50 MyMessage msg(CHILD_ID, V_TEMP);
51 
52 void setup()
53 {
54 }
55 
57 {
58  // Send the sketch version information to the gateway and controller
59  sendSketchInfo("Passive node", "1.0");
60 
61  // Register all sensors to gw (they will be created as child devices)
62  present(CHILD_ID, S_TEMP);
63 }
64 
65 void loop()
66 {
67  // generate some random data
68  send(msg.set(25.0+random(0,30)/10.0,2));
69  sleep(2000);
70 }
sendSketchInfo
bool sendSketchInfo(const char *name, const char *version, const bool requestEcho=false)
loop
void loop()
Main loop.
Definition: PassiveNode.ino:65
presentation
void presentation()
Node presentation.
Definition: PassiveNode.ino:56
MyMessage::set
MyMessage & set(const void *payload, const size_t length)
Set entire payload.
send
bool send(MyMessage &msg, const bool requestEcho=false)
present
bool present(const uint8_t sensorId, const mysensors_sensor_t sensorType, const char *description="", const bool requestEcho=false)
setup
void setup()
Called after node initialises but before main loop.
Definition: PassiveNode.ino:52
sleep
int8_t sleep(const uint32_t sleepingMS, const bool smartSleep=false)
MySensors.h
API declaration for MySensors.
MyMessage
MyMessage is used to create, manipulate, send and read MySensors messages.
Definition: MyMessage.h:289