MySensors Library & Examples  2.3.2-38-gaa76d26
SecureActuator.ino
Go to the documentation of this file.
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  */
44 #define MY_DEBUG
45 #define MY_DEBUG_VERBOSE_SIGNING
46 #define MY_NODE_LOCK_FEATURE
47 
48 // Enable and select radio type attached
49 #define MY_RADIO_RF24
50 //#define MY_RADIO_NRF5_ESB
51 //#define MY_RADIO_RFM69
52 //#define MY_RADIO_RFM95
53 
54 // Select soft/hardware signing method
55 #define MY_SIGNING_SOFT
56 //#define MY_SIGNING_ATSHA204
57 
58 // Enable node whitelisting
59 //#define MY_SIGNING_NODE_WHITELISTING {{.nodeId = GATEWAY_ADDRESS,.serial = {0x09,0x08,0x07,0x06,0x05,0x04,0x03,0x02,0x01}}}
60 // Enable this if you want destination node to sign all messages sent to this node.
61 #define MY_SIGNING_REQUEST_SIGNATURES
62 
63 
64 // SETTINGS FOR MY_SIGNING_SOFT
65 #define MY_SIGNING_SOFT_RANDOMSEED_PIN 7
66 
67 // SETTINGS FOR MY_SIGNING_ATSHA204
68 #ifndef MY_SIGNING_ATSHA204_PIN
69 #define MY_SIGNING_ATSHA204_PIN 17
70 #endif
71 
72 #include <MySensors.h>
73 
74 
75 #define LOCK_1 3
76 #define NOF_LOCKS 1
77 #define LOCK_LOCK 1
78 #define LOCK_UNLOCK 0
79 
80 void setup()
81 {
82  for (int lock=1, pin=LOCK_1; lock<=NOF_LOCKS; lock++, pin++) {
83  // Set lock pins in output mode
84  pinMode(pin, OUTPUT);
85  // Set lock to last known state (using eeprom storage)
86  digitalWrite(pin, loadState(lock)?LOCK_LOCK:LOCK_UNLOCK);
87  }
88 }
89 
91 {
92  // Send the sketch version information to the gateway and Controller
93  sendSketchInfo("Secure Lock", "1.0");
94 
95  // Fetch lock status
96  for (int lock=1, pin=LOCK_1; lock<=NOF_LOCKS; lock++, pin++) {
97  // Register all locks to gw (they will be created as child devices)
98  present(lock, S_LOCK, "SecureActuator", false);
99  }
100 }
101 
103 void loop()
104 {
105 }
106 
112 void receive(const MyMessage &message)
113 {
114  // We only expect one type of message from controller. But we better check anyway.
115  // And echoed messages are not accepted as control messages
116  if (message.getType()==V_LOCK_STATUS && message.getSensor()<=NOF_LOCKS && !message.isEcho()) {
117  // Change relay state
118  digitalWrite(message.getSensor()-1+LOCK_1, message.getBool()?LOCK_LOCK:LOCK_UNLOCK);
119  // Store state in eeprom
120  saveState(message.getSensor(), message.getBool());
121  // Write some debug info
122  Serial.print("Incoming change for lock:");
123  Serial.print(message.getSensor());
124  Serial.print(", New status: ");
125  Serial.println(message.getBool());
126  }
127 }
sendSketchInfo
bool sendSketchInfo(const char *name, const char *version, const bool requestEcho=false)
MyMessage::getSensor
uint8_t getSensor(void) const
Get sensor ID of message.
receive
void receive(const MyMessage &message)
Incoming message handler.
Definition: SecureActuator.ino:112
loop
void loop()
Sketch execution code.
Definition: SecureActuator.ino:103
loadState
uint8_t loadState(const uint8_t pos)
NOF_LOCKS
#define NOF_LOCKS
Total number of attached locks.
Definition: SecureActuator.ino:76
LOCK_1
#define LOCK_1
Arduino Digital I/O pin number for first lock (second on pin+1 etc)
Definition: SecureActuator.ino:75
presentation
void presentation()
Node presentation.
Definition: SecureActuator.ino:90
saveState
void saveState(const uint8_t pos, const uint8_t value)
MyMessage::getType
uint8_t getType(void) const
Get message type.
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: SecureActuator.ino:80
MySensors.h
API declaration for MySensors.
MyMessage::isEcho
bool isEcho(void) const
Getter for echo-flag.
LOCK_LOCK
#define LOCK_LOCK
GPIO value to write to lock attached lock.
Definition: SecureActuator.ino:77
MyMessage::getBool
bool getBool(void) const
Get bool payload.
MyMessage
MyMessage is used to create, manipulate, send and read MySensors messages.
Definition: MyMessage.h:289
LOCK_UNLOCK
#define LOCK_UNLOCK
GPIO value to write to unlock attached lock.
Definition: SecureActuator.ino:78