Merge branch 'development' into dev-raspberrypi
This commit is contained in:
+68
-23
@@ -6,7 +6,7 @@
|
||||
* network topology allowing messages to be routed to nodes.
|
||||
*
|
||||
* Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
|
||||
* Copyright (C) 2013-2015 Sensnology AB
|
||||
* Copyright (C) 2013-2016 Sensnology AB
|
||||
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
|
||||
*
|
||||
* Documentation: http://www.mysensors.org
|
||||
@@ -17,28 +17,73 @@
|
||||
* version 2 as published by the Free Software Foundation.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file MyEepromAddresses.h
|
||||
* @brief Eeprom addresses for MySensors library data
|
||||
*
|
||||
* @defgroup MyEepromAddressesgrp MyEepromAddresses
|
||||
* @ingroup internals
|
||||
* @{
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef MyEepromAddresses_h
|
||||
#define MyEepromAddresses_h
|
||||
// EEPROM start address for mysensors library data
|
||||
#define EEPROM_START 0
|
||||
// EEPROM location of node id
|
||||
#define EEPROM_NODE_ID_ADDRESS EEPROM_START
|
||||
// EEPROM location of parent id
|
||||
#define EEPROM_PARENT_NODE_ID_ADDRESS (EEPROM_START+1)
|
||||
// EEPROM location of distance to gateway
|
||||
#define EEPROM_DISTANCE_ADDRESS (EEPROM_PARENT_NODE_ID_ADDRESS+1)
|
||||
#define EEPROM_ROUTES_ADDRESS (EEPROM_DISTANCE_ADDRESS+1) // Where to start storing routing information in EEPROM. Will allocate 256 bytes.
|
||||
#define EEPROM_CONTROLLER_CONFIG_ADDRESS (EEPROM_ROUTES_ADDRESS+256) // Location of controller sent configuration (we allow one payload of config data from controller)
|
||||
#define EEPROM_FIRMWARE_TYPE_ADDRESS (EEPROM_CONTROLLER_CONFIG_ADDRESS+24)
|
||||
#define EEPROM_FIRMWARE_VERSION_ADDRESS (EEPROM_FIRMWARE_TYPE_ADDRESS+2)
|
||||
#define EEPROM_FIRMWARE_BLOCKS_ADDRESS (EEPROM_FIRMWARE_VERSION_ADDRESS+2)
|
||||
#define EEPROM_FIRMWARE_CRC_ADDRESS (EEPROM_FIRMWARE_BLOCKS_ADDRESS+2)
|
||||
#define EEPROM_SIGNING_REQUIREMENT_TABLE_ADDRESS (EEPROM_FIRMWARE_CRC_ADDRESS+2)
|
||||
#define EEPROM_WHITELIST_REQUIREMENT_TABLE_ADDRESS (EEPROM_SIGNING_REQUIREMENT_TABLE_ADDRESS+32)
|
||||
#define EEPROM_SIGNING_SOFT_HMAC_KEY_ADDRESS (EEPROM_WHITELIST_REQUIREMENT_TABLE_ADDRESS+32) // This is set with SecurityPersonalizer.ino
|
||||
#define EEPROM_SIGNING_SOFT_SERIAL_ADDRESS (EEPROM_SIGNING_SOFT_HMAC_KEY_ADDRESS+32) // This is set with SecurityPersonalizer.ino
|
||||
#define EEPROM_RF_ENCRYPTION_AES_KEY_ADDRESS (EEPROM_SIGNING_SOFT_SERIAL_ADDRESS+9) // This is set with SecurityPersonalizer.ino
|
||||
#define EEPROM_NODE_LOCK_COUNTER (EEPROM_RF_ENCRYPTION_AES_KEY_ADDRESS+16)
|
||||
#define EEPROM_LOCAL_CONFIG_ADDRESS (EEPROM_NODE_LOCK_COUNTER+1) // First free address for sketch static configuration
|
||||
|
||||
#endif
|
||||
// EEPROM variable sizes, in bytes
|
||||
#define SIZE_NODE_ID (1) //!< Size node ID
|
||||
#define SIZE_PARENT_NODE_ID (1) //!< Size parent node ID
|
||||
#define SIZE_DISTANCE (1) //!< Size GW distance
|
||||
#define SIZE_ROUTES (256) //!< Size routing table
|
||||
#define SIZE_CONTROLLER_CONFIG (24) //!< Size controller config
|
||||
#define SIZE_FIRMWARE_TYPE (2) //!< Size firmware type
|
||||
#define SIZE_FIRMWARE_VERSION (2) //!< Size firmware version
|
||||
#define SIZE_FIRMWARE_BLOCKS (2) //!< Size firmware blocks
|
||||
#define SIZE_FIRMWARE_CRC (2) //!< Size firmware CRC
|
||||
#define SIZE_SIGNING_REQUIREMENT_TABLE (32) //!< Size signing requirement table
|
||||
#define SIZE_WHITELIST_REQUIREMENT_TABLE (32) //!< Size whitelist requirement table
|
||||
#define SIZE_SIGNING_SOFT_HMAC_KEY (32) //!< Size soft signing HMAC key
|
||||
#define SIZE_SIGNING_SOFT_SERIAL (9) //!< Size soft signing serial
|
||||
#define SIZE_RF_ENCRYPTION_AES_KEY (16) //!< Size RF AES encryption key
|
||||
#define SIZE_NODE_LOCK_COUNTER (1) //!< Size node lock counter
|
||||
|
||||
|
||||
/** @brief EEPROM start address */
|
||||
#define EEPROM_START 0
|
||||
/** @brief Address node ID */
|
||||
#define EEPROM_NODE_ID_ADDRESS EEPROM_START
|
||||
/** @brief Address parent node ID */
|
||||
#define EEPROM_PARENT_NODE_ID_ADDRESS (EEPROM_NODE_ID_ADDRESS + SIZE_NODE_ID)
|
||||
/** @brief Address distance to GW */
|
||||
#define EEPROM_DISTANCE_ADDRESS (EEPROM_PARENT_NODE_ID_ADDRESS + SIZE_PARENT_NODE_ID)
|
||||
/** @brief Address routing table */
|
||||
#define EEPROM_ROUTES_ADDRESS (EEPROM_DISTANCE_ADDRESS + SIZE_DISTANCE)
|
||||
/** @brief Address configuration bytes sent by controller */
|
||||
#define EEPROM_CONTROLLER_CONFIG_ADDRESS (EEPROM_ROUTES_ADDRESS + SIZE_ROUTES)
|
||||
/** @brief Address firmware type */
|
||||
#define EEPROM_FIRMWARE_TYPE_ADDRESS (EEPROM_CONTROLLER_CONFIG_ADDRESS + SIZE_CONTROLLER_CONFIG)
|
||||
/** @brief Address firmware version */
|
||||
#define EEPROM_FIRMWARE_VERSION_ADDRESS (EEPROM_FIRMWARE_TYPE_ADDRESS + SIZE_FIRMWARE_TYPE)
|
||||
/** @brief Address firmware blocks */
|
||||
#define EEPROM_FIRMWARE_BLOCKS_ADDRESS (EEPROM_FIRMWARE_VERSION_ADDRESS + SIZE_FIRMWARE_VERSION)
|
||||
/** @brief Address firmware CRC */
|
||||
#define EEPROM_FIRMWARE_CRC_ADDRESS (EEPROM_FIRMWARE_BLOCKS_ADDRESS + SIZE_FIRMWARE_BLOCKS)
|
||||
/** @brief Address signing requirement table */
|
||||
#define EEPROM_SIGNING_REQUIREMENT_TABLE_ADDRESS (EEPROM_FIRMWARE_CRC_ADDRESS + SIZE_FIRMWARE_CRC)
|
||||
/** @brief Address whitelist requirement table */
|
||||
#define EEPROM_WHITELIST_REQUIREMENT_TABLE_ADDRESS (EEPROM_SIGNING_REQUIREMENT_TABLE_ADDRESS + SIZE_SIGNING_REQUIREMENT_TABLE)
|
||||
/** @brief Address soft signing HMAC key. This is set with @ref SecurityPersonalizer.ino */
|
||||
#define EEPROM_SIGNING_SOFT_HMAC_KEY_ADDRESS (EEPROM_WHITELIST_REQUIREMENT_TABLE_ADDRESS + SIZE_WHITELIST_REQUIREMENT_TABLE)
|
||||
/** @brief Address soft signing serial key. This is set with @ref SecurityPersonalizer.ino */
|
||||
#define EEPROM_SIGNING_SOFT_SERIAL_ADDRESS (EEPROM_SIGNING_SOFT_HMAC_KEY_ADDRESS + SIZE_SIGNING_SOFT_HMAC_KEY)
|
||||
/** @brief Address RF AES encryption key. This is set with @ref SecurityPersonalizer.ino */
|
||||
#define EEPROM_RF_ENCRYPTION_AES_KEY_ADDRESS (EEPROM_SIGNING_SOFT_SERIAL_ADDRESS + SIZE_SIGNING_SOFT_SERIAL)
|
||||
/** @brief Address node lock couner. This is set with @ref SecurityPersonalizer.ino */
|
||||
#define EEPROM_NODE_LOCK_COUNTER (EEPROM_RF_ENCRYPTION_AES_KEY_ADDRESS + SIZE_RF_ENCRYPTION_AES_KEY)
|
||||
/** @brief First free address for sketch static configuration */
|
||||
#define EEPROM_LOCAL_CONFIG_ADDRESS (EEPROM_NODE_LOCK_COUNTER + SIZE_NODE_LOCK_COUNTER)
|
||||
|
||||
#endif // MyEepromAddresses_h
|
||||
|
||||
/** @}*/
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
// global variables
|
||||
extern MyMessage _msgTmp;
|
||||
|
||||
|
||||
#if defined(MY_CONTROLLER_IP_ADDRESS)
|
||||
IPAddress _ethernetControllerIP(MY_CONTROLLER_IP_ADDRESS);
|
||||
#endif
|
||||
@@ -58,12 +57,16 @@ typedef struct
|
||||
EthernetUDP _ethernetServer;
|
||||
#elif defined(MY_GATEWAY_LINUX)
|
||||
EthernetServer _ethernetServer(_ethernetGatewayPort, MY_GATEWAY_MAX_CLIENTS);
|
||||
#elif defined(MY_GATEWAY_CLIENT_MODE)
|
||||
// Nothing to do here
|
||||
#else
|
||||
EthernetServer _ethernetServer(_ethernetGatewayPort);
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(MY_GATEWAY_ESP8266) || defined(MY_GATEWAY_LINUX)
|
||||
#if defined(MY_GATEWAY_CLIENT_MODE)
|
||||
static EthernetClient client = EthernetClient();
|
||||
static inputBuffer inputString;
|
||||
#elif defined(MY_GATEWAY_ESP8266) || defined(MY_GATEWAY_LINUX)
|
||||
static EthernetClient clients[MY_GATEWAY_MAX_CLIENTS];
|
||||
static bool clientsConnected[MY_GATEWAY_MAX_CLIENTS];
|
||||
static inputBuffer inputString[MY_GATEWAY_MAX_CLIENTS];
|
||||
@@ -72,7 +75,6 @@ typedef struct
|
||||
static inputBuffer inputString;
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef MY_IP_ADDRESS
|
||||
void gatewayTransportRenewIP();
|
||||
#endif
|
||||
@@ -99,8 +101,6 @@ typedef struct
|
||||
#define _w5100_spi_en(x)
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
bool gatewayTransportInit() {
|
||||
_w5100_spi_en(true);
|
||||
#if defined(MY_GATEWAY_ESP8266)
|
||||
@@ -140,10 +140,25 @@ bool gatewayTransportInit() {
|
||||
MY_SERIALDEVICE.println(Ethernet.localIP());
|
||||
// give the Ethernet interface a second to initialize
|
||||
delay(1000);
|
||||
#endif
|
||||
#endif /* MY_GATEWAY_ESP8266 */
|
||||
|
||||
#ifdef MY_USE_UDP
|
||||
_ethernetServer.begin(_ethernetGatewayPort);
|
||||
#elif defined(MY_GATEWAY_CLIENT_MODE)
|
||||
#if defined(MY_CONTROLLER_URL_ADDRESS)
|
||||
if (client.connect(MY_CONTROLLER_URL_ADDRESS, MY_PORT)) {
|
||||
#else
|
||||
if (client.connect(_ethernetControllerIP, MY_PORT)) {
|
||||
#endif
|
||||
debug(PSTR("Eth: connect\n"));
|
||||
_w5100_spi_en(false);
|
||||
gatewayTransportSend(buildGw(_msgTmp, I_GATEWAY_READY).set("Gateway startup complete."));
|
||||
_w5100_spi_en(true);
|
||||
presentNode();
|
||||
} else {
|
||||
client.stop();
|
||||
debug(PSTR("Eth: Failed to connect\n"));
|
||||
}
|
||||
#else
|
||||
#if defined(MY_GATEWAY_LINUX) && defined(MY_IP_ADDRESS)
|
||||
_ethernetServer.begin(_ethernetGatewayIP);
|
||||
@@ -158,31 +173,43 @@ bool gatewayTransportInit() {
|
||||
|
||||
bool gatewayTransportSend(MyMessage &message)
|
||||
{
|
||||
bool ret = true;
|
||||
int nbytes = 0;
|
||||
char *_ethernetMsg = protocolFormat(message);
|
||||
|
||||
setIndication(INDICATION_GW_TX);
|
||||
|
||||
_w5100_spi_en(true);
|
||||
#if defined(MY_CONTROLLER_IP_ADDRESS)
|
||||
#if defined(MY_GATEWAY_CLIENT_MODE)
|
||||
#if defined(MY_USE_UDP)
|
||||
_ethernetServer.beginPacket(_ethernetControllerIP, MY_PORT);
|
||||
#if defined(MY_CONTROLLER_URL_ADDRESS)
|
||||
_ethernetServer.beginPacket(MY_CONTROLLER_URL_ADDRESS, MY_PORT);
|
||||
#else
|
||||
_ethernetServer.beginPacket(_ethernetControllerIP, MY_PORT);
|
||||
#endif
|
||||
_ethernetServer.write(_ethernetMsg, strlen(_ethernetMsg));
|
||||
// returns 1 if the packet was sent successfully
|
||||
ret = _ethernetServer.endPacket();
|
||||
nbytes = _ethernetServer.endPacket();
|
||||
#else
|
||||
EthernetClient client;
|
||||
if (!client.connected()) {
|
||||
client.stop();
|
||||
#if defined(MY_CONTROLLER_URL_ADDRESS)
|
||||
if (client.connected() || client.connect(MY_CONTROLLER_URL_ADDRESS, MY_PORT)) {
|
||||
if (client.connect(MY_CONTROLLER_URL_ADDRESS, MY_PORT)) {
|
||||
#else
|
||||
if (client.connected() || client.connect(_ethernetControllerIP, MY_PORT)) {
|
||||
if (client.connect(_ethernetControllerIP, MY_PORT)) {
|
||||
#endif
|
||||
client.write(_ethernetMsg, strlen(_ethernetMsg));
|
||||
}
|
||||
else {
|
||||
debug(PSTR("Eth: connect\n"));
|
||||
_w5100_spi_en(false);
|
||||
gatewayTransportSend(buildGw(_msgTmp, I_GATEWAY_READY).set("Gateway startup complete."));
|
||||
_w5100_spi_en(true);
|
||||
presentNode();
|
||||
} else {
|
||||
// connecting to the server failed!
|
||||
ret = false;
|
||||
debug(PSTR("Eth: Failed to connect\n"));
|
||||
_w5100_spi_en(false);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
nbytes = client.write(_ethernetMsg, strlen(_ethernetMsg));
|
||||
#endif
|
||||
#else
|
||||
// Send message to connected clients
|
||||
@@ -191,20 +218,18 @@ bool gatewayTransportSend(MyMessage &message)
|
||||
{
|
||||
if (clients[i] && clients[i].connected())
|
||||
{
|
||||
clients[i].write((uint8_t*)_ethernetMsg, strlen(_ethernetMsg));
|
||||
nbytes += clients[i].write((uint8_t*)_ethernetMsg, strlen(_ethernetMsg));
|
||||
}
|
||||
}
|
||||
#else
|
||||
_ethernetServer.write(_ethernetMsg);
|
||||
nbytes = _ethernetServer.write(_ethernetMsg);
|
||||
#endif
|
||||
#endif
|
||||
#endif /* MY_GATEWAY_CLIENT_MODE */
|
||||
_w5100_spi_en(false);
|
||||
return ret;
|
||||
|
||||
return (nbytes > 0);
|
||||
}
|
||||
|
||||
|
||||
#if defined(MY_GATEWAY_ESP8266) || defined(MY_GATEWAY_LINUX)
|
||||
#if (defined(MY_GATEWAY_ESP8266) || defined(MY_GATEWAY_LINUX)) && !defined(MY_GATEWAY_CLIENT_MODE)
|
||||
bool _readFromClient(uint8_t i) {
|
||||
while (clients[i].connected() && clients[i].available()) {
|
||||
char inChar = clients[i].read();
|
||||
@@ -274,24 +299,51 @@ bool gatewayTransportAvailable()
|
||||
#endif
|
||||
|
||||
#ifdef MY_USE_UDP
|
||||
|
||||
int packet_size = _ethernetServer.parsePacket();
|
||||
|
||||
if (packet_size) {
|
||||
//debug(PSTR("UDP packet available. Size:%d\n"), packet_size);
|
||||
setIndication(INDICATION_GW_RX);
|
||||
#if defined(MY_GATEWAY_ESP8266)
|
||||
_ethernetServer.read(inputString[0].string, MY_GATEWAY_MAX_RECEIVE_LENGTH);
|
||||
inputString[0].string[packet_size] = 0;
|
||||
debug(PSTR("UDP packet received: %s\n"), inputString[0].string);
|
||||
return protocolParse(_ethernetMsg, inputString[0].string);
|
||||
const bool ok = protocolParse(_ethernetMsg, inputString[0].string);
|
||||
#else
|
||||
_ethernetServer.read(inputString.string, MY_GATEWAY_MAX_RECEIVE_LENGTH);
|
||||
inputString.string[packet_size] = 0;
|
||||
debug(PSTR("UDP packet received: %s\n"), inputString.string);
|
||||
_w5100_spi_en(false);
|
||||
return protocolParse(_ethernetMsg, inputString.string);
|
||||
const bool ok = protocolParse(_ethernetMsg, inputString.string);
|
||||
#endif
|
||||
if (ok)
|
||||
{
|
||||
setIndication(INDICATION_GW_RX);
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
#elif defined(MY_GATEWAY_CLIENT_MODE)
|
||||
if (!client.connected()) {
|
||||
client.stop();
|
||||
#if defined(MY_CONTROLLER_URL_ADDRESS)
|
||||
if (client.connect(MY_CONTROLLER_URL_ADDRESS, MY_PORT)) {
|
||||
#else
|
||||
if (client.connect(_ethernetControllerIP, MY_PORT)) {
|
||||
#endif
|
||||
debug(PSTR("Eth: connect\n"));
|
||||
_w5100_spi_en(false);
|
||||
gatewayTransportSend(buildGw(_msgTmp, I_GATEWAY_READY).set("Gateway startup complete."));
|
||||
_w5100_spi_en(true);
|
||||
presentNode();
|
||||
} else {
|
||||
debug(PSTR("Eth: Failed to connect\n"));
|
||||
_w5100_spi_en(false);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (_readFromClient()) {
|
||||
setIndication(INDICATION_GW_RX);
|
||||
_w5100_spi_en(false);
|
||||
return true;
|
||||
}
|
||||
#else
|
||||
#if defined(MY_GATEWAY_ESP8266) || defined(MY_GATEWAY_LINUX)
|
||||
@@ -359,7 +411,7 @@ bool gatewayTransportAvailable()
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif /* MY_GATEWAY_ESP8266 */
|
||||
#endif
|
||||
_w5100_spi_en(false);
|
||||
return false;
|
||||
@@ -371,7 +423,6 @@ MyMessage& gatewayTransportReceive()
|
||||
return _ethernetMsg;
|
||||
}
|
||||
|
||||
|
||||
#if !defined(MY_IP_ADDRESS) && !defined(MY_GATEWAY_ESP8266) && !defined(MY_GATEWAY_LINUX)
|
||||
void gatewayTransportRenewIP()
|
||||
{
|
||||
@@ -396,4 +447,4 @@ void gatewayTransportRenewIP()
|
||||
_w5100_spi_en(false);
|
||||
next_time = now + MY_IP_RENEWAL_INTERVAL;
|
||||
}
|
||||
#endif /* IP_ADDRESS_DHCP */
|
||||
#endif
|
||||
|
||||
@@ -144,7 +144,6 @@ bool gatewayTransportInit() {
|
||||
}
|
||||
|
||||
bool gatewayTransportAvailable() {
|
||||
|
||||
if (_MQTT_connecting)
|
||||
return false;
|
||||
|
||||
|
||||
@@ -55,7 +55,11 @@ bool gatewayTransportAvailable() {
|
||||
if (inChar == '\n') {
|
||||
_serialInputString[_serialInputPos] = 0;
|
||||
bool ok = protocolParse(_serialMsg, _serialInputString);
|
||||
_serialInputPos = 0;
|
||||
if (ok)
|
||||
{
|
||||
setIndication(INDICATION_GW_RX);
|
||||
}
|
||||
_serialInputPos = 0;
|
||||
return ok;
|
||||
} else {
|
||||
// add it to the inputString:
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
#include "MyHwATMega328.h"
|
||||
|
||||
#define INVALID_INTERRUPT_NUM (0xFFu)
|
||||
#define INVALID_INTERRUPT_NUM (0xFFu)
|
||||
|
||||
volatile uint8_t _wokeUpByInterrupt = INVALID_INTERRUPT_NUM; // Interrupt number that woke the mcu.
|
||||
volatile uint8_t _wakeUp1Interrupt = INVALID_INTERRUPT_NUM; // Interrupt number for wakeUp1-callback.
|
||||
@@ -105,7 +105,7 @@ void hwInternalSleep(unsigned long ms) {
|
||||
|
||||
int8_t hwSleep(unsigned long ms) {
|
||||
hwInternalSleep(ms);
|
||||
return -1;
|
||||
return MY_WAKE_UP_BY_TIMER;
|
||||
}
|
||||
|
||||
int8_t hwSleep(uint8_t interrupt, uint8_t mode, unsigned long ms) {
|
||||
@@ -131,7 +131,7 @@ int8_t hwSleep(uint8_t interrupt1, uint8_t mode1, uint8_t interrupt2, uint8_t mo
|
||||
}
|
||||
|
||||
// Return what woke the mcu.
|
||||
int ret = -1; // default: no interrupt triggered, timer wake up
|
||||
int8_t ret = MY_WAKE_UP_BY_TIMER; // default: no interrupt triggered, timer wake up
|
||||
if (interruptWakeUp()) ret = static_cast<int8_t>(_wokeUpByInterrupt);
|
||||
|
||||
// Clear woke-up-by-interrupt flag, so next sleeps won't return immediately.
|
||||
|
||||
@@ -69,6 +69,7 @@ do { \
|
||||
#define hwWatchdogReset() wdt_reset()
|
||||
#define hwReboot() wdt_enable(WDTO_15MS); while (1)
|
||||
#define hwMillis() millis()
|
||||
#define hwRandomNumberInit() randomSeed(analogRead(MY_SIGNING_SOFT_RANDOMSEED_PIN))
|
||||
#define hwReadConfig(__pos) (eeprom_read_byte((uint8_t*)(__pos)))
|
||||
|
||||
#ifndef eeprom_update_byte
|
||||
|
||||
@@ -93,7 +93,7 @@ void hwWriteConfig(int adr, uint8_t value)
|
||||
int8_t hwSleep(unsigned long ms) {
|
||||
// TODO: Not supported!
|
||||
(void)ms;
|
||||
return -2;
|
||||
return MY_SLEEP_NOT_POSSIBLE;
|
||||
}
|
||||
|
||||
int8_t hwSleep(uint8_t interrupt, uint8_t mode, unsigned long ms) {
|
||||
@@ -101,7 +101,7 @@ int8_t hwSleep(uint8_t interrupt, uint8_t mode, unsigned long ms) {
|
||||
(void)interrupt;
|
||||
(void)mode;
|
||||
(void)ms;
|
||||
return -2;
|
||||
return MY_SLEEP_NOT_POSSIBLE;
|
||||
}
|
||||
|
||||
int8_t hwSleep(uint8_t interrupt1, uint8_t mode1, uint8_t interrupt2, uint8_t mode2, unsigned long ms) {
|
||||
@@ -111,7 +111,7 @@ int8_t hwSleep(uint8_t interrupt1, uint8_t mode1, uint8_t interrupt2, uint8_t mo
|
||||
(void)interrupt2;
|
||||
(void)mode2;
|
||||
(void)ms;
|
||||
return -2;
|
||||
return MY_SLEEP_NOT_POSSIBLE;
|
||||
}
|
||||
|
||||
ADC_MODE(ADC_VCC);
|
||||
|
||||
+3
-2
@@ -39,12 +39,13 @@
|
||||
#if defined(MY_DISABLED_SERIAL)
|
||||
#define hwInit()
|
||||
#else
|
||||
#define hwInit() MY_SERIALDEVICE.begin(MY_BAUD_RATE); MY_SERIALDEVICE.setDebugOutput(true)
|
||||
#define hwInit() MY_SERIALDEVICE.begin(MY_BAUD_RATE, SERIAL_8N1, MY_ESP8266_SERIAL_MODE, 1); MY_SERIALDEVICE.setDebugOutput(true)
|
||||
#endif
|
||||
|
||||
#define hwWatchdogReset() wdt_reset()
|
||||
#define hwReboot() ESP.restart();
|
||||
#define hwReboot() ESP.restart()
|
||||
#define hwMillis() millis()
|
||||
#define hwRandomNumberInit() randomSeed(analogRead(MY_SIGNING_SOFT_RANDOMSEED_PIN))
|
||||
|
||||
void hwReadConfigBlock(void* buf, void* adr, size_t length);
|
||||
void hwWriteConfigBlock(void* buf, void* adr, size_t length);
|
||||
|
||||
@@ -135,7 +135,7 @@ int8_t hwSleep(unsigned long ms)
|
||||
{
|
||||
(void)ms;
|
||||
|
||||
return -2;
|
||||
return MY_SLEEP_NOT_POSSIBLE;
|
||||
}
|
||||
|
||||
// Not supported!
|
||||
@@ -145,7 +145,7 @@ int8_t hwSleep(uint8_t interrupt, uint8_t mode, unsigned long ms)
|
||||
(void)mode;
|
||||
(void)ms;
|
||||
|
||||
return -2;
|
||||
return MY_SLEEP_NOT_POSSIBLE;
|
||||
}
|
||||
|
||||
// Not supported!
|
||||
@@ -157,7 +157,7 @@ int8_t hwSleep(uint8_t interrupt1, uint8_t mode1, uint8_t interrupt2, uint8_t mo
|
||||
(void)mode2;
|
||||
(void)ms;
|
||||
|
||||
return -2;
|
||||
return MY_SLEEP_NOT_POSSIBLE;
|
||||
}
|
||||
|
||||
uint16_t hwCPUVoltage()
|
||||
|
||||
+3
-3
@@ -117,7 +117,7 @@ void hwReboot() {
|
||||
int8_t hwSleep(unsigned long ms) {
|
||||
// TODO: Not supported!
|
||||
(void)ms;
|
||||
return -2;
|
||||
return MY_SLEEP_NOT_POSSIBLE;
|
||||
}
|
||||
|
||||
int8_t hwSleep(uint8_t interrupt, uint8_t mode, unsigned long ms) {
|
||||
@@ -125,7 +125,7 @@ int8_t hwSleep(uint8_t interrupt, uint8_t mode, unsigned long ms) {
|
||||
(void)interrupt;
|
||||
(void)mode;
|
||||
(void)ms;
|
||||
return -2;
|
||||
return MY_SLEEP_NOT_POSSIBLE;
|
||||
}
|
||||
|
||||
int8_t hwSleep(uint8_t interrupt1, uint8_t mode1, uint8_t interrupt2, uint8_t mode2, unsigned long ms) {
|
||||
@@ -135,7 +135,7 @@ int8_t hwSleep(uint8_t interrupt1, uint8_t mode1, uint8_t interrupt2, uint8_t mo
|
||||
(void)interrupt2;
|
||||
(void)mode2;
|
||||
(void)ms;
|
||||
return -2;
|
||||
return MY_SLEEP_NOT_POSSIBLE;
|
||||
}
|
||||
|
||||
uint16_t hwCPUVoltage() {
|
||||
|
||||
@@ -43,6 +43,7 @@ void hwInit();
|
||||
void hwWatchdogReset();
|
||||
void hwReboot();
|
||||
#define hwMillis() millis()
|
||||
#define hwRandomNumberInit() randomSeed(analogRead(MY_SIGNING_SOFT_RANDOMSEED_PIN))
|
||||
|
||||
void hwReadConfigBlock(void* buf, void* adr, size_t length);
|
||||
void hwWriteConfigBlock(void* buf, void* adr, size_t length);
|
||||
|
||||
+10
-4
@@ -18,20 +18,26 @@
|
||||
*/
|
||||
|
||||
#include "MyIndication.h"
|
||||
#ifdef MY_LEDS_BLINKING_FEATURE
|
||||
#if defined(MY_DEFAULT_TX_LED_PIN)|| defined(MY_DEFAULT_RX_LED_PIN) || defined(MY_DEFAULT_ERR_LED_PIN)
|
||||
#include "MyLeds.h"
|
||||
#endif
|
||||
|
||||
void setIndication( const indication_t ind )
|
||||
{
|
||||
#ifdef MY_LEDS_BLINKING_FEATURE
|
||||
#if defined(MY_DEFAULT_TX_LED_PIN)
|
||||
if ((INDICATION_TX == ind) || (INDICATION_GW_TX == ind))
|
||||
{
|
||||
ledsBlinkTx(1);
|
||||
} else if ((INDICATION_RX == ind) || (INDICATION_GW_RX == ind))
|
||||
} else
|
||||
#endif
|
||||
#if defined(MY_DEFAULT_RX_LED_PIN)
|
||||
if ((INDICATION_RX == ind) || (INDICATION_GW_RX == ind))
|
||||
{
|
||||
ledsBlinkRx(1);
|
||||
} else if (ind > INDICATION_ERR_START)
|
||||
} else
|
||||
#endif
|
||||
#if defined(MY_DEFAULT_ERR_LED_PIN)
|
||||
if (ind > INDICATION_ERR_START)
|
||||
{
|
||||
// Number of blinks indicates which error occurred.
|
||||
ledsBlinkErr(ind-INDICATION_ERR_START);
|
||||
|
||||
+12
-2
@@ -37,10 +37,15 @@ inline void ledsInit()
|
||||
countErr = 0;
|
||||
|
||||
// Setup led pins
|
||||
#if defined(MY_DEFAULT_RX_LED_PIN)
|
||||
pinMode(MY_DEFAULT_RX_LED_PIN, OUTPUT);
|
||||
#endif
|
||||
#if defined(MY_DEFAULT_TX_LED_PIN)
|
||||
pinMode(MY_DEFAULT_TX_LED_PIN, OUTPUT);
|
||||
#endif
|
||||
#if defined(MY_DEFAULT_ERR_LED_PIN)
|
||||
pinMode(MY_DEFAULT_ERR_LED_PIN, OUTPUT);
|
||||
|
||||
#endif
|
||||
ledsProcess();
|
||||
}
|
||||
|
||||
@@ -55,17 +60,23 @@ void ledsProcess() {
|
||||
|
||||
// For an On/Off ratio of 4, the pattern repeated will be [on, on, on, off]
|
||||
// until the counter becomes 0.
|
||||
#if defined(MY_DEFAULT_RX_LED_PIN)
|
||||
state = (countRx & (LED_ON_OFF_RATIO-1)) ? LED_ON : LED_OFF;
|
||||
hwDigitalWrite(MY_DEFAULT_RX_LED_PIN, state);
|
||||
if (countRx) --countRx;
|
||||
#endif
|
||||
|
||||
#if defined(MY_DEFAULT_TX_LED_PIN)
|
||||
state = (countTx & (LED_ON_OFF_RATIO-1)) ? LED_ON : LED_OFF;
|
||||
hwDigitalWrite(MY_DEFAULT_TX_LED_PIN, state);
|
||||
if (countTx) --countTx;
|
||||
#endif
|
||||
|
||||
#if defined(MY_DEFAULT_ERR_LED_PIN)
|
||||
state = (countErr & (LED_ON_OFF_RATIO-1)) ? LED_ON : LED_OFF;
|
||||
hwDigitalWrite(MY_DEFAULT_ERR_LED_PIN, state);
|
||||
if (countErr) --countErr;
|
||||
#endif
|
||||
}
|
||||
|
||||
void ledsBlinkRx(uint8_t cnt) {
|
||||
@@ -79,4 +90,3 @@ void ledsBlinkTx(uint8_t cnt) {
|
||||
void ledsBlinkErr(uint8_t cnt) {
|
||||
if(!countErr) { countErr = cnt*LED_ON_OFF_RATIO; }
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@
|
||||
#define LED_OFF 0x1
|
||||
#endif
|
||||
|
||||
#ifdef MY_LEDS_BLINKING_FEATURE
|
||||
#if defined(MY_DEFAULT_TX_LED_PIN) || defined(MY_DEFAULT_RX_LED_PIN) || defined(MY_DEFAULT_ERR_LED_PIN)
|
||||
#define ledBlinkTx(x,...) ledsBlinkTx(x)
|
||||
#define ledBlinkRx(x,...) ledsBlinkRx(x)
|
||||
#define ledBlinkErr(x,...) ledsBlinkErr(x)
|
||||
|
||||
+99
-86
@@ -35,7 +35,7 @@ void (*_timeCallback)(unsigned long); // Callback for requested time messages
|
||||
void _process() {
|
||||
hwWatchdogReset();
|
||||
|
||||
#if defined (MY_LEDS_BLINKING_FEATURE)
|
||||
#if defined (MY_DEFAULT_TX_LED_PIN) || defined(MY_DEFAULT_RX_LED_PIN) || defined(MY_DEFAULT_ERR_LED_PIN)
|
||||
ledsProcess();
|
||||
#endif
|
||||
|
||||
@@ -62,7 +62,7 @@ void _infiniteLoop() {
|
||||
#if defined(ARDUINO_ARCH_ESP8266)
|
||||
yield();
|
||||
#endif
|
||||
#if defined (MY_LEDS_BLINKING_FEATURE)
|
||||
#if defined (MY_DEFAULT_TX_LED_PIN) || defined(MY_DEFAULT_RX_LED_PIN) || defined(MY_DEFAULT_ERR_LED_PIN)
|
||||
ledsProcess();
|
||||
#endif
|
||||
#if defined(__linux__)
|
||||
@@ -85,7 +85,7 @@ void _begin() {
|
||||
before();
|
||||
}
|
||||
|
||||
#if defined(MY_LEDS_BLINKING_FEATURE)
|
||||
#if defined(MY_DEFAULT_TX_LED_PIN) || defined(MY_DEFAULT_RX_LED_PIN) || defined(MY_DEFAULT_ERR_LED_PIN)
|
||||
ledsInit();
|
||||
#endif
|
||||
|
||||
@@ -284,12 +284,10 @@ void sendBatteryLevel(uint8_t value, bool enableAck) {
|
||||
}
|
||||
|
||||
void sendHeartbeat(void) {
|
||||
#if defined(MY_RADIO_NRF24) || defined(MY_RADIO_RFM69) || defined(MY_RS485)
|
||||
#if defined(MY_RADIO_FEATURE)
|
||||
uint32_t heartbeat = transportGetHeartbeat();
|
||||
#else
|
||||
uint32_t heartbeat = hwMillis();
|
||||
_sendRoute(build(_msgTmp, _nc.nodeId, GATEWAY_ADDRESS, NODE_SENSOR_ID, C_INTERNAL, I_HEARTBEAT_RESPONSE, false).set(heartbeat));
|
||||
#endif
|
||||
_sendRoute(build(_msgTmp, _nc.nodeId, GATEWAY_ADDRESS, NODE_SENSOR_ID, C_INTERNAL, I_HEARTBEAT_RESPONSE, false).set(heartbeat));
|
||||
}
|
||||
|
||||
void present(uint8_t childSensorId, uint8_t sensorType, const char *description, bool enableAck) {
|
||||
@@ -448,104 +446,118 @@ bool wait(unsigned long ms, uint8_t cmd, uint8_t msgtype) {
|
||||
return expectedResponse;
|
||||
}
|
||||
|
||||
|
||||
int8_t sleep(unsigned long ms) {
|
||||
int8_t _sleep(const uint32_t ms, const bool smartSleep, const uint8_t interrupt1, const uint8_t mode1, const uint8_t interrupt2, const uint8_t mode2) {
|
||||
debug(PSTR("MCO:SLP:MS=%lu,SMS=%d,I1=%d,M1=%d,I2=%d,M2=%d\n"), ms, smartSleep, interrupt1, mode1, interrupt2, mode2);
|
||||
// OTA FW feature: do not sleep if FW update ongoing
|
||||
#if defined(MY_OTA_FIRMWARE_FEATURE)
|
||||
if (_fwUpdateOngoing) {
|
||||
// Do not sleep node while fw update is ongoing
|
||||
wait(ms);
|
||||
return -1;
|
||||
}
|
||||
if (_fwUpdateOngoing) {
|
||||
debug(PSTR("!MCO:SLP:FWUPD\n")); // sleeping not possible, FW update ongoing
|
||||
wait(ms);
|
||||
return MY_SLEEP_NOT_POSSIBLE;
|
||||
}
|
||||
#endif
|
||||
// if repeater, do not sleep
|
||||
// repeater feature: sleeping not possible
|
||||
#if defined(MY_REPEATER_FEATURE)
|
||||
wait(ms);
|
||||
return -1;
|
||||
#else
|
||||
#if defined(MY_RADIO_FEATURE)
|
||||
transportPowerDown();
|
||||
#endif
|
||||
setIndication(INDICATION_SLEEP);
|
||||
const int8_t res = hwSleep(ms);
|
||||
setIndication(INDICATION_WAKEUP);
|
||||
return res;
|
||||
#endif
|
||||
}
|
||||
|
||||
int8_t smartSleep(unsigned long ms) {
|
||||
// notify controller about going to sleep
|
||||
sendHeartbeat();
|
||||
// listen for incoming messages
|
||||
wait(MY_SMART_SLEEP_WAIT_DURATION);
|
||||
return sleep(ms);
|
||||
}
|
||||
|
||||
int8_t sleep(uint8_t interrupt, uint8_t mode, unsigned long ms) {
|
||||
#if defined(MY_OTA_FIRMWARE_FEATURE)
|
||||
if (_fwUpdateOngoing) {
|
||||
// not supported
|
||||
return -2;
|
||||
}
|
||||
#endif
|
||||
#if defined(MY_REPEATER_FEATURE)
|
||||
// not supported
|
||||
(void)interrupt;
|
||||
(void)mode;
|
||||
(void)ms;
|
||||
return -2;
|
||||
#else
|
||||
#if defined(MY_RADIO_FEATURE)
|
||||
transportPowerDown();
|
||||
#endif
|
||||
setIndication(INDICATION_SLEEP);
|
||||
const int8_t res = hwSleep(interrupt, mode, ms);
|
||||
setIndication(INDICATION_WAKEUP);
|
||||
return res;
|
||||
#endif
|
||||
}
|
||||
|
||||
int8_t smartSleep(uint8_t interrupt, uint8_t mode, unsigned long ms) {
|
||||
// notify controller about going to sleep
|
||||
sendHeartbeat();
|
||||
// listen for incoming messages
|
||||
wait(MY_SMART_SLEEP_WAIT_DURATION);
|
||||
return sleep(interrupt, mode, ms);
|
||||
}
|
||||
|
||||
int8_t sleep(uint8_t interrupt1, uint8_t mode1, uint8_t interrupt2, uint8_t mode2, unsigned long ms) {
|
||||
#if defined(MY_OTA_FIRMWARE_FEATURE)
|
||||
if (_fwUpdateOngoing) {
|
||||
// not supported
|
||||
return -2;
|
||||
}
|
||||
#endif
|
||||
#if defined(MY_REPEATER_FEATURE)
|
||||
// not supported
|
||||
(void)smartSleep;
|
||||
(void)interrupt1;
|
||||
(void)mode1;
|
||||
(void)interrupt2;
|
||||
(void)mode2;
|
||||
(void)ms;
|
||||
return -2;
|
||||
|
||||
debug(PSTR("!MCO:SLP:REP\n")); // sleeping not possible, repeater feature enabled
|
||||
wait(ms);
|
||||
return MY_SLEEP_NOT_POSSIBLE;
|
||||
#else
|
||||
uint32_t sleepingTime = ms;
|
||||
#if defined(MY_RADIO_FEATURE)
|
||||
// Do not sleep if transport not ready
|
||||
if (!isTransportReady()) {
|
||||
debug(PSTR("!MCO:SLP:TNR\n")); // sleeping not possible, transport not ready
|
||||
uint32_t sleepEnter = hwMillis();
|
||||
uint32_t sleepDelta = 0;
|
||||
while (!isTransportReady() && (sleepDelta < sleepingTime) && (sleepDelta < MY_SLEEP_TRANSPORT_RECONNECT_TIMEOUT_MS)) {
|
||||
_process();
|
||||
#if defined(ARDUINO_ARCH_ESP8266)
|
||||
yield();
|
||||
#endif
|
||||
sleepDelta = hwMillis() - sleepEnter;
|
||||
}
|
||||
// sleep remainder
|
||||
if (sleepDelta < sleepingTime) {
|
||||
sleepingTime -= sleepDelta; // calculate remaining sleeping time
|
||||
debug(PSTR("MCO:SLP:MS=%lu\n"), sleepingTime);
|
||||
}
|
||||
else {
|
||||
// no sleeping time left
|
||||
return MY_SLEEP_NOT_POSSIBLE;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (smartSleep) {
|
||||
// notify controller about going to sleep
|
||||
sendHeartbeat();
|
||||
wait(MY_SMART_SLEEP_WAIT_DURATION_MS); // listen for incoming messages
|
||||
}
|
||||
|
||||
#if defined(MY_RADIO_FEATURE)
|
||||
debug(PSTR("MCO:SLP:TPD\n")); // sleep, power down transport
|
||||
transportPowerDown();
|
||||
#endif
|
||||
|
||||
setIndication(INDICATION_SLEEP);
|
||||
const int8_t res = hwSleep(interrupt1, mode1, interrupt2, mode2, ms);
|
||||
|
||||
int8_t res = MY_SLEEP_NOT_POSSIBLE; // default
|
||||
|
||||
if (interrupt1 != INTERRUPT_NOT_DEFINED && interrupt2 != INTERRUPT_NOT_DEFINED) {
|
||||
// both IRQs
|
||||
res = hwSleep(interrupt1, mode1, interrupt2, mode2, sleepingTime);
|
||||
}
|
||||
else if (interrupt1 != INTERRUPT_NOT_DEFINED && interrupt2 == INTERRUPT_NOT_DEFINED) {
|
||||
// one IRQ
|
||||
res = hwSleep(interrupt1, mode1, sleepingTime);
|
||||
}
|
||||
else if (interrupt1 == INTERRUPT_NOT_DEFINED && interrupt2 == INTERRUPT_NOT_DEFINED) {
|
||||
// no IRQ
|
||||
res = hwSleep(sleepingTime);
|
||||
}
|
||||
|
||||
setIndication(INDICATION_WAKEUP);
|
||||
debug(PSTR("MCO:SLP:WUP=%d\n"), res); // sleep wake-up
|
||||
return res;
|
||||
#endif
|
||||
}
|
||||
|
||||
int8_t smartSleep(uint8_t interrupt1, uint8_t mode1, uint8_t interrupt2, uint8_t mode2, unsigned long ms) {
|
||||
// notify controller about going to sleep
|
||||
sendHeartbeat();
|
||||
// listen for incoming messages
|
||||
wait(MY_SMART_SLEEP_WAIT_DURATION);
|
||||
return sleep(interrupt1, mode1, interrupt2, mode2, ms);
|
||||
// sleep functions
|
||||
int8_t sleep(const uint32_t ms, const bool smartSleep) {
|
||||
return _sleep(ms, smartSleep);
|
||||
}
|
||||
|
||||
int8_t sleep(const uint8_t interrupt, const uint8_t mode, const uint32_t ms, const bool smartSleep) {
|
||||
return _sleep(ms, smartSleep, interrupt, mode);
|
||||
}
|
||||
|
||||
int8_t sleep(const uint8_t interrupt1, const uint8_t mode1, const uint8_t interrupt2, const uint8_t mode2, const uint32_t ms, const bool smartSleep) {
|
||||
return _sleep(ms, smartSleep, interrupt1, mode1, interrupt2, mode2);
|
||||
}
|
||||
|
||||
// deprecated smartSleep() functions
|
||||
int8_t smartSleep(const uint32_t ms) {
|
||||
// compatibility
|
||||
return _sleep(ms, true);
|
||||
}
|
||||
|
||||
int8_t smartSleep(const uint8_t interrupt, const uint8_t mode, const uint32_t ms) {
|
||||
// compatibility
|
||||
return _sleep(ms, true, interrupt, mode);
|
||||
}
|
||||
|
||||
int8_t smartSleep(const uint8_t interrupt1, const uint8_t mode1, const uint8_t interrupt2, const uint8_t mode2, const uint32_t ms) {
|
||||
// compatibility
|
||||
return _sleep(ms, true, interrupt1, mode1, interrupt2, mode2);
|
||||
}
|
||||
|
||||
|
||||
#ifdef MY_NODE_LOCK_FEATURE
|
||||
void nodeLock(const char* str) {
|
||||
// Make sure EEPROM is updated to locked status
|
||||
@@ -559,6 +571,7 @@ void nodeLock(const char* str) {
|
||||
_sendRoute(build(_msgTmp, _nc.nodeId, GATEWAY_ADDRESS, NODE_SENSOR_ID,C_INTERNAL, I_LOCKED, false).set(str));
|
||||
#if defined(MY_RADIO_FEATURE)
|
||||
transportPowerDown();
|
||||
debug(PSTR("MCO:NLK:TPD\n")); // power down transport
|
||||
#endif
|
||||
setIndication(INDICATION_SLEEP);
|
||||
(void)hwSleep((unsigned long)1000*60*30); // Sleep for 30 min before resending LOCKED message
|
||||
|
||||
+78
-42
@@ -37,20 +37,26 @@
|
||||
*
|
||||
* MySensorsCore debug log messages:
|
||||
*
|
||||
* |E| SYS | SUB | Message | Comment
|
||||
* |-|------|-------|-------------------------------------------|----------------------------------------------------------------------------
|
||||
* | | MCO | BGN | INIT %%s,CP=%%s,LIB=%%s | Core initialization, capabilities (CP), library version (VER)
|
||||
* | | MCO | BGN | BFR | Callback before()
|
||||
* | | MCO | BGN | STP | Callback setup()
|
||||
* | | MCO | BGN | INIT OK,ID=%%d,PAR=%%d,DIS=%%d,REG=%%d | Core initialized, parent ID (PAR), distance to GW (DIS), registration (REG)
|
||||
* | | MCO | BGN | NODE UNLOCKED | Node successfully unlocked (see signing chapter)
|
||||
* |!| MCO | BGN | TSP FAIL | Transport initialization failed
|
||||
* | | MCO | REG | REQ | Registration request
|
||||
* | | MCO | REG | NOT NEEDED | No registration needed (i.e. GW)
|
||||
* |!| MCO | SND | NODE NOT REG | Node is not registered, cannot send message
|
||||
* | | MCO | PIM | NODE REG=%%d | Registration response received, registration status (REG)
|
||||
* | | MCO | PIM | ROUTE N=%%d,R=%%d | Routing table, messages to node (N) are routed via node (R)
|
||||
* | | MCO | NLK | NODE LOCKED. UNLOCK: GND PIN %%d AND RESET| Node locked during booting, see signing chapter for additional information
|
||||
* |E| SYS | SUB | Message | Comment
|
||||
* |-|------|-------|-----------------------------------------------|----------------------------------------------------------------------------
|
||||
* | | MCO | BGN | INIT %%s,CP=%%s,LIB=%%s | Core initialization, capabilities (CP), library version (VER)
|
||||
* | | MCO | BGN | BFR | Callback before()
|
||||
* | | MCO | BGN | STP | Callback setup()
|
||||
* | | MCO | BGN | INIT OK,ID=%%d,PAR=%%d,DIS=%%d,REG=%%d | Core initialized, parent ID (PAR), distance to GW (DIS), registration (REG)
|
||||
* | | MCO | BGN | NODE UNLOCKED | Node successfully unlocked (see signing chapter)
|
||||
* |!| MCO | BGN | TSP FAIL | Transport initialization failed
|
||||
* | | MCO | REG | REQ | Registration request
|
||||
* | | MCO | REG | NOT NEEDED | No registration needed (i.e. GW)
|
||||
* |!| MCO | SND | NODE NOT REG | Node is not registered, cannot send message
|
||||
* | | MCO | PIM | NODE REG=%%d | Registration response received, registration status (REG)
|
||||
* | | MCO | PIM | ROUTE N=%%d,R=%%d | Routing table, messages to node (N) are routed via node (R)
|
||||
* | | MCO | SLP | MS=%%lu,SMS=%%d,I1=%%d,M1=%%d,I2=%%d,M2=%%d | Sleep node, time (MS), smartSleep (SMS), Int1/M1, Int2/M2
|
||||
* | | MCO | SLP | TPD | Sleep node, powerdown transport
|
||||
* | | MCO | SLP | WUP=%%d | Node woke-up, reason/IRQ (WUP)
|
||||
* |!| MCO | SLP | FWUPD | Sleeping not possible, FW update ongoing
|
||||
* |!| MCO | SLP | REP | Sleeping not possible, repeater feature enabled
|
||||
* | | MCO | NLK | NODE LOCKED. UNLOCK: GND PIN %%d AND RESET | Node locked during booting, see signing chapter for additional information
|
||||
* | | MCO | NLK | TPD | Powerdown transport
|
||||
*
|
||||
*
|
||||
* @brief API declaration for MySensorsCore
|
||||
@@ -67,10 +73,16 @@
|
||||
#include <stddef.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#define GATEWAY_ADDRESS ((uint8_t)0) //!< Node ID for GW sketch
|
||||
#define NODE_SENSOR_ID 0xFF //!< Node child is always created/presented when a node is started
|
||||
#define MY_CORE_VERSION ((uint8_t)2) //!< core version
|
||||
#define MY_CORE_MIN_VERSION ((uint8_t)2) //!< min core version required for compatibility
|
||||
#define GATEWAY_ADDRESS ((uint8_t)0) //!< Node ID for GW sketch
|
||||
#define NODE_SENSOR_ID ((uint8_t)255) //!< Node child is always created/presented when a node is started
|
||||
#define MY_CORE_VERSION ((uint8_t)2) //!< core version
|
||||
#define MY_CORE_MIN_VERSION ((uint8_t)2) //!< min core version required for compatibility
|
||||
|
||||
#define MY_WAKE_UP_BY_TIMER ((int8_t)-1) //!< Sleeping wake up by timer
|
||||
#define MY_SLEEP_NOT_POSSIBLE ((int8_t)-2) //!< Sleeping not possible
|
||||
#define INTERRUPT_NOT_DEFINED ((uint8_t)255) //!< _sleep() param: no interrupt defined
|
||||
#define MODE_NOT_DEFINED ((uint8_t)255) //!< _sleep() param: no mode defined
|
||||
|
||||
|
||||
#ifdef MY_DEBUG
|
||||
#define debug(x,...) hwDebugPrint(x, ##__VA_ARGS__) //!< debug
|
||||
@@ -232,16 +244,10 @@ bool wait(unsigned long ms, uint8_t cmd, uint8_t msgtype);
|
||||
/**
|
||||
* Sleep (PowerDownMode) the MCU and radio. Wake up on timer.
|
||||
* @param ms Number of milliseconds to sleep.
|
||||
* @return -1 if timer woke it up, -2 if not possible (e.g. ongoing FW update)
|
||||
* @param smartSleep Set True if sending heartbeat and process incoming messages before going to sleep.
|
||||
* @return @ref MY_WAKE_UP_BY_TIMER if timer woke it up, @ref MY_SLEEP_NOT_POSSIBLE if not possible (e.g. ongoing FW update)
|
||||
*/
|
||||
int8_t sleep(unsigned long ms);
|
||||
/**
|
||||
* Same as sleep(), send heartbeat and process incoming messages before going to sleep.
|
||||
* Specify the time to wait for incoming messages by defining MY_SMART_SLEEP_WAIT_DURATION to a time (ms).
|
||||
* @param ms Number of milliseconds to sleep.
|
||||
* @return -1 if timer woke it up, -2 if not possible (e.g. ongoing FW update)
|
||||
*/
|
||||
int8_t smartSleep(unsigned long ms);
|
||||
int8_t sleep(const uint32_t ms, const bool smartSleep = false);
|
||||
|
||||
/**
|
||||
* Sleep (PowerDownMode) the MCU and radio. Wake up on timer or pin change.
|
||||
@@ -250,18 +256,10 @@ int8_t smartSleep(unsigned long ms);
|
||||
* @param interrupt Interrupt that should trigger the wakeup
|
||||
* @param mode RISING, FALLING, CHANGE
|
||||
* @param ms Number of milliseconds to sleep or 0 to sleep forever
|
||||
* @return Interrupt number if wake up was triggered by pin change, -1 if wake up was triggered by timer, -2 if sleep was not possible (e.g. ongoing FW update)
|
||||
* @param smartSleep Set True if sending heartbeat and process incoming messages before going to sleep
|
||||
* @return Interrupt number if wake up was triggered by pin change, @ref MY_WAKE_UP_BY_TIMER if wake up was triggered by timer, @ref MY_SLEEP_NOT_POSSIBLE if sleep was not possible (e.g. ongoing FW update)
|
||||
*/
|
||||
int8_t sleep(uint8_t interrupt, uint8_t mode, unsigned long ms=0);
|
||||
/**
|
||||
* Same as sleep(), send heartbeat and process incoming messages before going to sleep.
|
||||
* Specify the time to wait for incoming messages by defining MY_SMART_SLEEP_WAIT_DURATION to a time (ms).
|
||||
* @param interrupt Interrupt that should trigger the wakeup
|
||||
* @param mode RISING, FALLING, CHANGE
|
||||
* @param ms Number of milliseconds to sleep or 0 to sleep forever
|
||||
* @return Interrupt number if wake up was triggered by pin change, -1 if wake up was triggered by timer, -2 if sleep was not possible (e.g. ongoing FW update)
|
||||
*/
|
||||
int8_t smartSleep(uint8_t interrupt, uint8_t mode, unsigned long ms=0);
|
||||
int8_t sleep(const uint8_t interrupt, const uint8_t mode, const uint32_t ms=0, const bool smartSleep = false);
|
||||
|
||||
/**
|
||||
* Sleep (PowerDownMode) the MCU and radio. Wake up on timer or pin change for two separate interrupts.
|
||||
@@ -272,10 +270,33 @@ int8_t smartSleep(uint8_t interrupt, uint8_t mode, unsigned long ms=0);
|
||||
* @param interrupt2 Second interrupt that should trigger the wakeup
|
||||
* @param mode2 Mode for second interrupt (RISING, FALLING, CHANGE)
|
||||
* @param ms Number of milliseconds to sleep or 0 to sleep forever
|
||||
* @return Interrupt number if wake up was triggered by pin change, -1 if wake up was triggered by timer, -2 if sleep was not possible (e.g. ongoing FW update)
|
||||
* @param smartSleep Set True if sending heartbeat and process incoming messages before going to sleep.
|
||||
* @return Interrupt number if wake up was triggered by pin change, @ref MY_WAKE_UP_BY_TIMER if wake up was triggered by timer, @ref MY_SLEEP_NOT_POSSIBLE if sleep was not possible (e.g. ongoing FW update)
|
||||
*/
|
||||
int8_t sleep(uint8_t interrupt1, uint8_t mode1, uint8_t interrupt2, uint8_t mode2, unsigned long ms=0);
|
||||
int8_t sleep(const uint8_t interrupt1, const uint8_t mode1, const uint8_t interrupt2, const uint8_t mode2, const uint32_t ms=0, const bool smartSleep = false);
|
||||
|
||||
/**
|
||||
* \deprecated Use sleep(ms, true) instead
|
||||
* Same as sleep(), send heartbeat and process incoming messages before going to sleep.
|
||||
* Specify the time to wait for incoming messages by defining MY_SMART_SLEEP_WAIT_DURATION to a time (ms).
|
||||
* @param ms Number of milliseconds to sleep.
|
||||
* @return @ref MY_WAKE_UP_BY_TIMER if timer woke it up, @ref MY_SLEEP_NOT_POSSIBLE if not possible (e.g. ongoing FW update)
|
||||
*/
|
||||
int8_t smartSleep(const uint32_t ms);
|
||||
|
||||
/**
|
||||
* \deprecated Use sleep(interrupt, mode, ms, true) instead
|
||||
* Same as sleep(), send heartbeat and process incoming messages before going to sleep.
|
||||
* Specify the time to wait for incoming messages by defining MY_SMART_SLEEP_WAIT_DURATION to a time (ms).
|
||||
* @param interrupt Interrupt that should trigger the wakeup
|
||||
* @param mode RISING, FALLING, CHANGE
|
||||
* @param ms Number of milliseconds to sleep or 0 to sleep forever
|
||||
* @return Interrupt number if wake up was triggered by pin change, @ref MY_WAKE_UP_BY_TIMER if wake up was triggered by timer, @ref MY_SLEEP_NOT_POSSIBLE if sleep was not possible (e.g. ongoing FW update)
|
||||
*/
|
||||
int8_t smartSleep(const uint8_t interrupt, const uint8_t mode, const uint32_t ms = 0);
|
||||
|
||||
/**
|
||||
* \deprecated Use sleep(interrupt1, mode1, interrupt2, mode2, ms, true) instead
|
||||
* Same as sleep(), send heartbeat and process incoming messages before going to sleep.
|
||||
* Specify the time to wait for incoming messages by defining MY_SMART_SLEEP_WAIT_DURATION to a time (ms).
|
||||
* @param interrupt1 First interrupt that should trigger the wakeup
|
||||
@@ -283,9 +304,24 @@ int8_t sleep(uint8_t interrupt1, uint8_t mode1, uint8_t interrupt2, uint8_t mode
|
||||
* @param interrupt2 Second interrupt that should trigger the wakeup
|
||||
* @param mode2 Mode for second interrupt (RISING, FALLING, CHANGE)
|
||||
* @param ms Number of milliseconds to sleep or 0 to sleep forever
|
||||
* @return Interrupt number if wake up was triggered by pin change, -1 if wake up was triggered by timer, -2 if sleep was not possible (e.g. ongoing FW update)
|
||||
* @return Interrupt number if wake up was triggered by pin change, @ref MY_WAKE_UP_BY_TIMER if wake up was triggered by timer, @ref MY_SLEEP_NOT_POSSIBLE if sleep was not possible (e.g. ongoing FW update)
|
||||
*/
|
||||
int8_t smartSleep(uint8_t interrupt1, uint8_t mode1, uint8_t interrupt2, uint8_t mode2, unsigned long ms=0);
|
||||
int8_t smartSleep(const uint8_t interrupt1, const uint8_t mode1, const uint8_t interrupt2, const uint8_t mode2, const uint32_t ms=0);
|
||||
|
||||
/**
|
||||
* Sleep (PowerDownMode) the MCU and radio. Wake up on timer or pin change for two separate interrupts.
|
||||
* See: http://arduino.cc/en/Reference/attachInterrupt for details on modes and which pin
|
||||
* is assigned to what interrupt. On Nano/Pro Mini: 0=Pin2, 1=Pin3
|
||||
* @param ms Number of milliseconds to sleep or 0 to sleep forever
|
||||
* @param interrupt1 (optional) First interrupt that should trigger the wakeup
|
||||
* @param mode1 (optional) Mode for first interrupt (RISING, FALLING, CHANGE)
|
||||
* @param interrupt2 (optional) Second interrupt that should trigger the wakeup
|
||||
* @param mode2 (optional) Mode for second interrupt (RISING, FALLING, CHANGE)
|
||||
* @param smartSleep (optional) Set True if sending heartbeat and process incoming messages before going to sleep.
|
||||
* @return Interrupt number if wake up was triggered by pin change, @ref MY_WAKE_UP_BY_TIMER if wake up was triggered by timer, @ref MY_SLEEP_NOT_POSSIBLE if sleep was not possible (e.g. ongoing FW update)
|
||||
*/
|
||||
int8_t _sleep(const uint32_t ms, const bool smartSleep = false, const uint8_t interrupt1 = INTERRUPT_NOT_DEFINED, const uint8_t mode1 = MODE_NOT_DEFINED, const uint8_t interrupt2 = INTERRUPT_NOT_DEFINED, const uint8_t mode2 = MODE_NOT_DEFINED);
|
||||
|
||||
|
||||
#ifdef MY_NODE_LOCK_FEATURE
|
||||
/**
|
||||
|
||||
@@ -92,7 +92,7 @@ static void DEBUG_SIGNING_PRINTBUF(const __FlashStringHelper* str, uint8_t* buf,
|
||||
|
||||
void signerAtsha204SoftInit(void) {
|
||||
// initialize pseudo-RNG
|
||||
randomSeed(analogRead(MY_SIGNING_SOFT_RANDOMSEED_PIN));
|
||||
hwRandomNumberInit();
|
||||
// Set secrets
|
||||
hwReadConfigBlock((void*)_signing_hmac_key, (void*)EEPROM_SIGNING_SOFT_HMAC_KEY_ADDRESS, 32);
|
||||
hwReadConfigBlock((void*)_signing_node_serial_info, (void*)EEPROM_SIGNING_SOFT_SERIAL_ADDRESS, 9);
|
||||
|
||||
Reference in New Issue
Block a user