Various MyTransport optimisations p2
This commit is contained in:
+34
-18
@@ -123,6 +123,12 @@
|
|||||||
*/
|
*/
|
||||||
//#define MY_TRANSPORT_UPLINK_CHECK_DISABLED
|
//#define MY_TRANSPORT_UPLINK_CHECK_DISABLED
|
||||||
|
|
||||||
|
/**
|
||||||
|
*@def MY_TRANSPORT_DONT_CARE_MODE
|
||||||
|
*@brief If set, transport traffic is unmonitored and GW connection is optional
|
||||||
|
*/
|
||||||
|
//#define MY_TRANSPORT_DONT_CARE_MODE
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*@def MY_TRANSPORT_MAX_TX_FAILURES
|
*@def MY_TRANSPORT_MAX_TX_FAILURES
|
||||||
*@brief Set to override max. consecutive TX failures until SNP is initiated
|
*@brief Set to override max. consecutive TX failures until SNP is initiated
|
||||||
@@ -191,14 +197,22 @@
|
|||||||
//#define MY_REPEATER_FEATURE
|
//#define MY_REPEATER_FEATURE
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @def MY_SMART_SLEEP_WAIT_DURATION
|
* @def MY_SLEEP_TRANSPORT_RECONNECT_TIMEOUT_MS
|
||||||
* @brief The wait period before going to sleep when using smartSleep-functions.
|
* @brief Timeout (in ms) to re-establish link if node is send to sleep and transport is not ready.
|
||||||
|
*/
|
||||||
|
#ifndef MY_SLEEP_TRANSPORT_RECONNECT_TIMEOUT_MS
|
||||||
|
#define MY_SLEEP_TRANSPORT_RECONNECT_TIMEOUT_MS (10*1000ul)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @def MY_SMART_SLEEP_WAIT_DURATION_MS
|
||||||
|
* @brief The wait period (in ms) before going to sleep when using smartSleep-functions.
|
||||||
*
|
*
|
||||||
* This period has to be long enough for controller to be able to send out
|
* This period has to be long enough for controller to be able to send out
|
||||||
* potential buffered messages.
|
* potential buffered messages.
|
||||||
*/
|
*/
|
||||||
#ifndef MY_SMART_SLEEP_WAIT_DURATION
|
#ifndef MY_SMART_SLEEP_WAIT_DURATION_MS
|
||||||
#define MY_SMART_SLEEP_WAIT_DURATION (500ul)
|
#define MY_SMART_SLEEP_WAIT_DURATION_MS (500ul)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**********************************
|
/**********************************
|
||||||
@@ -261,25 +275,22 @@
|
|||||||
/**********************************
|
/**********************************
|
||||||
* Information LEDs blinking
|
* Information LEDs blinking
|
||||||
***********************************/
|
***********************************/
|
||||||
// This feature enables LEDs blinking on message receive, transmit
|
// If one of the following is defined here, or in the sketch, the pin will be used for the
|
||||||
// or if some error occurred. This was commonly used only in gateways,
|
// corresponding led function.
|
||||||
// but now can be used in any sensor node. Also the LEDs can now be
|
// They have to be enabled here (or in your sketch). Replace x with the pin number you have the LED on.
|
||||||
// disabled in the gateway.
|
//
|
||||||
|
// NOTE!! that on some platforms (for example sensebender GW) the hardware variant can enable LEDs by default,
|
||||||
|
// These defaults can be overridden by defining one of these.
|
||||||
|
//#define MY_DEFAULT_ERR_LED_PIN x
|
||||||
|
//#define MY_DEFAULT_TX_LED_PIN x
|
||||||
|
//#define MY_DEFAULT_RX_LED_PIN x
|
||||||
|
|
||||||
//#define MY_LEDS_BLINKING_FEATURE
|
// The following setting allows you to inverse the LED blinking
|
||||||
|
|
||||||
// The following setting allows you to inverse the blinking feature MY_LEDS_BLINKING_FEATURE
|
|
||||||
// When MY_WITH_LEDS_BLINKING_INVERSE is enabled LEDSs are normally turned on and switches
|
// When MY_WITH_LEDS_BLINKING_INVERSE is enabled LEDSs are normally turned on and switches
|
||||||
// off when blinking
|
// off when blinking
|
||||||
|
|
||||||
//#define MY_WITH_LEDS_BLINKING_INVERSE
|
//#define MY_WITH_LEDS_BLINKING_INVERSE
|
||||||
|
|
||||||
// The following defines can be used to set the port pin, that the LED is connected to
|
|
||||||
// If one of the following is defined here, or in the sketch, MY_LEDS_BLINKING_FEATURE will be
|
|
||||||
// enabled by default. (Replace x with the pin number you have the LED on)
|
|
||||||
//#define MY_DEFAULT_ERR_LED_PIN x
|
|
||||||
//#define MY_DEFAULT_TX_LED_PIN x
|
|
||||||
//#define MY_DEFAULT_RX_LED_PIN x
|
|
||||||
|
|
||||||
/**********************************************
|
/**********************************************
|
||||||
* Gateway inclusion button/mode configuration
|
* Gateway inclusion button/mode configuration
|
||||||
@@ -649,7 +660,11 @@
|
|||||||
* @brief The Ethernet TCP/UDP port to open on controller or gateway.
|
* @brief The Ethernet TCP/UDP port to open on controller or gateway.
|
||||||
*/
|
*/
|
||||||
#ifndef MY_PORT
|
#ifndef MY_PORT
|
||||||
#define MY_PORT 5003
|
#ifdef MY_GATEWAY_MQTT_CLIENT
|
||||||
|
#define MY_PORT 1883
|
||||||
|
#else
|
||||||
|
#define MY_PORT 5003
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Static ip address of gateway (if this is disabled, DHCP will be used)
|
// Static ip address of gateway (if this is disabled, DHCP will be used)
|
||||||
@@ -755,4 +770,5 @@
|
|||||||
#define MY_RX_MESSAGE_BUFFER_SIZE
|
#define MY_RX_MESSAGE_BUFFER_SIZE
|
||||||
#define MY_NODE_LOCK_FEATURE
|
#define MY_NODE_LOCK_FEATURE
|
||||||
#define MY_REPEATER_FEATURE
|
#define MY_REPEATER_FEATURE
|
||||||
|
#define MY_TRANSPORT_DONT_CARE_MODE
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+29
-43
@@ -84,17 +84,12 @@
|
|||||||
#define MY_DEFAULT_RX_LED_PIN MY_HW_TX_LED_PIN
|
#define MY_DEFAULT_RX_LED_PIN MY_HW_TX_LED_PIN
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Not necessary to include blinking feature if no LED's are defined!
|
#if defined(MY_LEDS_BLINKING_FEATURE)
|
||||||
#if defined(MY_LEDS_BLINKING_FEATURE) && !defined(MY_DEFAULT_RX_LED_PIN) && !defined(MY_DEFAULT_TX_LED_PIN) && !defined(MY_ERR_LED_PIN)
|
#error MY_LEDS_BLINKING_FEATURE is now removed from MySensors core,\
|
||||||
#undef MY_LEDS_BLINKING_FEATURE
|
define MY_DEFAULT_ERR_LED_PIN, MY_DEFAULT_TX_LED_PIN or\
|
||||||
|
MY_DEFAULT_RX_LED_PIN in your sketch instead to enable LEDs
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Enable LED BLINKING FEATURE, if there are any LEDs defined.
|
|
||||||
#if defined(MY_DEFAULT_RX_LED_PIN) || defined(MY_DEFAULT_ERR_LED) || defined(MY_DEFAULT_TX_LED_PIN)
|
|
||||||
#define MY_LEDS_BLINKING_FEATURE
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @def MY_DEFAULT_LED_BLINK_PERIOD
|
* @def MY_DEFAULT_LED_BLINK_PERIOD
|
||||||
* @brief Default LEDs blinking period in milliseconds.
|
* @brief Default LEDs blinking period in milliseconds.
|
||||||
@@ -102,41 +97,8 @@
|
|||||||
#ifndef MY_DEFAULT_LED_BLINK_PERIOD
|
#ifndef MY_DEFAULT_LED_BLINK_PERIOD
|
||||||
#define MY_DEFAULT_LED_BLINK_PERIOD 300
|
#define MY_DEFAULT_LED_BLINK_PERIOD 300
|
||||||
#endif
|
#endif
|
||||||
/**
|
|
||||||
* @def MY_DEFAULT_RX_LED_PIN
|
|
||||||
* @brief The RX LED default pin.
|
|
||||||
*/
|
|
||||||
#ifndef MY_DEFAULT_RX_LED_PIN
|
|
||||||
#if defined(ARDUINO_ARCH_ESP8266)
|
|
||||||
#define MY_DEFAULT_RX_LED_PIN 8
|
|
||||||
#else
|
|
||||||
#define MY_DEFAULT_RX_LED_PIN 6
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
/**
|
|
||||||
* @def MY_DEFAULT_TX_LED_PIN
|
|
||||||
* @brief The TX LED default pin.
|
|
||||||
*/
|
|
||||||
#ifndef MY_DEFAULT_TX_LED_PIN
|
|
||||||
#if defined(ARDUINO_ARCH_ESP8266)
|
|
||||||
#define MY_DEFAULT_TX_LED_PIN 9
|
|
||||||
#else
|
|
||||||
#define MY_DEFAULT_TX_LED_PIN 5
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
/**
|
|
||||||
* @def MY_DEFAULT_ERR_LED_PIN
|
|
||||||
* @brief The Error LED default pin.
|
|
||||||
*/
|
|
||||||
#ifndef MY_DEFAULT_ERR_LED_PIN
|
|
||||||
#if defined(ARDUINO_ARCH_ESP8266)
|
|
||||||
#define MY_DEFAULT_ERR_LED_PIN 7
|
|
||||||
#else
|
|
||||||
#define MY_DEFAULT_ERR_LED_PIN 4
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MY_LEDS_BLINKING_FEATURE)
|
#if defined(MY_DEFAULT_RX_LED_PIN) || defined(MY_DEFAULT_TX_LED_PIN) || defined(MY_DEFAULT_ERR_LED_PIN)
|
||||||
#include "core/MyLeds.cpp"
|
#include "core/MyLeds.cpp"
|
||||||
#else
|
#else
|
||||||
#include "core/MyLeds.h"
|
#include "core/MyLeds.h"
|
||||||
@@ -250,6 +212,29 @@
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(MY_TRANSPORT_DONT_CARE_MODE) && !defined(MY_GATEWAY_FEATURE)
|
||||||
|
// enables transport don't care mode, i.e. transport link is not monitored and GW connection optional
|
||||||
|
#if !defined(MY_PARENT_NODE_ID) || MY_PARENT_NODE_ID==255
|
||||||
|
#error MY_TRANSPORT_DONT_CARE_MODE requires MY_PARENT_NODE_ID set
|
||||||
|
#endif
|
||||||
|
#if !defined(MY_PARENT_NODE_IS_STATIC)
|
||||||
|
#define MY_PARENT_NODE_IS_STATIC
|
||||||
|
#endif
|
||||||
|
#ifdef MY_REGISTRATION_FEATURE
|
||||||
|
#undef MY_REGISTRATION_FEATURE
|
||||||
|
#endif
|
||||||
|
#ifdef MY_TRANSPORT_SANITY_CHECK
|
||||||
|
#undef MY_TRANSPORT_SANITY_CHECK
|
||||||
|
#endif
|
||||||
|
#ifndef MY_TRANSPORT_UPLINK_CHECK_DISABLED
|
||||||
|
#define MY_TRANSPORT_UPLINK_CHECK_DISABLED
|
||||||
|
#endif
|
||||||
|
#ifdef MY_REGISTRATION_FEATURE
|
||||||
|
#undef MY_REGISTRATION_FEATURE
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
// RADIO
|
// RADIO
|
||||||
#if defined(MY_RADIO_NRF24) || defined(MY_RADIO_RFM69) || defined(MY_RS485)
|
#if defined(MY_RADIO_NRF24) || defined(MY_RADIO_RFM69) || defined(MY_RS485)
|
||||||
// SOFTSPI
|
// SOFTSPI
|
||||||
@@ -321,4 +306,5 @@
|
|||||||
// This is used to enable disabled macros/definitions to be included in the documentation as well.
|
// This is used to enable disabled macros/definitions to be included in the documentation as well.
|
||||||
#if DOXYGEN
|
#if DOXYGEN
|
||||||
#define MY_GATEWAY_FEATURE
|
#define MY_GATEWAY_FEATURE
|
||||||
|
#define MY_LEDS_BLINKING_FEATURE //!< \deprecated use MY_DEFAULT_RX_LED_PIN, MY_DEFAULT_TX_LED_PIN and/or MY_DEFAULT_ERR_LED_PIN instead **** DEPRECATED, DO NOT USE ****
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+68
-23
@@ -6,7 +6,7 @@
|
|||||||
* network topology allowing messages to be routed to nodes.
|
* network topology allowing messages to be routed to nodes.
|
||||||
*
|
*
|
||||||
* Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
|
* 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
|
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
|
||||||
*
|
*
|
||||||
* Documentation: http://www.mysensors.org
|
* Documentation: http://www.mysensors.org
|
||||||
@@ -17,28 +17,73 @@
|
|||||||
* version 2 as published by the Free Software Foundation.
|
* 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
|
#ifndef MyEepromAddresses_h
|
||||||
#define 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
|
||||||
|
|
||||||
|
/** @}*/
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
#include "MyHwATMega328.h"
|
#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 _wokeUpByInterrupt = INVALID_INTERRUPT_NUM; // Interrupt number that woke the mcu.
|
||||||
volatile uint8_t _wakeUp1Interrupt = INVALID_INTERRUPT_NUM; // Interrupt number for wakeUp1-callback.
|
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) {
|
int8_t hwSleep(unsigned long ms) {
|
||||||
hwInternalSleep(ms);
|
hwInternalSleep(ms);
|
||||||
return -1;
|
return MY_WAKE_UP_BY_TIMER;
|
||||||
}
|
}
|
||||||
|
|
||||||
int8_t hwSleep(uint8_t interrupt, uint8_t mode, unsigned long ms) {
|
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.
|
// 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);
|
if (interruptWakeUp()) ret = static_cast<int8_t>(_wokeUpByInterrupt);
|
||||||
|
|
||||||
// Clear woke-up-by-interrupt flag, so next sleeps won't return immediately.
|
// Clear woke-up-by-interrupt flag, so next sleeps won't return immediately.
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ do { \
|
|||||||
#define hwWatchdogReset() wdt_reset()
|
#define hwWatchdogReset() wdt_reset()
|
||||||
#define hwReboot() wdt_enable(WDTO_15MS); while (1)
|
#define hwReboot() wdt_enable(WDTO_15MS); while (1)
|
||||||
#define hwMillis() millis()
|
#define hwMillis() millis()
|
||||||
|
#define hwRandomNumberInit() randomSeed(analogRead(MY_SIGNING_SOFT_RANDOMSEED_PIN))
|
||||||
#define hwReadConfig(__pos) (eeprom_read_byte((uint8_t*)(__pos)))
|
#define hwReadConfig(__pos) (eeprom_read_byte((uint8_t*)(__pos)))
|
||||||
|
|
||||||
#ifndef eeprom_update_byte
|
#ifndef eeprom_update_byte
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ void hwWriteConfig(int adr, uint8_t value)
|
|||||||
int8_t hwSleep(unsigned long ms) {
|
int8_t hwSleep(unsigned long ms) {
|
||||||
// TODO: Not supported!
|
// TODO: Not supported!
|
||||||
(void)ms;
|
(void)ms;
|
||||||
return -2;
|
return MY_SLEEP_NOT_POSSIBLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
int8_t hwSleep(uint8_t interrupt, uint8_t mode, unsigned long ms) {
|
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)interrupt;
|
||||||
(void)mode;
|
(void)mode;
|
||||||
(void)ms;
|
(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) {
|
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)interrupt2;
|
||||||
(void)mode2;
|
(void)mode2;
|
||||||
(void)ms;
|
(void)ms;
|
||||||
return -2;
|
return MY_SLEEP_NOT_POSSIBLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
ADC_MODE(ADC_VCC);
|
ADC_MODE(ADC_VCC);
|
||||||
|
|||||||
+2
-1
@@ -37,8 +37,9 @@
|
|||||||
#define hwDigitalWrite(__pin, __value) (digitalWrite(__pin, __value))
|
#define hwDigitalWrite(__pin, __value) (digitalWrite(__pin, __value))
|
||||||
#define hwInit() MY_SERIALDEVICE.begin(MY_BAUD_RATE); MY_SERIALDEVICE.setDebugOutput(true)
|
#define hwInit() MY_SERIALDEVICE.begin(MY_BAUD_RATE); MY_SERIALDEVICE.setDebugOutput(true)
|
||||||
#define hwWatchdogReset() wdt_reset()
|
#define hwWatchdogReset() wdt_reset()
|
||||||
#define hwReboot() ESP.restart();
|
#define hwReboot() ESP.restart()
|
||||||
#define hwMillis() millis()
|
#define hwMillis() millis()
|
||||||
|
#define hwRandomNumberInit() randomSeed(analogRead(MY_SIGNING_SOFT_RANDOMSEED_PIN))
|
||||||
|
|
||||||
void hwReadConfigBlock(void* buf, void* adr, size_t length);
|
void hwReadConfigBlock(void* buf, void* adr, size_t length);
|
||||||
void hwWriteConfigBlock(void* buf, void* adr, size_t length);
|
void hwWriteConfigBlock(void* buf, void* adr, size_t length);
|
||||||
|
|||||||
+3
-3
@@ -117,7 +117,7 @@ void hwReboot() {
|
|||||||
int8_t hwSleep(unsigned long ms) {
|
int8_t hwSleep(unsigned long ms) {
|
||||||
// TODO: Not supported!
|
// TODO: Not supported!
|
||||||
(void)ms;
|
(void)ms;
|
||||||
return -2;
|
return MY_SLEEP_NOT_POSSIBLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
int8_t hwSleep(uint8_t interrupt, uint8_t mode, unsigned long ms) {
|
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)interrupt;
|
||||||
(void)mode;
|
(void)mode;
|
||||||
(void)ms;
|
(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) {
|
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)interrupt2;
|
||||||
(void)mode2;
|
(void)mode2;
|
||||||
(void)ms;
|
(void)ms;
|
||||||
return -2;
|
return MY_SLEEP_NOT_POSSIBLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t hwCPUVoltage() {
|
uint16_t hwCPUVoltage() {
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ void hwInit();
|
|||||||
void hwWatchdogReset();
|
void hwWatchdogReset();
|
||||||
void hwReboot();
|
void hwReboot();
|
||||||
#define hwMillis() millis()
|
#define hwMillis() millis()
|
||||||
|
#define hwRandomNumberInit() randomSeed(analogRead(MY_SIGNING_SOFT_RANDOMSEED_PIN))
|
||||||
|
|
||||||
void hwReadConfigBlock(void* buf, void* adr, size_t length);
|
void hwReadConfigBlock(void* buf, void* adr, size_t length);
|
||||||
void hwWriteConfigBlock(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"
|
#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"
|
#include "MyLeds.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void setIndication( const indication_t ind )
|
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))
|
if ((INDICATION_TX == ind) || (INDICATION_GW_TX == ind))
|
||||||
{
|
{
|
||||||
ledsBlinkTx(1);
|
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);
|
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.
|
// Number of blinks indicates which error occurred.
|
||||||
ledsBlinkErr(ind-INDICATION_ERR_START);
|
ledsBlinkErr(ind-INDICATION_ERR_START);
|
||||||
|
|||||||
+12
-2
@@ -37,10 +37,15 @@ inline void ledsInit()
|
|||||||
countErr = 0;
|
countErr = 0;
|
||||||
|
|
||||||
// Setup led pins
|
// Setup led pins
|
||||||
|
#if defined(MY_DEFAULT_RX_LED_PIN)
|
||||||
pinMode(MY_DEFAULT_RX_LED_PIN, OUTPUT);
|
pinMode(MY_DEFAULT_RX_LED_PIN, OUTPUT);
|
||||||
|
#endif
|
||||||
|
#if defined(MY_DEFAULT_TX_LED_PIN)
|
||||||
pinMode(MY_DEFAULT_TX_LED_PIN, OUTPUT);
|
pinMode(MY_DEFAULT_TX_LED_PIN, OUTPUT);
|
||||||
|
#endif
|
||||||
|
#if defined(MY_DEFAULT_ERR_LED_PIN)
|
||||||
pinMode(MY_DEFAULT_ERR_LED_PIN, OUTPUT);
|
pinMode(MY_DEFAULT_ERR_LED_PIN, OUTPUT);
|
||||||
|
#endif
|
||||||
ledsProcess();
|
ledsProcess();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,17 +60,23 @@ void ledsProcess() {
|
|||||||
|
|
||||||
// For an On/Off ratio of 4, the pattern repeated will be [on, on, on, off]
|
// For an On/Off ratio of 4, the pattern repeated will be [on, on, on, off]
|
||||||
// until the counter becomes 0.
|
// until the counter becomes 0.
|
||||||
|
#if defined(MY_DEFAULT_RX_LED_PIN)
|
||||||
state = (countRx & (LED_ON_OFF_RATIO-1)) ? LED_ON : LED_OFF;
|
state = (countRx & (LED_ON_OFF_RATIO-1)) ? LED_ON : LED_OFF;
|
||||||
hwDigitalWrite(MY_DEFAULT_RX_LED_PIN, state);
|
hwDigitalWrite(MY_DEFAULT_RX_LED_PIN, state);
|
||||||
if (countRx) --countRx;
|
if (countRx) --countRx;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MY_DEFAULT_TX_LED_PIN)
|
||||||
state = (countTx & (LED_ON_OFF_RATIO-1)) ? LED_ON : LED_OFF;
|
state = (countTx & (LED_ON_OFF_RATIO-1)) ? LED_ON : LED_OFF;
|
||||||
hwDigitalWrite(MY_DEFAULT_TX_LED_PIN, state);
|
hwDigitalWrite(MY_DEFAULT_TX_LED_PIN, state);
|
||||||
if (countTx) --countTx;
|
if (countTx) --countTx;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MY_DEFAULT_ERR_LED_PIN)
|
||||||
state = (countErr & (LED_ON_OFF_RATIO-1)) ? LED_ON : LED_OFF;
|
state = (countErr & (LED_ON_OFF_RATIO-1)) ? LED_ON : LED_OFF;
|
||||||
hwDigitalWrite(MY_DEFAULT_ERR_LED_PIN, state);
|
hwDigitalWrite(MY_DEFAULT_ERR_LED_PIN, state);
|
||||||
if (countErr) --countErr;
|
if (countErr) --countErr;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void ledsBlinkRx(uint8_t cnt) {
|
void ledsBlinkRx(uint8_t cnt) {
|
||||||
@@ -79,4 +90,3 @@ void ledsBlinkTx(uint8_t cnt) {
|
|||||||
void ledsBlinkErr(uint8_t cnt) {
|
void ledsBlinkErr(uint8_t cnt) {
|
||||||
if(!countErr) { countErr = cnt*LED_ON_OFF_RATIO; }
|
if(!countErr) { countErr = cnt*LED_ON_OFF_RATIO; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -29,7 +29,7 @@
|
|||||||
#define LED_OFF 0x1
|
#define LED_OFF 0x1
|
||||||
#endif
|
#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 ledBlinkTx(x,...) ledsBlinkTx(x)
|
||||||
#define ledBlinkRx(x,...) ledsBlinkRx(x)
|
#define ledBlinkRx(x,...) ledsBlinkRx(x)
|
||||||
#define ledBlinkErr(x,...) ledsBlinkErr(x)
|
#define ledBlinkErr(x,...) ledsBlinkErr(x)
|
||||||
|
|||||||
+106
-89
@@ -35,7 +35,7 @@ void (*_timeCallback)(unsigned long); // Callback for requested time messages
|
|||||||
void _process() {
|
void _process() {
|
||||||
hwWatchdogReset();
|
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();
|
ledsProcess();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -58,7 +58,7 @@ void _infiniteLoop() {
|
|||||||
#if defined(ARDUINO_ARCH_ESP8266)
|
#if defined(ARDUINO_ARCH_ESP8266)
|
||||||
yield();
|
yield();
|
||||||
#endif
|
#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();
|
ledsProcess();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -81,7 +81,7 @@ void _begin() {
|
|||||||
before();
|
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();
|
ledsInit();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -280,12 +280,10 @@ void sendBatteryLevel(uint8_t value, bool enableAck) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void sendHeartbeat(void) {
|
void sendHeartbeat(void) {
|
||||||
#if defined(MY_RADIO_NRF24) || defined(MY_RADIO_RFM69) || defined(MY_RS485)
|
#if defined(MY_RADIO_FEATURE)
|
||||||
uint32_t heartbeat = transportGetHeartbeat();
|
uint32_t heartbeat = transportGetHeartbeat();
|
||||||
#else
|
_sendRoute(build(_msgTmp, _nc.nodeId, GATEWAY_ADDRESS, NODE_SENSOR_ID, C_INTERNAL, I_HEARTBEAT_RESPONSE, false).set(heartbeat));
|
||||||
uint32_t heartbeat = hwMillis();
|
|
||||||
#endif
|
#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) {
|
void present(uint8_t childSensorId, uint8_t sensorType, const char *description, bool enableAck) {
|
||||||
@@ -356,11 +354,11 @@ bool _processInternalMessages() {
|
|||||||
const char debug_msg = _msg.data[0];
|
const char debug_msg = _msg.data[0];
|
||||||
if (debug_msg == 'R') { // routing table
|
if (debug_msg == 'R') { // routing table
|
||||||
#if defined(MY_REPEATER_FEATURE)
|
#if defined(MY_REPEATER_FEATURE)
|
||||||
for (uint8_t cnt = 0; cnt != 255; cnt++) {
|
for (uint16_t cnt = 0; cnt < SIZE_ROUTES; cnt++) {
|
||||||
const uint8_t route = transportGetRoute(cnt);
|
const uint8_t route = transportGetRoute(cnt);
|
||||||
if (route != BROADCAST_ADDRESS) {
|
if (route != BROADCAST_ADDRESS) {
|
||||||
debug(PSTR("MCO:PIM:ROUTE N=%d,R=%d\n"), cnt, route);
|
debug(PSTR("MCO:PIM:ROUTE N=%d,R=%d\n"), cnt, route);
|
||||||
uint8_t outBuf[2] = { cnt,route };
|
uint8_t outBuf[2] = { (uint8_t)cnt,route };
|
||||||
_sendRoute(build(_msgTmp, _nc.nodeId, GATEWAY_ADDRESS, NODE_SENSOR_ID, C_INTERNAL, I_DEBUG, false).set(outBuf, 2));
|
_sendRoute(build(_msgTmp, _nc.nodeId, GATEWAY_ADDRESS, NODE_SENSOR_ID, C_INTERNAL, I_DEBUG, false).set(outBuf, 2));
|
||||||
wait(200);
|
wait(200);
|
||||||
}
|
}
|
||||||
@@ -398,7 +396,11 @@ bool _processInternalMessages() {
|
|||||||
#if defined(MY_CORE_COMPATIBILITY_CHECK)
|
#if defined(MY_CORE_COMPATIBILITY_CHECK)
|
||||||
approveRegistration = (_msg.getByte() >= MY_CORE_MIN_VERSION);
|
approveRegistration = (_msg.getByte() >= MY_CORE_MIN_VERSION);
|
||||||
#endif
|
#endif
|
||||||
// delay for slow nodes *****************************
|
|
||||||
|
#if (F_CPU>16000000)
|
||||||
|
// delay for fast GW and slow nodes
|
||||||
|
delay(5);
|
||||||
|
#endif
|
||||||
_sendRoute(build(_msgTmp, _nc.nodeId, _msg.sender, NODE_SENSOR_ID, C_INTERNAL, I_REGISTRATION_RESPONSE, false).set(approveRegistration));
|
_sendRoute(build(_msgTmp, _nc.nodeId, _msg.sender, NODE_SENSOR_ID, C_INTERNAL, I_REGISTRATION_RESPONSE, false).set(approveRegistration));
|
||||||
#else
|
#else
|
||||||
return false; // processing of this request via controller
|
return false; // processing of this request via controller
|
||||||
@@ -444,104 +446,118 @@ bool wait(unsigned long ms, uint8_t cmd, uint8_t msgtype) {
|
|||||||
return expectedResponse;
|
return expectedResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
||||||
int8_t sleep(unsigned long ms) {
|
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 defined(MY_OTA_FIRMWARE_FEATURE)
|
||||||
if (_fwUpdateOngoing) {
|
if (_fwUpdateOngoing) {
|
||||||
// Do not sleep node while fw update is ongoing
|
debug(PSTR("!MCO:SLP:FWUPD\n")); // sleeping not possible, FW update ongoing
|
||||||
wait(ms);
|
wait(ms);
|
||||||
return -1;
|
return MY_SLEEP_NOT_POSSIBLE;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
// if repeater, do not sleep
|
// repeater feature: sleeping not possible
|
||||||
#if defined(MY_REPEATER_FEATURE)
|
#if defined(MY_REPEATER_FEATURE)
|
||||||
wait(ms);
|
(void)smartSleep;
|
||||||
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)interrupt1;
|
(void)interrupt1;
|
||||||
(void)mode1;
|
(void)mode1;
|
||||||
(void)interrupt2;
|
(void)interrupt2;
|
||||||
(void)mode2;
|
(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
|
#else
|
||||||
|
uint32_t sleepingTime = ms;
|
||||||
#if defined(MY_RADIO_FEATURE)
|
#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();
|
transportPowerDown();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
setIndication(INDICATION_SLEEP);
|
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);
|
setIndication(INDICATION_WAKEUP);
|
||||||
|
debug(PSTR("MCO:SLP:WUP=%d\n"), res); // sleep wake-up
|
||||||
return res;
|
return res;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int8_t smartSleep(uint8_t interrupt1, uint8_t mode1, uint8_t interrupt2, uint8_t mode2, unsigned long ms) {
|
// sleep functions
|
||||||
// notify controller about going to sleep
|
int8_t sleep(const uint32_t ms, const bool smartSleep) {
|
||||||
sendHeartbeat();
|
return _sleep(ms, smartSleep);
|
||||||
// listen for incoming messages
|
|
||||||
wait(MY_SMART_SLEEP_WAIT_DURATION);
|
|
||||||
return sleep(interrupt1, mode1, interrupt2, mode2, ms);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
#ifdef MY_NODE_LOCK_FEATURE
|
||||||
void nodeLock(const char* str) {
|
void nodeLock(const char* str) {
|
||||||
// Make sure EEPROM is updated to locked status
|
// Make sure EEPROM is updated to locked status
|
||||||
@@ -555,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));
|
_sendRoute(build(_msgTmp, _nc.nodeId, GATEWAY_ADDRESS, NODE_SENSOR_ID,C_INTERNAL, I_LOCKED, false).set(str));
|
||||||
#if defined(MY_RADIO_FEATURE)
|
#if defined(MY_RADIO_FEATURE)
|
||||||
transportPowerDown();
|
transportPowerDown();
|
||||||
|
debug(PSTR("MCO:NLK:TPD\n")); // power down transport
|
||||||
#endif
|
#endif
|
||||||
setIndication(INDICATION_SLEEP);
|
setIndication(INDICATION_SLEEP);
|
||||||
(void)hwSleep((unsigned long)1000*60*30); // Sleep for 30 min before resending LOCKED message
|
(void)hwSleep((unsigned long)1000*60*30); // Sleep for 30 min before resending LOCKED message
|
||||||
|
|||||||
+81
-28
@@ -37,6 +37,7 @@
|
|||||||
*
|
*
|
||||||
* MySensorsCore debug log messages:
|
* MySensorsCore debug log messages:
|
||||||
*
|
*
|
||||||
|
<<<<<<< HEAD
|
||||||
* |E| SYS | SUB | Message | Comment
|
* |E| SYS | SUB | Message | Comment
|
||||||
* |-|------|-------|-------------------------------------------|----------------------------------------------------------------------------
|
* |-|------|-------|-------------------------------------------|----------------------------------------------------------------------------
|
||||||
* | | MCO | BGN | INIT %%s,CP=%%s,LIB=%%s | Core initialization, capabilities (CP), library version (VER)
|
* | | MCO | BGN | INIT %%s,CP=%%s,LIB=%%s | Core initialization, capabilities (CP), library version (VER)
|
||||||
@@ -51,6 +52,28 @@
|
|||||||
* | | MCO | PIM | NODE REG=%%d | Registration response received, registration status (REG)
|
* | | 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 | 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
|
* | | 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
|
||||||
|
>>>>>>> development
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @brief API declaration for MySensorsCore
|
* @brief API declaration for MySensorsCore
|
||||||
@@ -67,10 +90,16 @@
|
|||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
#define GATEWAY_ADDRESS ((uint8_t)0) //!< Node ID for GW sketch
|
#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 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_VERSION ((uint8_t)2) //!< core version
|
||||||
#define MY_CORE_MIN_VERSION ((uint8_t)2) //!< min core version required for compatibility
|
#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
|
#ifdef MY_DEBUG
|
||||||
#define debug(x,...) hwDebugPrint(x, ##__VA_ARGS__) //!< debug
|
#define debug(x,...) hwDebugPrint(x, ##__VA_ARGS__) //!< debug
|
||||||
@@ -232,16 +261,10 @@ bool wait(unsigned long ms, uint8_t cmd, uint8_t msgtype);
|
|||||||
/**
|
/**
|
||||||
* Sleep (PowerDownMode) the MCU and radio. Wake up on timer.
|
* Sleep (PowerDownMode) the MCU and radio. Wake up on timer.
|
||||||
* @param ms Number of milliseconds to sleep.
|
* @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);
|
int8_t sleep(const uint32_t ms, const bool smartSleep = false);
|
||||||
/**
|
|
||||||
* 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);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sleep (PowerDownMode) the MCU and radio. Wake up on timer or pin change.
|
* Sleep (PowerDownMode) the MCU and radio. Wake up on timer or pin change.
|
||||||
@@ -250,18 +273,10 @@ int8_t smartSleep(unsigned long ms);
|
|||||||
* @param interrupt Interrupt that should trigger the wakeup
|
* @param interrupt Interrupt that should trigger the wakeup
|
||||||
* @param mode RISING, FALLING, CHANGE
|
* @param mode RISING, FALLING, CHANGE
|
||||||
* @param ms Number of milliseconds to sleep or 0 to sleep forever
|
* @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);
|
int8_t sleep(const uint8_t interrupt, const uint8_t mode, const uint32_t ms=0, const bool smartSleep = false);
|
||||||
/**
|
|
||||||
* 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);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sleep (PowerDownMode) the MCU and radio. Wake up on timer or pin change for two separate interrupts.
|
* Sleep (PowerDownMode) the MCU and radio. Wake up on timer or pin change for two separate interrupts.
|
||||||
@@ -272,10 +287,33 @@ int8_t smartSleep(uint8_t interrupt, uint8_t mode, unsigned long ms=0);
|
|||||||
* @param interrupt2 Second interrupt that should trigger the wakeup
|
* @param interrupt2 Second interrupt that should trigger the wakeup
|
||||||
* @param mode2 Mode for second interrupt (RISING, FALLING, CHANGE)
|
* @param mode2 Mode for second interrupt (RISING, FALLING, CHANGE)
|
||||||
* @param ms Number of milliseconds to sleep or 0 to sleep forever
|
* @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.
|
* 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).
|
* 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
|
* @param interrupt1 First interrupt that should trigger the wakeup
|
||||||
@@ -283,9 +321,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 interrupt2 Second interrupt that should trigger the wakeup
|
||||||
* @param mode2 Mode for second interrupt (RISING, FALLING, CHANGE)
|
* @param mode2 Mode for second interrupt (RISING, FALLING, CHANGE)
|
||||||
* @param ms Number of milliseconds to sleep or 0 to sleep forever
|
* @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
|
#ifdef MY_NODE_LOCK_FEATURE
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ static void DEBUG_SIGNING_PRINTBUF(const __FlashStringHelper* str, uint8_t* buf,
|
|||||||
|
|
||||||
void signerAtsha204SoftInit(void) {
|
void signerAtsha204SoftInit(void) {
|
||||||
// initialize pseudo-RNG
|
// initialize pseudo-RNG
|
||||||
randomSeed(analogRead(MY_SIGNING_SOFT_RANDOMSEED_PIN));
|
hwRandomNumberInit();
|
||||||
// Set secrets
|
// Set secrets
|
||||||
hwReadConfigBlock((void*)_signing_hmac_key, (void*)EEPROM_SIGNING_SOFT_HMAC_KEY_ADDRESS, 32);
|
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);
|
hwReadConfigBlock((void*)_signing_node_serial_info, (void*)EEPROM_SIGNING_SOFT_SERIAL_ADDRESS, 9);
|
||||||
|
|||||||
+23
-7
@@ -74,6 +74,9 @@ void stInitTransition(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void stInitUpdate(void) {
|
void stInitUpdate(void) {
|
||||||
|
#if defined(MY_TRANSPORT_DONT_CARE_MODE)
|
||||||
|
TRANSPORT_DEBUG(PSTR("TSM:INIT:TDC\n")); // transport don't care mode
|
||||||
|
#endif
|
||||||
// initialise radio
|
// initialise radio
|
||||||
if (!transportInit()) {
|
if (!transportInit()) {
|
||||||
TRANSPORT_DEBUG(PSTR("!TSM:INIT:TSP FAIL\n"));
|
TRANSPORT_DEBUG(PSTR("!TSM:INIT:TSP FAIL\n"));
|
||||||
@@ -281,7 +284,6 @@ void stReadyUpdate(void) {
|
|||||||
#if defined(MY_RAM_ROUTING_TABLE_ENABLED)
|
#if defined(MY_RAM_ROUTING_TABLE_ENABLED)
|
||||||
if (hwMillis() - _lastRoutingTableSave > MY_ROUTING_TABLE_SAVE_INTERVAL_MS) {
|
if (hwMillis() - _lastRoutingTableSave > MY_ROUTING_TABLE_SAVE_INTERVAL_MS) {
|
||||||
_lastRoutingTableSave = hwMillis();
|
_lastRoutingTableSave = hwMillis();
|
||||||
TRANSPORT_DEBUG(PSTR("TSM:READY:SRT\n")); // save routing table
|
|
||||||
transportSaveRoutingTable();
|
transportSaveRoutingTable();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -341,6 +343,15 @@ bool isTransportSearchingParent(void) {
|
|||||||
return _transportSM.findingParentNode;
|
return _transportSM.findingParentNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isMessageReceived(void) {
|
||||||
|
return _transportSM.MsgReceived;
|
||||||
|
}
|
||||||
|
|
||||||
|
void resetMessageReceived(void) {
|
||||||
|
_transportSM.MsgReceived = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void transportInitialise(void) {
|
void transportInitialise(void) {
|
||||||
_transportSM.failureCounter = 0u; // reset failure counter
|
_transportSM.failureCounter = 0u; // reset failure counter
|
||||||
transportLoadRoutingTable(); // load routing table to RAM (if feature enabled)
|
transportLoadRoutingTable(); // load routing table to RAM (if feature enabled)
|
||||||
@@ -567,6 +578,9 @@ void transportProcessMessage(void) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// set message received flag
|
||||||
|
_transportSM.MsgReceived = true;
|
||||||
|
|
||||||
// Is message addressed to this node?
|
// Is message addressed to this node?
|
||||||
if (destination == _nc.nodeId) {
|
if (destination == _nc.nodeId) {
|
||||||
// null terminate data
|
// null terminate data
|
||||||
@@ -627,8 +641,8 @@ void transportProcessMessage(void) {
|
|||||||
// general
|
// general
|
||||||
if (type == I_PING) {
|
if (type == I_PING) {
|
||||||
TRANSPORT_DEBUG(PSTR("TSF:MSG:PINGED,ID=%d,HP=%d\n"), sender, _msg.getByte()); // node pinged
|
TRANSPORT_DEBUG(PSTR("TSF:MSG:PINGED,ID=%d,HP=%d\n"), sender, _msg.getByte()); // node pinged
|
||||||
// delay for slow nodes *****************************
|
#if defined(MY_GATEWAY_FEATURE) && (F_CPU>16000000)
|
||||||
#if defined(MY_GATEWAY_FEATURE) && (F_CPU<=16000000)
|
// delay for fast GW and slow nodes
|
||||||
delay(5);
|
delay(5);
|
||||||
#endif
|
#endif
|
||||||
(void)transportRouteMessage(build(_msgTmp, _nc.nodeId, sender, NODE_SENSOR_ID, C_INTERNAL, I_PONG, false).set((uint8_t)1));
|
(void)transportRouteMessage(build(_msgTmp, _nc.nodeId, sender, NODE_SENSOR_ID, C_INTERNAL, I_PONG, false).set((uint8_t)1));
|
||||||
@@ -819,8 +833,8 @@ bool transportSendWrite(const uint8_t to, MyMessage &message) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void transportClearRoutingTable(void) {
|
void transportClearRoutingTable(void) {
|
||||||
for (uint8_t i = 0; i != 255; i++) {
|
for (uint16_t i = 0; i < SIZE_ROUTES; i++) {
|
||||||
transportSetRoute(i, BROADCAST_ADDRESS);
|
transportSetRoute((uint8_t)i, BROADCAST_ADDRESS);
|
||||||
}
|
}
|
||||||
transportSaveRoutingTable(); // save cleared routing table to EEPROM (if feature enabled)
|
transportSaveRoutingTable(); // save cleared routing table to EEPROM (if feature enabled)
|
||||||
TRANSPORT_DEBUG(PSTR("TSF:CRT:OK\n")); // clear routing table
|
TRANSPORT_DEBUG(PSTR("TSF:CRT:OK\n")); // clear routing table
|
||||||
@@ -828,13 +842,15 @@ void transportClearRoutingTable(void) {
|
|||||||
|
|
||||||
void transportLoadRoutingTable(void) {
|
void transportLoadRoutingTable(void) {
|
||||||
#if defined(MY_RAM_ROUTING_TABLE_ENABLED)
|
#if defined(MY_RAM_ROUTING_TABLE_ENABLED)
|
||||||
hwReadConfigBlock((void*)&_transportRoutingTable.route, (void*)EEPROM_ROUTES_ADDRESS, 256);
|
hwReadConfigBlock((void*)&_transportRoutingTable.route, (void*)EEPROM_ROUTES_ADDRESS, SIZE_ROUTES);
|
||||||
|
TRANSPORT_DEBUG(PSTR("TSF:LRT:OK\n")); // load routing table
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void transportSaveRoutingTable(void) {
|
void transportSaveRoutingTable(void) {
|
||||||
#if defined(MY_RAM_ROUTING_TABLE_ENABLED)
|
#if defined(MY_RAM_ROUTING_TABLE_ENABLED)
|
||||||
hwWriteConfigBlock((void*)EEPROM_ROUTES_ADDRESS, (void*)&_transportRoutingTable.route, 256);
|
hwWriteConfigBlock((void*)EEPROM_ROUTES_ADDRESS, (void*)&_transportRoutingTable.route, SIZE_ROUTES);
|
||||||
|
TRANSPORT_DEBUG(PSTR("TSF:SRT:OK\n")); // save routing table
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+22
-5
@@ -42,16 +42,20 @@
|
|||||||
* - TSF:ASID from @ref transportAssignNodeID(), assigns node ID
|
* - TSF:ASID from @ref transportAssignNodeID(), assigns node ID
|
||||||
* - TSF:PING from @ref transportPingNode(), pings a node
|
* - TSF:PING from @ref transportPingNode(), pings a node
|
||||||
* - TSF:CRT from @ref transportClearRoutingTable(), clears routing table stored in EEPROM
|
* - TSF:CRT from @ref transportClearRoutingTable(), clears routing table stored in EEPROM
|
||||||
|
* - TSF:LRT from @ref transportLoadRoutingTable(), loads RAM routing table from EEPROM (only GW/repeaters)
|
||||||
|
* - TSF:SRT from @ref transportSaveRoutingTable(), saves RAM routing table to EEPROM (only GW/repeaters)
|
||||||
* - TSF:MSG from @ref transportProcessMessage(), processes incoming message
|
* - TSF:MSG from @ref transportProcessMessage(), processes incoming message
|
||||||
* - TSF:SANCHK from @ref transportInvokeSanityCheck(), calls transport-specific sanity check
|
* - TSF:SANCHK from @ref transportInvokeSanityCheck(), calls transport-specific sanity check
|
||||||
* - TSF:ROUTE from @ref transportRouteMessage(), sends message
|
* - TSF:ROUTE from @ref transportRouteMessage(), sends message
|
||||||
* - TSF:SEND from @ref transportSendRoute(), sends message if transport is ready (exposed)
|
* - TSF:SEND from @ref transportSendRoute(), sends message if transport is ready (exposed)
|
||||||
|
|
||||||
*
|
*
|
||||||
* Transport debug log messages:
|
* Transport debug log messages:
|
||||||
*
|
*
|
||||||
* |E| SYS | SUB | Message | Comment
|
* |E| SYS | SUB | Message | Comment
|
||||||
* |-|------|-----------|-----------------------|---------------------------------------------------------------------
|
* |-|------|-----------|-----------------------|---------------------------------------------------------------------
|
||||||
* | | TSM | INIT | | <b>Transition to stInit state</b>
|
* | | TSM | INIT | | <b>Transition to stInit state</b>
|
||||||
|
* | | TSM | INIT | TDC | Transport don't care mode
|
||||||
* | | TSM | INIT | STATID=%%d | Node ID is static
|
* | | TSM | INIT | STATID=%%d | Node ID is static
|
||||||
* | | TSM | INIT | TSP OK | Transport device configured and fully operational
|
* | | TSM | INIT | TSP OK | Transport device configured and fully operational
|
||||||
* | | TSM | INIT | GW MODE | Node is set up as GW, thus omitting ID and findParent states
|
* | | TSM | INIT | GW MODE | Node is set up as GW, thus omitting ID and findParent states
|
||||||
@@ -70,6 +74,7 @@
|
|||||||
* | | TSF | UPL | DGWC,O=%%d,N=%%d | Uplink check revealed changed network topology, old distance (O), new distance (N)
|
* | | TSF | UPL | DGWC,O=%%d,N=%%d | Uplink check revealed changed network topology, old distance (O), new distance (N)
|
||||||
* |!| TSM | UPL | FAIL | Uplink check failed, i.e. GW could not be pinged
|
* |!| TSM | UPL | FAIL | Uplink check failed, i.e. GW could not be pinged
|
||||||
* | | TSM | READY | | <b>Transition to stReady</b>, i.e. transport is ready and fully operational
|
* | | TSM | READY | | <b>Transition to stReady</b>, i.e. transport is ready and fully operational
|
||||||
|
* | | TSM | READY | SRT | Save routing table
|
||||||
* |!| TSM | READY | UPL FAIL,SNP | Too many failed uplink transmissions, search new parent
|
* |!| TSM | READY | UPL FAIL,SNP | Too many failed uplink transmissions, search new parent
|
||||||
* |!| TSM | READY | FAIL,STATP | Too many failed uplink transmissions, static parent enforced
|
* |!| TSM | READY | FAIL,STATP | Too many failed uplink transmissions, static parent enforced
|
||||||
* | | TSM | FAIL | CNT=%%d | <b>Transition to stFailure state</b>, consecutive failure counter (CNT)
|
* | | TSM | FAIL | CNT=%%d | <b>Transition to stFailure state</b>, consecutive failure counter (CNT)
|
||||||
@@ -105,6 +110,8 @@
|
|||||||
* | | TSF | SANCHK | OK | Sanity check passed
|
* | | TSF | SANCHK | OK | Sanity check passed
|
||||||
* |!| TSF | SANCHK | FAIL | Sanity check failed, attempt to re-initialize radio
|
* |!| TSF | SANCHK | FAIL | Sanity check failed, attempt to re-initialize radio
|
||||||
* | | TSF | CRT | OK | Clearing routing table successful
|
* | | TSF | CRT | OK | Clearing routing table successful
|
||||||
|
* | | TSF | LRT | OK | Loading routing table successful
|
||||||
|
* | | TSF | SRT | OK | Saving routing table successful
|
||||||
* |!| TSF | ROUTE | FPAR ACTIVE | Finding parent active, message not sent
|
* |!| TSF | ROUTE | FPAR ACTIVE | Finding parent active, message not sent
|
||||||
* |!| TSF | ROUTE | DST %%d UNKNOWN | Routing for destination (DST) unknown, send message to parent
|
* |!| TSF | ROUTE | DST %%d UNKNOWN | Routing for destination (DST) unknown, send message to parent
|
||||||
* |!| TSF | SEND | TNR | Transport not ready, message cannot be sent
|
* |!| TSF | SEND | TNR | Transport not ready, message cannot be sent
|
||||||
@@ -151,7 +158,7 @@
|
|||||||
#define MY_TRANSPORT_MAX_TX_FAILURES (5u) //!< search for a new parent node after this many transmission failures, lower threshold for non-repeating nodes
|
#define MY_TRANSPORT_MAX_TX_FAILURES (5u) //!< search for a new parent node after this many transmission failures, lower threshold for non-repeating nodes
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define MY_TRANSPORT_MAX_TSM_FAILURES (15u) //!< Max. number of consecutive TSM failure state entries (4bit)
|
#define MY_TRANSPORT_MAX_TSM_FAILURES (7u) //!< Max. number of consecutive TSM failure state entries (3bits)
|
||||||
|
|
||||||
#ifndef MY_TRANSPORT_TIMEOUT_FAILURE_STATE
|
#ifndef MY_TRANSPORT_TIMEOUT_FAILURE_STATE
|
||||||
#define MY_TRANSPORT_TIMEOUT_FAILURE_STATE (10*1000ul) //!< Duration failure state (in ms)
|
#define MY_TRANSPORT_TIMEOUT_FAILURE_STATE (10*1000ul) //!< Duration failure state (in ms)
|
||||||
@@ -228,7 +235,8 @@ typedef struct {
|
|||||||
uint8_t stateRetries : 3; //!< retries / state re-enter (max 7)
|
uint8_t stateRetries : 3; //!< retries / state re-enter (max 7)
|
||||||
// 8 bits
|
// 8 bits
|
||||||
uint8_t failedUplinkTransmissions : 4; //!< counter failed uplink transmissions (max 15)
|
uint8_t failedUplinkTransmissions : 4; //!< counter failed uplink transmissions (max 15)
|
||||||
uint8_t failureCounter : 4; //!< counter for TSM failures (max 15)
|
uint8_t failureCounter : 3; //!< counter for TSM failures (max 7)
|
||||||
|
bool MsgReceived : 1; //!< flag message received
|
||||||
// 8 bits
|
// 8 bits
|
||||||
uint8_t pingResponse; //!< stores I_PONG hops
|
uint8_t pingResponse; //!< stores I_PONG hops
|
||||||
} transportSM;
|
} transportSM;
|
||||||
@@ -237,7 +245,7 @@ typedef struct {
|
|||||||
* @brief RAM routing table
|
* @brief RAM routing table
|
||||||
*/
|
*/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t route[256]; //!< route for node
|
uint8_t route[SIZE_ROUTES]; //!< route for node
|
||||||
} routingTable;
|
} routingTable;
|
||||||
|
|
||||||
// PRIVATE functions
|
// PRIVATE functions
|
||||||
@@ -363,7 +371,7 @@ bool transportSendWrite(const uint8_t to, MyMessage &message);
|
|||||||
* @param force to override flood control timer
|
* @param force to override flood control timer
|
||||||
* @return true if uplink ok
|
* @return true if uplink ok
|
||||||
*/
|
*/
|
||||||
bool transportCheckUplink(bool force=false);
|
bool transportCheckUplink(const bool force=false);
|
||||||
|
|
||||||
// PUBLIC functions
|
// PUBLIC functions
|
||||||
|
|
||||||
@@ -391,6 +399,15 @@ bool isTransportSearchingParent(void);
|
|||||||
*/
|
*/
|
||||||
bool isTransportExtendedFailure(void);
|
bool isTransportExtendedFailure(void);
|
||||||
/**
|
/**
|
||||||
|
* @brief Flag valid message received
|
||||||
|
* @return true if valid message received, needs to be reset if used
|
||||||
|
*/
|
||||||
|
bool isMessageReceived(void);
|
||||||
|
/**
|
||||||
|
* @brief Reset message received flag
|
||||||
|
*/
|
||||||
|
void resetMessageReceived(void);
|
||||||
|
/**
|
||||||
* @brief Clear routing table
|
* @brief Clear routing table
|
||||||
*/
|
*/
|
||||||
void transportClearRoutingTable(void);
|
void transportClearRoutingTable(void);
|
||||||
@@ -423,7 +440,7 @@ void transportSetRoute(const uint8_t node, const uint8_t route);
|
|||||||
uint8_t transportGetRoute(const uint8_t node);
|
uint8_t transportGetRoute(const uint8_t node);
|
||||||
|
|
||||||
|
|
||||||
// interface functions for radio driver ************************************************
|
// interface functions for radio driver
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Initialize transport HW
|
* @brief Initialize transport HW
|
||||||
|
|||||||
@@ -33,7 +33,7 @@
|
|||||||
* E.g. If you want to use the defualt values in this sketch enter: 192.168.178.66:5003
|
* E.g. If you want to use the defualt values in this sketch enter: 192.168.178.66:5003
|
||||||
*
|
*
|
||||||
* LED purposes:
|
* LED purposes:
|
||||||
* - To use the feature, uncomment WITH_LEDS_BLINKING in MyConfig.h
|
* - To use the feature, uncomment any of the MY_DEFAULT_xx_LED_PINs in your sketch, only the LEDs that is defined is used.
|
||||||
* - RX (green) - blink fast on radio message recieved. In inclusion mode will blink fast only on presentation recieved
|
* - RX (green) - blink fast on radio message recieved. In inclusion mode will blink fast only on presentation recieved
|
||||||
* - TX (yellow) - blink fast on radio message transmitted. In inclusion mode will blink slowly
|
* - TX (yellow) - blink fast on radio message transmitted. In inclusion mode will blink slowly
|
||||||
* - ERR (red) - fast blink on error during transmission error or recieve crc error
|
* - ERR (red) - fast blink on error during transmission error or recieve crc error
|
||||||
@@ -116,11 +116,10 @@
|
|||||||
#define MY_INCLUSION_MODE_BUTTON_PIN 3
|
#define MY_INCLUSION_MODE_BUTTON_PIN 3
|
||||||
|
|
||||||
|
|
||||||
// Flash leds on rx/tx/err
|
|
||||||
// #define MY_LEDS_BLINKING_FEATURE
|
|
||||||
// Set blinking period
|
// Set blinking period
|
||||||
// #define MY_DEFAULT_LED_BLINK_PERIOD 300
|
// #define MY_DEFAULT_LED_BLINK_PERIOD 300
|
||||||
|
|
||||||
|
// Flash leds on rx/tx/err
|
||||||
// Led pins used if blinking feature is enabled above
|
// Led pins used if blinking feature is enabled above
|
||||||
#define MY_DEFAULT_ERR_LED_PIN 16 // Error led pin
|
#define MY_DEFAULT_ERR_LED_PIN 16 // Error led pin
|
||||||
#define MY_DEFAULT_RX_LED_PIN 16 // Receive led pin
|
#define MY_DEFAULT_RX_LED_PIN 16 // Receive led pin
|
||||||
@@ -145,6 +144,3 @@ void presentation() {
|
|||||||
void loop() {
|
void loop() {
|
||||||
// Send locally attached sensors data here
|
// Send locally attached sensors data here
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
* The node also listens to MY_MQTT_TOPIC_PREFIX and sends out those messages to the radio network
|
* The node also listens to MY_MQTT_TOPIC_PREFIX and sends out those messages to the radio network
|
||||||
*
|
*
|
||||||
* LED purposes:
|
* LED purposes:
|
||||||
* - To use the feature, uncomment WITH_LEDS_BLINKING in MyConfig.h
|
* - To use the feature, uncomment any of the MY_DEFAULT_xx_LED_PINs in your sketch
|
||||||
* - RX (green) - blink fast on radio message recieved. In inclusion mode will blink fast only on presentation recieved
|
* - RX (green) - blink fast on radio message recieved. In inclusion mode will blink fast only on presentation recieved
|
||||||
* - TX (yellow) - blink fast on radio message transmitted. In inclusion mode will blink slowly
|
* - TX (yellow) - blink fast on radio message transmitted. In inclusion mode will blink slowly
|
||||||
* - ERR (red) - fast blink on error during transmission error or recieve crc error
|
* - ERR (red) - fast blink on error during transmission error or recieve crc error
|
||||||
@@ -105,11 +105,6 @@
|
|||||||
#define MY_PORT 1883
|
#define MY_PORT 1883
|
||||||
|
|
||||||
/*
|
/*
|
||||||
// Flash leds on rx/tx/err
|
|
||||||
#define MY_LEDS_BLINKING_FEATURE
|
|
||||||
// Set blinking period
|
|
||||||
#define MY_DEFAULT_LED_BLINK_PERIOD 300
|
|
||||||
|
|
||||||
// Enable inclusion mode
|
// Enable inclusion mode
|
||||||
#define MY_INCLUSION_MODE_FEATURE
|
#define MY_INCLUSION_MODE_FEATURE
|
||||||
// Enable Inclusion mode button on gateway
|
// Enable Inclusion mode button on gateway
|
||||||
@@ -119,6 +114,10 @@
|
|||||||
// Digital pin used for inclusion mode button
|
// Digital pin used for inclusion mode button
|
||||||
#define MY_INCLUSION_MODE_BUTTON_PIN 3
|
#define MY_INCLUSION_MODE_BUTTON_PIN 3
|
||||||
|
|
||||||
|
// Set blinking period
|
||||||
|
#define MY_DEFAULT_LED_BLINK_PERIOD 300
|
||||||
|
|
||||||
|
// Flash leds on rx/tx/err
|
||||||
#define MY_DEFAULT_ERR_LED_PIN 16 // Error led pin
|
#define MY_DEFAULT_ERR_LED_PIN 16 // Error led pin
|
||||||
#define MY_DEFAULT_RX_LED_PIN 16 // Receive led pin
|
#define MY_DEFAULT_RX_LED_PIN 16 // Receive led pin
|
||||||
#define MY_DEFAULT_TX_LED_PIN 16 // the PCB, on board LED
|
#define MY_DEFAULT_TX_LED_PIN 16 // the PCB, on board LED
|
||||||
@@ -138,6 +137,3 @@ void presentation() {
|
|||||||
void loop() {
|
void loop() {
|
||||||
// Send locally attech sensors data here
|
// Send locally attech sensors data here
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -118,11 +118,10 @@
|
|||||||
#define MY_INCLUSION_MODE_BUTTON_PIN 3
|
#define MY_INCLUSION_MODE_BUTTON_PIN 3
|
||||||
|
|
||||||
|
|
||||||
// Flash leds on rx/tx/err
|
|
||||||
// #define MY_LEDS_BLINKING_FEATURE
|
|
||||||
// Set blinking period
|
// Set blinking period
|
||||||
// #define MY_DEFAULT_LED_BLINK_PERIOD 300
|
// #define MY_DEFAULT_LED_BLINK_PERIOD 300
|
||||||
|
|
||||||
|
// Flash leds on rx/tx/err
|
||||||
// Led pins used if blinking feature is enabled above
|
// Led pins used if blinking feature is enabled above
|
||||||
#define MY_DEFAULT_ERR_LED_PIN 16 // Error led pin
|
#define MY_DEFAULT_ERR_LED_PIN 16 // Error led pin
|
||||||
#define MY_DEFAULT_RX_LED_PIN 16 // Receive led pin
|
#define MY_DEFAULT_RX_LED_PIN 16 // Receive led pin
|
||||||
@@ -171,7 +170,3 @@ void loop() {
|
|||||||
// Send locally attech sensors data here
|
// Send locally attech sensors data here
|
||||||
ArduinoOTA.handle();
|
ArduinoOTA.handle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,7 @@
|
|||||||
* - RX/TX/ERR leds need to be connected between +5V (anode) and digital pin 6/5/4 with resistor 270-330R in a series
|
* - RX/TX/ERR leds need to be connected between +5V (anode) and digital pin 6/5/4 with resistor 270-330R in a series
|
||||||
*
|
*
|
||||||
* LEDs (OPTIONAL):
|
* LEDs (OPTIONAL):
|
||||||
* - To use the feature, uncomment MY_LEDS_BLINKING_FEATURE in MyConfig.h
|
* - To use the feature, uncomment any of the MY_DEFAULT_xx_LED_PINs
|
||||||
* - RX (green) - blink fast on radio message recieved. In inclusion mode will blink fast only on presentation recieved
|
* - RX (green) - blink fast on radio message recieved. In inclusion mode will blink fast only on presentation recieved
|
||||||
* - TX (yellow) - blink fast on radio message transmitted. In inclusion mode will blink slowly
|
* - TX (yellow) - blink fast on radio message transmitted. In inclusion mode will blink slowly
|
||||||
* - ERR (red) - fast blink on error during transmission error or recieve crc error
|
* - ERR (red) - fast blink on error during transmission error or recieve crc error
|
||||||
@@ -56,14 +56,6 @@
|
|||||||
#define MY_BAUD_RATE 38400
|
#define MY_BAUD_RATE 38400
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Flash leds on rx/tx/err
|
|
||||||
#define MY_LEDS_BLINKING_FEATURE
|
|
||||||
// Set blinking period
|
|
||||||
#define MY_DEFAULT_LED_BLINK_PERIOD 300
|
|
||||||
|
|
||||||
// Inverses the behavior of leds
|
|
||||||
//#define MY_WITH_LEDS_BLINKING_INVERSE
|
|
||||||
|
|
||||||
// Enable inclusion mode
|
// Enable inclusion mode
|
||||||
#define MY_INCLUSION_MODE_FEATURE
|
#define MY_INCLUSION_MODE_FEATURE
|
||||||
// Enable Inclusion mode button on gateway
|
// Enable Inclusion mode button on gateway
|
||||||
@@ -77,6 +69,13 @@
|
|||||||
// Digital pin used for inclusion mode button
|
// Digital pin used for inclusion mode button
|
||||||
//#define MY_INCLUSION_MODE_BUTTON_PIN 3
|
//#define MY_INCLUSION_MODE_BUTTON_PIN 3
|
||||||
|
|
||||||
|
// Set blinking period
|
||||||
|
#define MY_DEFAULT_LED_BLINK_PERIOD 300
|
||||||
|
|
||||||
|
// Inverses the behavior of leds
|
||||||
|
//#define MY_WITH_LEDS_BLINKING_INVERSE
|
||||||
|
|
||||||
|
// Flash leds on rx/tx/err
|
||||||
// Uncomment to override default HW configurations
|
// Uncomment to override default HW configurations
|
||||||
//#define MY_DEFAULT_ERR_LED_PIN 4 // Error led pin
|
//#define MY_DEFAULT_ERR_LED_PIN 4 // Error led pin
|
||||||
//#define MY_DEFAULT_RX_LED_PIN 6 // Receive led pin
|
//#define MY_DEFAULT_RX_LED_PIN 6 // Receive led pin
|
||||||
@@ -95,8 +94,3 @@ void presentation() {
|
|||||||
void loop() {
|
void loop() {
|
||||||
// Send locally attached sensor data here
|
// Send locally attached sensor data here
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,6 @@
|
|||||||
* - RX/TX/ERR leds need to be connected between +5V (anode) and digital pin 6/5/4 with resistor 270-330R in a series
|
* - RX/TX/ERR leds need to be connected between +5V (anode) and digital pin 6/5/4 with resistor 270-330R in a series
|
||||||
*
|
*
|
||||||
* LEDs (OPTIONAL):
|
* LEDs (OPTIONAL):
|
||||||
* - To use the feature, uncomment MY_LEDS_BLINKING_FEATURE in MyConfig.h
|
|
||||||
* - RX (green) - blink fast on radio message recieved. In inclusion mode will blink fast only on presentation recieved
|
* - RX (green) - blink fast on radio message recieved. In inclusion mode will blink fast only on presentation recieved
|
||||||
* - TX (yellow) - blink fast on radio message transmitted. In inclusion mode will blink slowly
|
* - TX (yellow) - blink fast on radio message transmitted. In inclusion mode will blink slowly
|
||||||
* - ERR (red) - fast blink on error during transmission error or recieve crc error
|
* - ERR (red) - fast blink on error during transmission error or recieve crc error
|
||||||
@@ -64,10 +63,6 @@
|
|||||||
// Enable serial gateway
|
// Enable serial gateway
|
||||||
#define MY_GATEWAY_SERIAL
|
#define MY_GATEWAY_SERIAL
|
||||||
|
|
||||||
// Flash leds on rx/tx/err
|
|
||||||
#define MY_LEDS_BLINKING_FEATURE
|
|
||||||
// Set blinking period
|
|
||||||
#define MY_DEFAULT_LED_BLINK_PERIOD 300
|
|
||||||
|
|
||||||
// Enable inclusion mode
|
// Enable inclusion mode
|
||||||
#define MY_INCLUSION_MODE_FEATURE
|
#define MY_INCLUSION_MODE_FEATURE
|
||||||
@@ -78,6 +73,10 @@
|
|||||||
// Digital pin used for inclusion mode button
|
// Digital pin used for inclusion mode button
|
||||||
#define MY_INCLUSION_MODE_BUTTON_PIN 3
|
#define MY_INCLUSION_MODE_BUTTON_PIN 3
|
||||||
|
|
||||||
|
// Set blinking period
|
||||||
|
#define MY_DEFAULT_LED_BLINK_PERIOD 300
|
||||||
|
|
||||||
|
// Flash leds on rx/tx/err
|
||||||
#define MY_DEFAULT_ERR_LED_PIN 4 // Error led pin
|
#define MY_DEFAULT_ERR_LED_PIN 4 // Error led pin
|
||||||
#define MY_DEFAULT_RX_LED_PIN 5 // Receive led pin
|
#define MY_DEFAULT_RX_LED_PIN 5 // Receive led pin
|
||||||
#define MY_DEFAULT_TX_LED_PIN 6 // the PCB, on board LED
|
#define MY_DEFAULT_TX_LED_PIN 6 // the PCB, on board LED
|
||||||
@@ -95,8 +94,3 @@ void presentation() {
|
|||||||
void loop() {
|
void loop() {
|
||||||
// Send locally attached sensor data here
|
// Send locally attached sensor data here
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -90,11 +90,6 @@
|
|||||||
// Note that most of the Ardunio examples use "DEAD BEEF FEED" for the MAC address.
|
// Note that most of the Ardunio examples use "DEAD BEEF FEED" for the MAC address.
|
||||||
#define MY_MAC_ADDRESS 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
|
#define MY_MAC_ADDRESS 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
|
||||||
|
|
||||||
// Flash leds on rx/tx/err
|
|
||||||
#define MY_LEDS_BLINKING_FEATURE
|
|
||||||
// Set blinking period
|
|
||||||
#define MY_DEFAULT_LED_BLINK_PERIOD 300
|
|
||||||
|
|
||||||
// Enable inclusion mode
|
// Enable inclusion mode
|
||||||
#define MY_INCLUSION_MODE_FEATURE
|
#define MY_INCLUSION_MODE_FEATURE
|
||||||
// Enable Inclusion mode button on gateway
|
// Enable Inclusion mode button on gateway
|
||||||
@@ -104,6 +99,10 @@
|
|||||||
// Digital pin used for inclusion mode button
|
// Digital pin used for inclusion mode button
|
||||||
//#define MY_INCLUSION_MODE_BUTTON_PIN 3
|
//#define MY_INCLUSION_MODE_BUTTON_PIN 3
|
||||||
|
|
||||||
|
// Set blinking period
|
||||||
|
#define MY_DEFAULT_LED_BLINK_PERIOD 300
|
||||||
|
|
||||||
|
// Flash leds on rx/tx/err
|
||||||
// Uncomment to override default HW configurations
|
// Uncomment to override default HW configurations
|
||||||
//#define MY_DEFAULT_ERR_LED_PIN 7 // Error led pin
|
//#define MY_DEFAULT_ERR_LED_PIN 7 // Error led pin
|
||||||
//#define MY_DEFAULT_RX_LED_PIN 8 // Receive led pin
|
//#define MY_DEFAULT_RX_LED_PIN 8 // Receive led pin
|
||||||
@@ -123,4 +122,3 @@ void setup()
|
|||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -114,11 +114,6 @@
|
|||||||
#define MY_PORT 1883
|
#define MY_PORT 1883
|
||||||
|
|
||||||
/*
|
/*
|
||||||
// Flash leds on rx/tx/err
|
|
||||||
#define MY_LEDS_BLINKING_FEATURE
|
|
||||||
// Set blinking period
|
|
||||||
#define MY_DEFAULT_LED_BLINK_PERIOD 300
|
|
||||||
|
|
||||||
// Enable inclusion mode
|
// Enable inclusion mode
|
||||||
#define MY_INCLUSION_MODE_FEATURE
|
#define MY_INCLUSION_MODE_FEATURE
|
||||||
// Enable Inclusion mode button on gateway
|
// Enable Inclusion mode button on gateway
|
||||||
@@ -128,6 +123,10 @@
|
|||||||
// Digital pin used for inclusion mode button
|
// Digital pin used for inclusion mode button
|
||||||
//#define MY_INCLUSION_MODE_BUTTON_PIN 3
|
//#define MY_INCLUSION_MODE_BUTTON_PIN 3
|
||||||
|
|
||||||
|
// Set blinking period
|
||||||
|
#define MY_DEFAULT_LED_BLINK_PERIOD 300
|
||||||
|
|
||||||
|
// Flash leds on rx/tx/err
|
||||||
// Uncomment to override default HW configurations
|
// Uncomment to override default HW configurations
|
||||||
//#define MY_DEFAULT_ERR_LED_PIN 16 // Error led pin
|
//#define MY_DEFAULT_ERR_LED_PIN 16 // Error led pin
|
||||||
//#define MY_DEFAULT_RX_LED_PIN 16 // Receive led pin
|
//#define MY_DEFAULT_RX_LED_PIN 16 // Receive led pin
|
||||||
@@ -148,6 +147,3 @@ void presentation() {
|
|||||||
void loop() {
|
void loop() {
|
||||||
// Send locally attached sensors data here
|
// Send locally attached sensors data here
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,8 @@
|
|||||||
* The ArduinoGateway prints data received from sensors on the serial link.
|
* The ArduinoGateway prints data received from sensors on the serial link.
|
||||||
* The gateway accepts input on seral which will be sent out on radio network.
|
* The gateway accepts input on seral which will be sent out on radio network.
|
||||||
*
|
*
|
||||||
|
the last one is meant for the end user to break up into the various connectors used on the board.
|
||||||
|
|
||||||
* This GW code is designed for Sensebender GateWay / Arduino Zero
|
* This GW code is designed for Sensebender GateWay / Arduino Zero
|
||||||
*
|
*
|
||||||
* Wire connections (OPTIONAL):
|
* Wire connections (OPTIONAL):
|
||||||
@@ -29,14 +31,14 @@
|
|||||||
* - RX/TX/ERR leds need to be connected between +5V (anode) and digital pin 6/5/4 with resistor 270-330R in a series
|
* - RX/TX/ERR leds need to be connected between +5V (anode) and digital pin 6/5/4 with resistor 270-330R in a series
|
||||||
*
|
*
|
||||||
* LEDs (OPTIONAL):
|
* LEDs (OPTIONAL):
|
||||||
* - To use the feature, uncomment MY_LEDS_BLINKING_FEATURE in MyConfig.h
|
* - To use the feature, uncomment any of the MY_DEFAULT_xx_LED_PINs
|
||||||
* - RX (green) - blink fast on radio message recieved. In inclusion mode will blink fast only on presentation recieved
|
* - RX (green) - blink fast on radio message recieved. In inclusion mode will blink fast only on presentation recieved
|
||||||
* - TX (yellow) - blink fast on radio message transmitted. In inclusion mode will blink slowly
|
* - TX (yellow) - blink fast on radio message transmitted. In inclusion mode will blink slowly
|
||||||
* - ERR (red) - fast blink on error during transmission error or recieve crc error
|
* - ERR (red) - fast blink on error during transmission error or recieve crc error
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define SKETCH_VERSION "0.1"
|
#define SKETCH_VERSION "0.2"
|
||||||
// Enable debug prints to serial monitor
|
// Enable debug prints to serial monitor
|
||||||
#define MY_DEBUG
|
#define MY_DEBUG
|
||||||
|
|
||||||
@@ -56,14 +58,6 @@
|
|||||||
#define MY_BAUD_RATE 38400
|
#define MY_BAUD_RATE 38400
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Flash leds on rx/tx/err
|
|
||||||
#define MY_LEDS_BLINKING_FEATURE
|
|
||||||
// Set blinking period
|
|
||||||
#define MY_DEFAULT_LED_BLINK_PERIOD 300
|
|
||||||
|
|
||||||
// Inverses the behavior of leds
|
|
||||||
//#define MY_WITH_LEDS_BLINKING_INVERSE
|
|
||||||
|
|
||||||
// Enable inclusion mode
|
// Enable inclusion mode
|
||||||
#define MY_INCLUSION_MODE_FEATURE
|
#define MY_INCLUSION_MODE_FEATURE
|
||||||
// Enable Inclusion mode button on gateway
|
// Enable Inclusion mode button on gateway
|
||||||
@@ -77,6 +71,13 @@
|
|||||||
// Digital pin used for inclusion mode button
|
// Digital pin used for inclusion mode button
|
||||||
//#define MY_INCLUSION_MODE_BUTTON_PIN 3
|
//#define MY_INCLUSION_MODE_BUTTON_PIN 3
|
||||||
|
|
||||||
|
// Set blinking period
|
||||||
|
#define MY_DEFAULT_LED_BLINK_PERIOD 300
|
||||||
|
|
||||||
|
// Inverses the behavior of leds
|
||||||
|
//#define MY_WITH_LEDS_BLINKING_INVERSE
|
||||||
|
|
||||||
|
// Flash leds on rx/tx/err
|
||||||
// Uncomment to override default HW configurations
|
// Uncomment to override default HW configurations
|
||||||
//#define MY_DEFAULT_ERR_LED_PIN 4 // Error led pin
|
//#define MY_DEFAULT_ERR_LED_PIN 4 // Error led pin
|
||||||
//#define MY_DEFAULT_RX_LED_PIN 6 // Receive led pin
|
//#define MY_DEFAULT_RX_LED_PIN 6 // Receive led pin
|
||||||
@@ -125,6 +126,7 @@ void preHwInit() {
|
|||||||
delay(500);
|
delay(500);
|
||||||
} // Wait for USB to be connected, before spewing out data.
|
} // Wait for USB to be connected, before spewing out data.
|
||||||
}
|
}
|
||||||
|
digitalWrite(LED_BLUE, LOW);
|
||||||
if (Serial) {
|
if (Serial) {
|
||||||
Serial.println("Sensebender GateWay test routine");
|
Serial.println("Sensebender GateWay test routine");
|
||||||
Serial.print("Mysensors core version : ");
|
Serial.print("Mysensors core version : ");
|
||||||
@@ -147,7 +149,11 @@ void preHwInit() {
|
|||||||
digitalWrite(LED_ORANGE, HIGH);
|
digitalWrite(LED_ORANGE, HIGH);
|
||||||
tests++;
|
tests++;
|
||||||
}
|
}
|
||||||
if (tests == 3) {
|
if (testAnalog()) {
|
||||||
|
digitalWrite(LED_BLUE, HIGH);
|
||||||
|
tests++;
|
||||||
|
}
|
||||||
|
if (tests == 4) {
|
||||||
while(1) {
|
while(1) {
|
||||||
for (int i=0; i<num_of_leds; i++) {
|
for (int i=0; i<num_of_leds; i++) {
|
||||||
digitalWrite(leds[i], HIGH);
|
digitalWrite(leds[i], HIGH);
|
||||||
@@ -250,3 +256,17 @@ bool testEEProm() {
|
|||||||
SerialUSB.println("FAILED!");
|
SerialUSB.println("FAILED!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool testAnalog() {
|
||||||
|
int bat_detect = analogRead(MY_BAT_DETECT);
|
||||||
|
Serial.print("-> analog : ");
|
||||||
|
Serial.print(bat_detect);
|
||||||
|
if (bat_detect < 400 || bat_detect > 650) {
|
||||||
|
Serial.println(" Failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Serial.println(" Passed");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -52,7 +52,6 @@ MY_PARENT_NODE_IS_STATIC LITERAL1
|
|||||||
MY_OTA_FIRMWARE_FEATURE LITERAL1
|
MY_OTA_FIRMWARE_FEATURE LITERAL1
|
||||||
MY_OTA_FLASH_SS LITERAL1
|
MY_OTA_FLASH_SS LITERAL1
|
||||||
MY_OTA_FLASH_JDECID LITERAL1
|
MY_OTA_FLASH_JDECID LITERAL1
|
||||||
MY_LEDS_BLINKING_FEATURE LITERAL1
|
|
||||||
MY_WITH_LEDS_BLINKING_INVERSE LITERAL1
|
MY_WITH_LEDS_BLINKING_INVERSE LITERAL1
|
||||||
MY_DEFAULT_LED_BLINK_PERIOD LITERAL1
|
MY_DEFAULT_LED_BLINK_PERIOD LITERAL1
|
||||||
MY_WITH_LEDS_BLINKING_INVERSE LITERAL1
|
MY_WITH_LEDS_BLINKING_INVERSE LITERAL1
|
||||||
|
|||||||
+5
-1
@@ -9,7 +9,11 @@
|
|||||||
},
|
},
|
||||||
"version": "2.0.1-beta",
|
"version": "2.0.1-beta",
|
||||||
"frameworks": "arduino",
|
"frameworks": "arduino",
|
||||||
"platforms": "*",
|
"platforms": [
|
||||||
|
"atmelavr",
|
||||||
|
"atmelsam",
|
||||||
|
"espressif"
|
||||||
|
],
|
||||||
"exclude": [
|
"exclude": [
|
||||||
"tests",
|
"tests",
|
||||||
"Documentation"
|
"Documentation"
|
||||||
|
|||||||
Reference in New Issue
Block a user