Smart-Home am Beispiel der Präsenzerkennung im Raum Projektarbeit Lennart Heimbs, Johannes Krug, Sebastian Dohle und Kevin Holzschuh bei Prof. Oliver Hofmann SS2019
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SecureActuator.ino 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 <henrik.ekblad@mysensors.org>
  9. * Copyright (C) 2013-2018 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. /**
  22. * @ingroup MySigninggrp
  23. * @{
  24. * @file SecureActuator.ino
  25. * @brief Example sketch showing how to securely control locks.
  26. *
  27. * This example will remember lock state even after power failure.
  28. *
  29. * REVISION HISTORY
  30. * - See git log (git log libraries/MySensors/examples/SecureActuator/SecureActuator.ino)
  31. */
  32. /**
  33. * @example SecureActuator.ino
  34. * This example implements a secure actuator in the form of a IO controlled electrical lock.<br>
  35. * Multiple locks are supported as long as they are on subsequent IO pin indices. The first lock pin
  36. * is defined by @ref LOCK_1. The number of locks is controlled by @ref NOF_LOCKS .<br>
  37. * The sketch will require incoming messages to be signed and the use of signing backend is selected
  38. * by @ref MY_SIGNING_ATSHA204 or @ref MY_SIGNING_SOFT. Hard or soft ATSHA204 signing is supported.<br>
  39. * Whitelisting can be enabled through @ref MY_SIGNING_NODE_WHITELISTING in which case a single entry
  40. * is provided in this example which typically should map to the gateway of the network.
  41. */
  42. #define MY_DEBUG //!< Enable debug prints to serial monitor
  43. #define MY_DEBUG_VERBOSE_SIGNING //!< Enable signing related debug prints to serial monitor
  44. #define MY_NODE_LOCK_FEATURE //!< Enable lockdown of node if suspicious activity is detected
  45. // Enable and select radio type attached
  46. #define MY_RADIO_RF24 //!< nRF24L01 radio driver
  47. //#define MY_RADIO_NRF5_ESB //!< nRF5 radio driver (RF24 compatible)
  48. //#define MY_RADIO_RFM69 //!< RFM69 radio driver
  49. //#define MY_RADIO_RFM95 //!< RFM95 radio driver
  50. // Select soft/hardware signing method
  51. #define MY_SIGNING_SOFT //!< Software signing
  52. //#define MY_SIGNING_ATSHA204 //!< Hardware signing using ATSHA204A
  53. // Enable node whitelisting
  54. //#define MY_SIGNING_NODE_WHITELISTING {{.nodeId = GATEWAY_ADDRESS,.serial = {0x09,0x08,0x07,0x06,0x05,0x04,0x03,0x02,0x01}}}
  55. // Enable this if you want destination node to sign all messages sent to this node.
  56. #define MY_SIGNING_REQUEST_SIGNATURES
  57. // SETTINGS FOR MY_SIGNING_SOFT
  58. #define MY_SIGNING_SOFT_RANDOMSEED_PIN 7 //!< Unconnected analog pin for random seed
  59. // SETTINGS FOR MY_SIGNING_ATSHA204
  60. #ifndef MY_SIGNING_ATSHA204_PIN
  61. #define MY_SIGNING_ATSHA204_PIN 17 //!< A3 - pin where ATSHA204 is attached
  62. #endif
  63. #include <MySensors.h>
  64. #define LOCK_1 3 //!< Arduino Digital I/O pin number for first lock (second on pin+1 etc)
  65. #define NOF_LOCKS 1 //!< Total number of attached locks
  66. #define LOCK_LOCK 1 //!< GPIO value to write to lock attached lock
  67. #define LOCK_UNLOCK 0 //!< GPIO value to write to unlock attached lock
  68. void setup()
  69. {
  70. for (int lock=1, pin=LOCK_1; lock<=NOF_LOCKS; lock++, pin++) {
  71. // Set lock pins in output mode
  72. pinMode(pin, OUTPUT);
  73. // Set lock to last known state (using eeprom storage)
  74. digitalWrite(pin, loadState(lock)?LOCK_LOCK:LOCK_UNLOCK);
  75. }
  76. }
  77. void presentation()
  78. {
  79. // Send the sketch version information to the gateway and Controller
  80. sendSketchInfo("Secure Lock", "1.0");
  81. // Fetch lock status
  82. for (int lock=1, pin=LOCK_1; lock<=NOF_LOCKS; lock++, pin++) {
  83. // Register all locks to gw (they will be created as child devices)
  84. present(lock, S_LOCK, "SecureActuator", false);
  85. }
  86. }
  87. /** @brief Sketch execution code */
  88. void loop()
  89. {
  90. }
  91. /**
  92. * @brief Incoming message handler
  93. *
  94. * @param message The message to handle.
  95. */
  96. void receive(const MyMessage &message)
  97. {
  98. // We only expect one type of message from controller. But we better check anyway.
  99. // And acks are not accepted as control messages
  100. if (message.type==V_LOCK_STATUS && message.sensor<=NOF_LOCKS && !mGetAck(message)) {
  101. // Change relay state
  102. digitalWrite(message.sensor-1+LOCK_1, message.getBool()?LOCK_LOCK:LOCK_UNLOCK);
  103. // Store state in eeprom
  104. saveState(message.sensor, message.getBool());
  105. // Write some debug info
  106. Serial.print("Incoming change for lock:");
  107. Serial.print(message.sensor);
  108. Serial.print(", New status: ");
  109. Serial.println(message.getBool());
  110. }
  111. }
  112. /** @}*/