MySensors Library & Examples  2.3.2
Node2Node.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 2018
23  *
24  * DESCRIPTION
25  * Node to node communication example, destination node id = ACTUATOR_ID
26  * Use SIGNING_ENABLED to enable soft/hard signing
27  *
28  */
29 #define MY_DEBUG
30 #define MY_RADIO_RF24
31 #define CHILD_SENSOR_ID 0
32 #define ACTUATOR_ID 200
33 //#define SIGNING_ENABLED // enable for secure actuator
34 
35 #if defined(SIGNING_ENABLED)
36 // Signing, select soft/hardware signing method
37 #define MY_SIGNING_SOFT
38 //#define MY_SIGNING_ATSHA204
39 #define MY_DEBUG_VERBOSE_SIGNING
40 // Enable this if you want destination node to sign all messages sent to this node.
41 //#define MY_SIGNING_REQUEST_SIGNATURES
42 #endif
43 
44 // triggering interval
45 static const uint32_t trigger_ms = 10000;
46 
47 #include "MySensors.h"
48 MyMessage msgGeneral(CHILD_SENSOR_ID, V_STATUS);
49 uint32_t lastTrigger = 0;
50 bool actuatorStatus = false;
51 
52 void presentation(void)
53 {
54  sendSketchInfo("Node2Node", __DATE__);
55  present(CHILD_SENSOR_ID, S_BINARY, "Remote");
56 }
57 
58 void setup()
59 {
60 #if defined(SIGNING_ENABLED)
61  SET_SIGN(ACTUATOR_ID); // define signing requirements for remote node
62 #endif
63 }
64 
65 void loop()
66 {
67  if (millis() - lastTrigger > trigger_ms) {
68  lastTrigger = millis();
69  // set destination address
70  msgGeneral.setDestination(ACTUATOR_ID);
71  // send message to node
72  send(msgGeneral.set(actuatorStatus));
73  // invert status
74  actuatorStatus ^= true;
75  }
76 }
sendSketchInfo
bool sendSketchInfo(const char *name, const char *version, const bool requestEcho=false)
loop
void loop()
Main loop.
Definition: Node2Node.ino:65
presentation
void presentation(void)
Node presentation.
Definition: Node2Node.ino:52
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: Node2Node.ino:58
MyMessage::setDestination
MyMessage & setDestination(const uint8_t destinationId)
Set final destination node id for this message.
MySensors.h
API declaration for MySensors.
MyMessage
MyMessage is used to create, manipulate, send and read MySensors messages.
Definition: MyMessage.h:289