Clean up the header files
This commit is contained in:
@@ -35,6 +35,13 @@ MyMessage _ethernetMsg;
|
||||
#endif /* USE_UDP */
|
||||
|
||||
|
||||
#define MAX_RECEIVE_LENGTH 100 // Maximum message length for messages coming from controller
|
||||
|
||||
#ifndef MY_IP_ADDRESS
|
||||
void gatewayTransportRenewIP();
|
||||
#endif
|
||||
|
||||
|
||||
bool gatewayTransportInit() {
|
||||
#ifdef MY_IP_ADDRESS
|
||||
Ethernet.begin(_ethernetGatewayMAC, _ethernetGatewayIP);
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
/**
|
||||
* The MySensors Arduino library handles the wireless radio link and protocol
|
||||
* between your home built sensors/actuators and HA controller of choice.
|
||||
* The sensors forms a self healing radio network with optional repeaters. Each
|
||||
* repeater and gateway builds a routing tables in EEPROM which keeps track of the
|
||||
* network topology allowing messages to be routed to nodes.
|
||||
*
|
||||
* Created by Tomas Hozza <thozza@gmail.com>
|
||||
* Copyright (C) 2015 Tomas Hozza
|
||||
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
|
||||
*
|
||||
* Documentation: http://www.mysensors.org
|
||||
* Support Forum: http://forum.mysensors.org
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* version 2 as published by the Free Software Foundation.
|
||||
*/
|
||||
|
||||
#ifndef MyGatewayTransportEthernet_h
|
||||
#define MyGatewayTransportEthernet_h
|
||||
|
||||
#include "MyConfig.h"
|
||||
#include "MyMessage.h"
|
||||
#include "MyProtocol.h"
|
||||
#include "MyProtocolMySensors.h"
|
||||
#include "MyGatewayTransport.h"
|
||||
|
||||
|
||||
// Use this if you have attached a Ethernet ENC28J60 shields
|
||||
//#include <UIPEthernet.h>
|
||||
|
||||
|
||||
|
||||
#define CONTROLLER_PORT 5003
|
||||
#define IP_RENEWAL_INTERVAL 60000 // in milliseconds
|
||||
#define MAX_RECEIVE_LENGTH 100 // Maximum message length for messages coming from controller
|
||||
|
||||
|
||||
#ifndef MY_IP_ADDRESS
|
||||
void gatewayTransportRenewIP();
|
||||
#endif
|
||||
|
||||
#endif /* MyGatewayTransportEthernet_h */
|
||||
@@ -18,14 +18,18 @@
|
||||
*/
|
||||
|
||||
|
||||
#include "MyGatewayTransportSerial.h"
|
||||
#include "MyConfig.h"
|
||||
#include "MyProtocolMySensors.h"
|
||||
#include "MyGatewayTransport.h"
|
||||
#include "MyMessage.h"
|
||||
#include "MyProtocol.h"
|
||||
|
||||
#define MAX_RECEIVE_LENGTH 100 // Maximum message length for messages coming from controller
|
||||
|
||||
char _serialInputString[MAX_RECEIVE_LENGTH]; // A buffer for incoming commands from serial interface
|
||||
int _serialInputPos;
|
||||
MyMessage _serialMsg;
|
||||
|
||||
|
||||
|
||||
bool gatewayTransportInit() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
/**
|
||||
* The MySensors Arduino library handles the wireless radio link and protocol
|
||||
* between your home built sensors/actuators and HA controller of choice.
|
||||
* The sensors forms a self healing radio network with optional repeaters. Each
|
||||
* repeater and gateway builds a routing tables in EEPROM which keeps track of the
|
||||
* network topology allowing messages to be routed to nodes.
|
||||
*
|
||||
* Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
|
||||
* Copyright (C) 2013-2015 Sensnology AB
|
||||
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
|
||||
*
|
||||
* Documentation: http://www.mysensors.org
|
||||
* Support Forum: http://forum.mysensors.org
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* version 2 as published by the Free Software Foundation.
|
||||
*/
|
||||
|
||||
#ifndef MyGatewayTransportSerial_h
|
||||
#define MyGatewayTransportSerial_h
|
||||
|
||||
#include "MyMessage.h"
|
||||
#include "MyGatewayTransport.h"
|
||||
#include "MyProtocol.h"
|
||||
#include "MyProtocolMySensors.h"
|
||||
|
||||
#define MAX_RECEIVE_LENGTH 100 // Maximum message length for messages coming from controller
|
||||
|
||||
#endif
|
||||
@@ -17,9 +17,13 @@
|
||||
* version 2 as published by the Free Software Foundation.
|
||||
*/
|
||||
|
||||
#include "MyProtocol.h"
|
||||
#include "MyProtocolMySensors.h"
|
||||
#include "MyConfig.h"
|
||||
#include "MyTransport.h"
|
||||
#include "MyProtocol.h"
|
||||
|
||||
#define MAX_FORMAT_BUFFER_LENGTH 120 // Max buffersize when formatting messages
|
||||
|
||||
uint8_t protocolH2i(char c);
|
||||
|
||||
char _fmtBuffer[MAX_FORMAT_BUFFER_LENGTH];
|
||||
char _convBuffer[MAX_PAYLOAD*2+1];
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
/**
|
||||
* The MySensors Arduino library handles the wireless radio link and protocol
|
||||
* between your home built sensors/actuators and HA controller of choice.
|
||||
* The sensors forms a self healing radio network with optional repeaters. Each
|
||||
* repeater and gateway builds a routing tables in EEPROM which keeps track of the
|
||||
* network topology allowing messages to be routed to nodes.
|
||||
*
|
||||
* Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
|
||||
* Copyright (C) 2013-2015 Sensnology AB
|
||||
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
|
||||
*
|
||||
* Documentation: http://www.mysensors.org
|
||||
* Support Forum: http://forum.mysensors.org
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* version 2 as published by the Free Software Foundation.
|
||||
*/
|
||||
|
||||
#ifndef MyProtocolDefault_h
|
||||
#define MyProtocolDefault_h
|
||||
|
||||
#include "MyConfig.h"
|
||||
#include "MyTransport.h"
|
||||
|
||||
#define MAX_FORMAT_BUFFER_LENGTH 120 // Max buffersize when formatting messages
|
||||
|
||||
uint8_t protocolH2i(char c);
|
||||
|
||||
#endif
|
||||
@@ -27,6 +27,7 @@
|
||||
#ifndef MySigning_h
|
||||
#define MySigning_h
|
||||
|
||||
#include "MyConfig.h"
|
||||
#include <stdint.h>
|
||||
#include "MyMessage.h"
|
||||
#include "drivers/ATSHA204/ATSHA204.h"
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
#if defined(ARDUINO_ARCH_AVR)
|
||||
|
||||
#include "MySigning.h"
|
||||
#include "MySigningAtsha204.h"
|
||||
|
||||
#define SIGNING_IDENTIFIER (1)
|
||||
|
||||
@@ -46,6 +45,8 @@ uint8_t _singning_tx_buffer[SHA204_CMD_SIZE_MAX];
|
||||
const whitelist_entry_t _signing_whitelist[] = MY_SIGNING_NODE_WHITELISTING;
|
||||
#endif
|
||||
|
||||
void signerCalculateSignature(MyMessage &msg);
|
||||
uint8_t* signerSha256(const uint8_t* data, size_t sz);
|
||||
|
||||
|
||||
#ifdef DEBUG_SIGNING
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
/**
|
||||
* The MySensors Arduino library handles the wireless radio link and protocol
|
||||
* between your home built sensors/actuators and HA controller of choice.
|
||||
* The sensors forms a self healing radio network with optional repeaters. Each
|
||||
* repeater and gateway builds a routing tables in EEPROM which keeps track of the
|
||||
* network topology allowing messages to be routed to nodes.
|
||||
*
|
||||
* Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
|
||||
* Copyright (C) 2013-2015 Sensnology AB
|
||||
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
|
||||
*
|
||||
* Documentation: http://www.mysensors.org
|
||||
* Support Forum: http://forum.mysensors.org
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
*******************************
|
||||
*
|
||||
* DESCRIPTION
|
||||
* Signing support created by Patrick "Anticimex" Fallberg <patrick@fallberg.net>
|
||||
* ATSHA204 signing backend. The Atmel ATSHA204 offers true random number generation and
|
||||
* HMAC-SHA256 authentication with a readout-protected key.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef MySigningAtsha204_h
|
||||
#define MySigningAtsha204_h
|
||||
|
||||
#include "MyConfig.h"
|
||||
#include "MySigning.h"
|
||||
#include "drivers/ATSHA204/ATSHA204.h"
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
|
||||
// The ATSHA204 is capable of generating proper random numbers for nonce
|
||||
// and can calculate HMAC-SHA256 signatures. This is enterprise-
|
||||
// level of security and ought to implement the signing needs for anybody.
|
||||
|
||||
void signerCalculateSignature(MyMessage &msg);
|
||||
uint8_t* signerSha256(const uint8_t* data, size_t sz);
|
||||
|
||||
|
||||
#endif
|
||||
@@ -28,9 +28,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "MyConfig.h"
|
||||
#include "MySigning.h"
|
||||
#include "MySigningAtsha204Soft.h"
|
||||
#include "drivers/ATSHA204/sha256.h"
|
||||
|
||||
#define SIGNING_IDENTIFIER (1)
|
||||
@@ -49,6 +47,8 @@ uint8_t _signing_hmac[32];
|
||||
const whitelist_entry_t _signing_whitelist[] = MY_SIGNING_NODE_WHITELISTING;
|
||||
#endif
|
||||
|
||||
void signerCalculateSignature(MyMessage &msg);
|
||||
|
||||
// Uncomment this to get some useful serial debug info (Serial.print and Serial.println expected)
|
||||
//#define DEBUG_SIGNING
|
||||
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
/**
|
||||
* The MySensors Arduino library handles the wireless radio link and protocol
|
||||
* between your home built sensors/actuators and HA controller of choice.
|
||||
* The sensors forms a self healing radio network with optional repeaters. Each
|
||||
* repeater and gateway builds a routing tables in EEPROM which keeps track of the
|
||||
* network topology allowing messages to be routed to nodes.
|
||||
*
|
||||
* Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
|
||||
* Copyright (C) 2013-2015 Sensnology AB
|
||||
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
|
||||
*
|
||||
* Documentation: http://www.mysensors.org
|
||||
* Support Forum: http://forum.mysensors.org
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
*******************************
|
||||
*
|
||||
* DESCRIPTION
|
||||
* Signing support created by Patrick "Anticimex" Fallberg <patrick@fallberg.net>
|
||||
* ATSHA204 emulated signing backend. The emulated ATSHA204 implementation offers pseudo random
|
||||
* number generation and HMAC-SHA256 authentication compatible with a "physical" ATSHA204.
|
||||
* NOTE: Key is stored in clear text in the Arduino firmware. Therefore, the use of this back-end
|
||||
* could compromise the key used in the signed message infrastructure if device is lost and its memory
|
||||
* dumped.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef MySigningHmac256Soft_h
|
||||
#define MySigningHmac256Soft_h
|
||||
|
||||
#include "MyConfig.h"
|
||||
#include "MySigning.h"
|
||||
#include "drivers/ATSHA204/ATSHA204.h"
|
||||
#include "drivers/ATSHA204/sha256.h"
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
|
||||
// This implementation is the pure software variant of the ATSHA204.
|
||||
// It is designed to work fully compliant with nodes using ATSHA204 in the network
|
||||
// and therefore uses the same signing identifier as ATSHA204.
|
||||
// Because it is completely software based, the quality of the generated random numbers
|
||||
// is weaker though. Random numbers are generated using the Arduino library and seed
|
||||
// is sampled from an analog pin. This pin should unconnected in the hardware.
|
||||
// The pin is selected using MY_SIGNING_SOFT_RANDOMSEED_PIN in MyConfig.h.
|
||||
|
||||
void signerCalculateSignature(MyMessage &msg);
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,92 +0,0 @@
|
||||
/**
|
||||
* The MySensors Arduino library handles the wireless radio link and protocol
|
||||
* between your home built sensors/actuators and HA controller of choice.
|
||||
* The sensors forms a self healing radio network with optional repeaters. Each
|
||||
* repeater and gateway builds a routing tables in EEPROM which keeps track of the
|
||||
* network topology allowing messages to be routed to nodes.
|
||||
*
|
||||
* Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
|
||||
* Copyright (C) 2013-2015 Sensnology AB
|
||||
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
|
||||
*
|
||||
* Documentation: http://www.mysensors.org
|
||||
* Support Forum: http://forum.mysensors.org
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
*******************************
|
||||
*
|
||||
* DESCRIPTION
|
||||
* Signing support created by Patrick "Anticimex" Fallberg <patrick@fallberg.net>
|
||||
* Disabled signing backend. Does not provide any security measures.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "MyConfig.h"
|
||||
#include "MySigning.h"
|
||||
#include "MySigningNone.h"
|
||||
|
||||
#define SIGNING_IDENTIFIER (0)
|
||||
|
||||
// Uncomment this to get some useful serial debug info (Serial.print and Serial.println expected)
|
||||
//#define DEBUG_SIGNING
|
||||
|
||||
#ifdef DEBUG_SIGNING
|
||||
#define DEBUG_SIGNING_PRINTLN(args) Serial.println(args)
|
||||
#else
|
||||
#define DEBUG_SIGNING_PRINTLN(args)
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG_SIGNING
|
||||
static void DEBUG_NONE_PRINTBUF(const __FlashStringHelper* str, uint8_t* buf, uint8_t sz)
|
||||
{
|
||||
int i;
|
||||
Serial.println(str);
|
||||
for (int i=0; i<sz; i++)
|
||||
{
|
||||
if (buf[i] < 0x10)
|
||||
{
|
||||
Serial.print('0'); // Because Serial.print does not 0-pad HEX
|
||||
}
|
||||
Serial.print(buf[i], HEX);
|
||||
}
|
||||
Serial.println();
|
||||
}
|
||||
#else
|
||||
#define DEBUG_NONE_PRINTBUF(str, buf, sz)
|
||||
#endif
|
||||
|
||||
bool signerGetNonce(MyMessage &msg) {
|
||||
(void)msg;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool signerCheckTimer() {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool signerPutNonce(MyMessage &msg) {
|
||||
(void)msg;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool signerSignMsg(MyMessage &msg) {
|
||||
// If we cannot fit any signature in the message, refuse to sign it
|
||||
if (mGetLength(msg) > MAX_PAYLOAD-2) {
|
||||
DEBUG_SIGNING_PRINTLN(F("MTOL")); // Message too large for signature to fit
|
||||
return false;
|
||||
}
|
||||
mSetSigned(msg, 1); // make sure signing flag is set before signature is calculated
|
||||
msg.data[mGetLength(msg)] = SIGNING_IDENTIFIER; // Add signing identifier
|
||||
return true;
|
||||
}
|
||||
|
||||
bool signerVerifyMsg(MyMessage &msg) {
|
||||
if (msg.data[mGetLength(msg)] != SIGNING_IDENTIFIER)
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
/**
|
||||
* The MySensors Arduino library handles the wireless radio link and protocol
|
||||
* between your home built sensors/actuators and HA controller of choice.
|
||||
* The sensors forms a self healing radio network with optional repeaters. Each
|
||||
* repeater and gateway builds a routing tables in EEPROM which keeps track of the
|
||||
* network topology allowing messages to be routed to nodes.
|
||||
*
|
||||
* Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
|
||||
* Copyright (C) 2013-2015 Sensnology AB
|
||||
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
|
||||
*
|
||||
* Documentation: http://www.mysensors.org
|
||||
* Support Forum: http://forum.mysensors.org
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
*******************************
|
||||
*
|
||||
* DESCRIPTION
|
||||
* Signing support created by Patrick "Anticimex" Fallberg <patrick@fallberg.net>
|
||||
* Disabled signing backend. Does not provide any security measures.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef MySigningNone_h
|
||||
#define MySigningNone_h
|
||||
|
||||
#include "MyConfig.h"
|
||||
#include "MySigning.h"
|
||||
#include <stdint.h>
|
||||
|
||||
// The "none" signing driver that can be used for nodes
|
||||
// not requiring signing
|
||||
// It does check SIGNING_IDENTIFIER byte to avoid illegal mixing of signing back-ends in
|
||||
// the network (as seen by this node) and it does verify proper execution order on the API.
|
||||
// The "none" driver rejects all other back-ends.
|
||||
|
||||
#endif
|
||||
@@ -17,7 +17,21 @@
|
||||
* version 2 as published by the Free Software Foundation.
|
||||
*/
|
||||
|
||||
#include "MyTransportNRF24.h"
|
||||
#include "MyConfig.h"
|
||||
#include "MyTransport.h"
|
||||
#include <stdint.h>
|
||||
#include "drivers/RF24/RF24.h"
|
||||
#include "drivers/RF24/RF24_config.h"
|
||||
#if defined(MY_RF24_ENABLE_ENCRYPTION)
|
||||
#include "drivers/AES/AES.h"
|
||||
#endif
|
||||
|
||||
#define TO_ADDR(x) (MY_RF24_BASE_RADIO_ID + x)
|
||||
|
||||
#define WRITE_PIPE ((uint8_t)0)
|
||||
#define CURRENT_NODE_PIPE ((uint8_t)1)
|
||||
#define BROADCAST_PIPE ((uint8_t)2)
|
||||
|
||||
|
||||
RF24 _rf24(MY_RF24_CE_PIN, MY_RF24_CS_PIN);
|
||||
uint8_t _address;
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
/**
|
||||
* The MySensors Arduino library handles the wireless radio link and protocol
|
||||
* between your home built sensors/actuators and HA controller of choice.
|
||||
* The sensors forms a self healing radio network with optional repeaters. Each
|
||||
* repeater and gateway builds a routing tables in EEPROM which keeps track of the
|
||||
* network topology allowing messages to be routed to nodes.
|
||||
*
|
||||
* Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
|
||||
* Copyright (C) 2013-2015 Sensnology AB
|
||||
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
|
||||
*
|
||||
* Documentation: http://www.mysensors.org
|
||||
* Support Forum: http://forum.mysensors.org
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* version 2 as published by the Free Software Foundation.
|
||||
*/
|
||||
|
||||
#ifndef MyTransportNRF24_h
|
||||
#define MyTransportNRF24_h
|
||||
|
||||
#include "MyConfig.h"
|
||||
#include "MyTransport.h"
|
||||
#include <stdint.h>
|
||||
#include "drivers/RF24/RF24.h"
|
||||
#include "drivers/RF24/RF24_config.h"
|
||||
#if defined(MY_RF24_ENABLE_ENCRYPTION)
|
||||
#include "drivers/AES/AES.h"
|
||||
#endif
|
||||
|
||||
#define TO_ADDR(x) (MY_RF24_BASE_RADIO_ID + x)
|
||||
|
||||
#define WRITE_PIPE ((uint8_t)0)
|
||||
#define CURRENT_NODE_PIPE ((uint8_t)1)
|
||||
#define BROADCAST_PIPE ((uint8_t)2)
|
||||
|
||||
#endif
|
||||
@@ -17,8 +17,10 @@
|
||||
* version 2 as published by the Free Software Foundation.
|
||||
*/
|
||||
|
||||
#include "MyConfig.h"
|
||||
#include "MyTransport.h"
|
||||
#include "MyTransportRFM69.h"
|
||||
#include <stdint.h>
|
||||
#include "drivers/RFM69/RFM69.h"
|
||||
|
||||
RFM69 _radio(MY_RF69_SPI_CS, MY_RF69_IRQ_PIN, MY_IS_RFM69HW, MY_RF69_IRQ_NUM);
|
||||
uint8_t _address;
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
/**
|
||||
* The MySensors Arduino library handles the wireless radio link and protocol
|
||||
* between your home built sensors/actuators and HA controller of choice.
|
||||
* The sensors forms a self healing radio network with optional repeaters. Each
|
||||
* repeater and gateway builds a routing tables in EEPROM which keeps track of the
|
||||
* network topology allowing messages to be routed to nodes.
|
||||
*
|
||||
* Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
|
||||
* Copyright (C) 2013-2015 Sensnology AB
|
||||
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
|
||||
*
|
||||
* Documentation: http://www.mysensors.org
|
||||
* Support Forum: http://forum.mysensors.org
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* version 2 as published by the Free Software Foundation.
|
||||
*/
|
||||
|
||||
#ifndef MyTransportRF69_h
|
||||
#define MyTransportRF69_h
|
||||
|
||||
#include "MyConfig.h"
|
||||
#include "MyTransport.h"
|
||||
#include <stdint.h>
|
||||
#include "drivers/RFM69/RFM69.h"
|
||||
|
||||
|
||||
#endif
|
||||
@@ -26,7 +26,13 @@
|
||||
* http://www.mysensors.org/build/light
|
||||
*/
|
||||
|
||||
#include <SPI.h>
|
||||
// Enable debug prints to serial monitor
|
||||
#define MY_DEBUG
|
||||
|
||||
// Enable and select radio type attached
|
||||
#define MY_RADIO_NRF24
|
||||
//#define MY_RADIO_RFM69
|
||||
|
||||
#include <MySensor.h>
|
||||
|
||||
#define CHILD_ID_LIGHT 0
|
||||
@@ -34,19 +40,16 @@
|
||||
|
||||
unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
|
||||
|
||||
MySensor gw;
|
||||
MyMessage msg(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
|
||||
int lastLightLevel;
|
||||
|
||||
void setup()
|
||||
{
|
||||
gw.begin();
|
||||
|
||||
// Send the sketch version information to the gateway and Controller
|
||||
gw.sendSketchInfo("Light Sensor", "1.0");
|
||||
sendSketchInfo("Light Sensor", "1.0");
|
||||
|
||||
// Register all sensors to gateway (they will be created as child devices)
|
||||
gw.present(CHILD_ID_LIGHT, S_LIGHT_LEVEL);
|
||||
present(CHILD_ID_LIGHT, S_LIGHT_LEVEL);
|
||||
}
|
||||
|
||||
void loop()
|
||||
@@ -54,10 +57,10 @@ void loop()
|
||||
int lightLevel = (1023-analogRead(LIGHT_SENSOR_ANALOG_PIN))/10.23;
|
||||
Serial.println(lightLevel);
|
||||
if (lightLevel != lastLightLevel) {
|
||||
gw.send(msg.set(lightLevel));
|
||||
send(msg.set(lightLevel));
|
||||
lastLightLevel = lightLevel;
|
||||
}
|
||||
gw.sleep(SLEEP_TIME);
|
||||
sleep(SLEEP_TIME);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@
|
||||
|
||||
void setup()
|
||||
{
|
||||
// Initialize library and add callback for incoming messages (signing is required)
|
||||
// Add callback for incoming messages (signing is required)
|
||||
setIncomingCallback(incomingMessage);
|
||||
// Send the sketch version information to the gateway and Controller
|
||||
sendSketchInfo("Secure Lock", "1.0");
|
||||
|
||||
Reference in New Issue
Block a user