From 378112db7d33a0afa2b923cc31d1fc13449b5cfa Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Tue, 16 Aug 2016 13:10:05 +0300 Subject: [PATCH 01/12] Update supported development platforms --- library.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/library.json b/library.json index 0bd3962..d55c3e4 100644 --- a/library.json +++ b/library.json @@ -9,7 +9,11 @@ }, "version": "2.0.1-beta", "frameworks": "arduino", - "platforms": "*", + "platforms": [ + "atmelavr", + "atmelsam", + "espressif" + ], "exclude": [ "tests", "Documentation" From 15b46f8023a272d6bc1c86327c44134059512772 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=B8rch?= Date: Fri, 19 Aug 2016 23:30:03 +0200 Subject: [PATCH 02/12] Fixes LED issues as discussed in #562 Removing MY_LED_BLINKING_FEATURE, as we now are using MY_DEFAULT_LED_xx_PIN defines to enable LED blinking feature. updated Gateway sketches to not refer to MY_LED_BLINKING_FEATURE any more fixes #562 --- MyConfig.h | 27 +++++----- MySensors.h | 48 ++--------------- core/MyIndication.cpp | 14 +++-- core/MyLeds.cpp | 14 ++++- core/MyLeds.h | 2 +- core/MySensorsCore.cpp | 6 +-- examples/GatewayESP8266/GatewayESP8266.ino | 48 ++++++++--------- .../GatewayESP8266MQTTClient.ino | 46 ++++++++-------- .../GatewayESP8266OTA/GatewayESP8266OTA.ino | 49 ++++++++--------- examples/GatewaySerial/GatewaySerial.ino | 48 ++++++++--------- .../GatewaySerialRS485/GatewaySerialRS485.ino | 46 +++++++--------- examples/GatewayW5100/GatewayW5100.ino | 40 +++++++------- .../GatewayW5100MQTTClient.ino | 52 +++++++++---------- .../SensebenderGatewaySerial.ino | 49 +++++++++-------- keywords.txt | 3 +- 15 files changed, 216 insertions(+), 276 deletions(-) diff --git a/MyConfig.h b/MyConfig.h index 9582a1d..845d594 100644 --- a/MyConfig.h +++ b/MyConfig.h @@ -223,25 +223,22 @@ /********************************** * Information LEDs blinking ***********************************/ -// This feature enables LEDs blinking on message receive, transmit -// or if some error occurred. This was commonly used only in gateways, -// but now can be used in any sensor node. Also the LEDs can now be -// disabled in the gateway. +// If one of the following is defined here, or in the sketch, the pin will be used for the +// corresponding led function. +// They have to be enabled here (or in your sketch). Replace x with the pin number you have the LED on. +// +// 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 blinking feature MY_LEDS_BLINKING_FEATURE +// The following setting allows you to inverse the LED blinking // When MY_WITH_LEDS_BLINKING_INVERSE is enabled LEDSs are normally turned on and switches // off when blinking //#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 @@ -431,7 +428,7 @@ /** * @def MY_RX_MESSAGE_BUFFER_FEATURE -* @brief This enabled the receiving buffer feature. +* @brief This enabled the receiving buffer feature. * * This feature is currently not supported for RFM69 and RS485, for RF24 MY_RF24_IRQ_PIN has to be defined. */ @@ -439,7 +436,7 @@ /** * @def MY_RX_MESSAGE_BUFFER_SIZE - * @brief Declare the amount of incoming messages that can be buffered. + * @brief Declare the amount of incoming messages that can be buffered. */ #ifdef MY_RX_MESSAGE_BUFFER_FEATURE #ifndef MY_RX_MESSAGE_BUFFER_SIZE diff --git a/MySensors.h b/MySensors.h index 70bc936..c0fd42a 100644 --- a/MySensors.h +++ b/MySensors.h @@ -84,17 +84,10 @@ #define MY_DEFAULT_RX_LED_PIN MY_HW_TX_LED_PIN #endif -// Not necessary to include blinking feature if no LED's are defined! -#if defined(MY_LEDS_BLINKING_FEATURE) && !defined(MY_DEFAULT_RX_LED_PIN) && !defined(MY_DEFAULT_TX_LED_PIN) && !defined(MY_ERR_LED_PIN) - #undef MY_LEDS_BLINKING_FEATURE +#if defined(MY_LEDS_BLINKING_FEATURE) +#warning MY_LEDS_BLINKING_FEATURE is not working, define MY_DEFAULT_ERR_LED_PIN, MY_DEFAULT_TX_LED_PIN or MY_DEFAULT_RX_LED_PIN in your sketch #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 * @brief Default LEDs blinking period in milliseconds. @@ -102,41 +95,8 @@ #ifndef MY_DEFAULT_LED_BLINK_PERIOD #define MY_DEFAULT_LED_BLINK_PERIOD 300 #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" #else #include "core/MyLeds.h" @@ -270,7 +230,7 @@ #endif #if defined(MY_PARENT_NODE_IS_STATIC) && (MY_PARENT_NODE_ID == AUTO) - #error Parent is static but no parent ID defined. + #error Parent is static but no parent ID defined. #endif // Make sure to disable child features when parent feature is disabled diff --git a/core/MyIndication.cpp b/core/MyIndication.cpp index 8e5e65b..6eb5b45 100644 --- a/core/MyIndication.cpp +++ b/core/MyIndication.cpp @@ -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); diff --git a/core/MyLeds.cpp b/core/MyLeds.cpp index 2974c18..33f1eed 100644 --- a/core/MyLeds.cpp +++ b/core/MyLeds.cpp @@ -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; } } - diff --git a/core/MyLeds.h b/core/MyLeds.h index 18e138d..e6f982d 100644 --- a/core/MyLeds.h +++ b/core/MyLeds.h @@ -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) diff --git a/core/MySensorsCore.cpp b/core/MySensorsCore.cpp index 8e5a5fa..e66f2d4 100644 --- a/core/MySensorsCore.cpp +++ b/core/MySensorsCore.cpp @@ -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 @@ -58,7 +58,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 } @@ -81,7 +81,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 diff --git a/examples/GatewayESP8266/GatewayESP8266.ino b/examples/GatewayESP8266/GatewayESP8266.ino index 6582a70..f4f6fd8 100644 --- a/examples/GatewayESP8266/GatewayESP8266.ino +++ b/examples/GatewayESP8266/GatewayESP8266.ino @@ -20,34 +20,34 @@ * * REVISION HISTORY * Version 1.0 - Henrik EKblad - * Contribution by a-lurker and Anticimex, + * Contribution by a-lurker and Anticimex, * Contribution by Norbert Truchsess * Contribution by Ivo Pullens (ESP8266 support) - * + * * DESCRIPTION - * The EthernetGateway sends data received from sensors to the WiFi link. + * The EthernetGateway sends data received from sensors to the WiFi link. * The gateway also accepts input on ethernet interface, which is then sent out to the radio network. * * VERA CONFIGURATION: - * Enter "ip-number:port" in the ip-field of the Arduino GW device. This will temporarily override any serial configuration for the Vera plugin. + * Enter "ip-number:port" in the ip-field of the Arduino GW device. This will temporarily override any serial configuration for the Vera plugin. * E.g. If you want to use the defualt values in this sketch enter: 192.168.178.66:5003 * * 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 * - 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 + * * See http://www.mysensors.org/build/esp8266_gateway for wiring instructions. * nRF24L01+ ESP8266 * VCC VCC - * CE GPIO4 + * CE GPIO4 * CSN/CS GPIO15 * SCK GPIO14 * MISO GPIO12 * MOSI GPIO13 * GND GND - * + * * Not all ESP8266 modules have all pins available on their external interface. * This code has been tested on an ESP-12 module. * The ESP8266 requires a certain pin configuration to download code, and another one to run code: @@ -56,10 +56,10 @@ * - Connect CH_PD via 10K resistor to VCC * - Connect GPIO2 via 10K resistor to VCC * - Connect GPIO0 via 10K resistor to VCC, and via switch to GND ('bootload switch') - * + * * Inclusion mode button: * - Connect GPIO5 via switch to GND ('inclusion switch') - * + * * Hardware SHA204 signing is currently not supported! * * Make sure to fill in your ssid and WiFi password below for ssid & pass. @@ -67,7 +67,7 @@ // Enable debug prints to serial monitor -#define MY_DEBUG +#define MY_DEBUG // Use a bit lower baudrate for serial prints on ESP8266 than default in MyConfig.h #define MY_BAUD_RATE 9600 @@ -95,14 +95,14 @@ #define MY_IP_GATEWAY_ADDRESS 192,168,178,1 #define MY_IP_SUBNET_ADDRESS 255,255,255,0 -// The port to keep open on node server mode -#define MY_PORT 5003 +// The port to keep open on node server mode +#define MY_PORT 5003 // How many clients should be able to connect to this gateway (default 1) #define MY_GATEWAY_MAX_CLIENTS 2 -// Controller ip address. Enables client mode (default is "server" mode). -// Also enable this if MY_USE_UDP is used and you want sensor data sent somewhere. +// Controller ip address. Enables client mode (default is "server" mode). +// Also enable this if MY_USE_UDP is used and you want sensor data sent somewhere. //#define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 68 // Enable inclusion mode @@ -111,16 +111,15 @@ // Enable Inclusion mode button on gateway // #define MY_INCLUSION_BUTTON_FEATURE // Set inclusion mode duration (in seconds) -#define MY_INCLUSION_MODE_DURATION 60 +#define MY_INCLUSION_MODE_DURATION 60 // Digital pin used for inclusion mode button -#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 // #define MY_DEFAULT_LED_BLINK_PERIOD 300 +// Flash leds on rx/tx/err // Led pins used if blinking feature is enabled above #define MY_DEFAULT_ERR_LED_PIN 16 // Error led pin #define MY_DEFAULT_RX_LED_PIN 16 // Receive led pin @@ -134,17 +133,14 @@ #include -void setup() { +void setup() { } void presentation() { - // Present locally attached sensors here + // Present locally attached sensors here } void loop() { // Send locally attached sensors data here } - - - diff --git a/examples/GatewayESP8266MQTTClient/GatewayESP8266MQTTClient.ino b/examples/GatewayESP8266MQTTClient/GatewayESP8266MQTTClient.ino index 7a73594..0b4933b 100644 --- a/examples/GatewayESP8266MQTTClient/GatewayESP8266MQTTClient.ino +++ b/examples/GatewayESP8266MQTTClient/GatewayESP8266MQTTClient.ino @@ -20,26 +20,26 @@ * * REVISION HISTORY * Version 1.0 - Henrik Ekblad - * + * * DESCRIPTION * The ESP8266 MQTT gateway sends radio network (or locally attached sensors) data to your MQTT broker. * The node also listens to MY_MQTT_TOPIC_PREFIX and sends out those messages to the radio network * * 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 * - 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 + * * See http://www.mysensors.org/build/esp8266_gateway for wiring instructions. * nRF24L01+ ESP8266 * VCC VCC - * CE GPIO4 + * CE GPIO4 * CSN/CS GPIO15 * SCK GPIO14 * MISO GPIO12 * MOSI GPIO13 - * + * * Not all ESP8266 modules have all pins available on their external interface. * This code has been tested on an ESP-12 module. * The ESP8266 requires a certain pin configuration to download code, and another one to run code: @@ -48,10 +48,10 @@ * - Connect CH_PD via 10K resistor to VCC * - Connect GPIO2 via 10K resistor to VCC * - Connect GPIO0 via 10K resistor to VCC, and via switch to GND ('bootload switch') - * + * * Inclusion mode button: * - Connect GPIO5 via switch to GND ('inclusion switch') - * + * * Hardware SHA204 signing is currently not supported! * * Make sure to fill in your ssid and WiFi password below for ssid & pass. @@ -59,7 +59,7 @@ // Enable debug prints to serial monitor -#define MY_DEBUG +#define MY_DEBUG // Use a bit lower baudrate for serial prints on ESP8266 than default in MyConfig.h #define MY_BAUD_RATE 9600 @@ -87,7 +87,7 @@ #define MY_ESP8266_PASSWORD "MyVerySecretPassword" // Set the hostname for the WiFi Client. This is the hostname -// it will pass to the DHCP server if not static. +// it will pass to the DHCP server if not static. // #define MY_ESP8266_HOSTNAME "mqtt-sensor-gateway" // Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP) @@ -98,27 +98,26 @@ #define MY_IP_SUBNET_ADDRESS 255,255,255,0 -// MQTT broker ip address. +// MQTT broker ip address. #define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 68 -// The MQTT broker port to to open -#define MY_PORT 1883 +// The MQTT broker port to to open +#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 #define MY_INCLUSION_MODE_FEATURE // Enable Inclusion mode button on gateway #define MY_INCLUSION_BUTTON_FEATURE // Set inclusion mode duration (in seconds) -#define MY_INCLUSION_MODE_DURATION 60 +#define MY_INCLUSION_MODE_DURATION 60 // 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_RX_LED_PIN 16 // Receive led pin #define MY_DEFAULT_TX_LED_PIN 16 // the PCB, on board LED @@ -127,17 +126,14 @@ #include #include -void setup() { +void setup() { } void presentation() { - // Present locally attached sensors here + // Present locally attached sensors here } void loop() { // Send locally attech sensors data here } - - - diff --git a/examples/GatewayESP8266OTA/GatewayESP8266OTA.ino b/examples/GatewayESP8266OTA/GatewayESP8266OTA.ino index 4e7870c..353a5f2 100644 --- a/examples/GatewayESP8266OTA/GatewayESP8266OTA.ino +++ b/examples/GatewayESP8266OTA/GatewayESP8266OTA.ino @@ -21,34 +21,34 @@ * REVISION HISTORY * Version 1.0 - Henrik EKblad * Contribution by tekka, - * Contribution by a-lurker and Anticimex, + * Contribution by a-lurker and Anticimex, * Contribution by Norbert Truchsess * Contribution by Ivo Pullens (ESP8266 support) - * + * * DESCRIPTION - * The EthernetGateway sends data received from sensors to the WiFi link. + * The EthernetGateway sends data received from sensors to the WiFi link. * The gateway also accepts input on ethernet interface, which is then sent out to the radio network. * * VERA CONFIGURATION: - * Enter "ip-number:port" in the ip-field of the Arduino GW device. This will temporarily override any serial configuration for the Vera plugin. + * Enter "ip-number:port" in the ip-field of the Arduino GW device. This will temporarily override any serial configuration for the Vera plugin. * E.g. If you want to use the defualt values in this sketch enter: 192.168.178.66:5003 * * LED purposes: * - To use the feature, uncomment WITH_LEDS_BLINKING in MyConfig.h * - 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 - * - 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 + * * See http://www.mysensors.org/build/esp8266_gateway for wiring instructions. * nRF24L01+ ESP8266 * VCC VCC - * CE GPIO4 + * CE GPIO4 * CSN/CS GPIO15 * SCK GPIO14 * MISO GPIO12 * MOSI GPIO13 * GND GND - * + * * Not all ESP8266 modules have all pins available on their external interface. * This code has been tested on an ESP-12 module. * The ESP8266 requires a certain pin configuration to download code, and another one to run code: @@ -57,10 +57,10 @@ * - Connect CH_PD via 10K resistor to VCC * - Connect GPIO2 via 10K resistor to VCC * - Connect GPIO0 via 10K resistor to VCC, and via switch to GND ('bootload switch') - * + * * Inclusion mode button: * - Connect GPIO5 via switch to GND ('inclusion switch') - * + * * Hardware SHA204 signing is currently not supported! * * Make sure to fill in your ssid and WiFi password below for ssid & pass. @@ -69,7 +69,7 @@ #include // Enable debug prints to serial monitor -#define MY_DEBUG +#define MY_DEBUG // Use a bit lower baudrate for serial prints on ESP8266 than default in MyConfig.h #define MY_BAUD_RATE 9600 @@ -97,14 +97,14 @@ #define MY_IP_GATEWAY_ADDRESS 192,168,178,1 #define MY_IP_SUBNET_ADDRESS 255,255,255,0 -// The port to keep open on node server mode -#define MY_PORT 5003 +// The port to keep open on node server mode +#define MY_PORT 5003 // How many clients should be able to connect to this gateway (default 1) #define MY_GATEWAY_MAX_CLIENTS 2 -// Controller ip address. Enables client mode (default is "server" mode). -// Also enable this if MY_USE_UDP is used and you want sensor data sent somewhere. +// Controller ip address. Enables client mode (default is "server" mode). +// Also enable this if MY_USE_UDP is used and you want sensor data sent somewhere. //#define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 68 // Enable inclusion mode @@ -113,16 +113,15 @@ // Enable Inclusion mode button on gateway // #define MY_INCLUSION_BUTTON_FEATURE // Set inclusion mode duration (in seconds) -#define MY_INCLUSION_MODE_DURATION 60 +#define MY_INCLUSION_MODE_DURATION 60 // Digital pin used for inclusion mode button -#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 // #define MY_DEFAULT_LED_BLINK_PERIOD 300 +// Flash leds on rx/tx/err // Led pins used if blinking feature is enabled above #define MY_DEFAULT_ERR_LED_PIN 16 // Error led pin #define MY_DEFAULT_RX_LED_PIN 16 // Receive led pin @@ -136,8 +135,8 @@ #include -void setup() { - +void setup() { + ArduinoOTA.onStart([]() { Serial.println("ArduinoOTA start"); }); @@ -163,7 +162,7 @@ void setup() { } void presentation() { - // Present locally attached sensors here + // Present locally attached sensors here } @@ -171,7 +170,3 @@ void loop() { // Send locally attech sensors data here ArduinoOTA.handle(); } - - - - diff --git a/examples/GatewaySerial/GatewaySerial.ino b/examples/GatewaySerial/GatewaySerial.ino index 3c0b6be..747ba9f 100644 --- a/examples/GatewaySerial/GatewaySerial.ino +++ b/examples/GatewaySerial/GatewaySerial.ino @@ -19,25 +19,25 @@ ******************************* * * DESCRIPTION - * 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 GW code is designed for Arduino Nano 328p / 16MHz * * Wire connections (OPTIONAL): - * - Inclusion button should be connected between digital pin 3 and GND + * - Inclusion button should be connected between digital pin 3 and GND * - 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): - * - 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 * - 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 + * */ // Enable debug prints to serial monitor -#define MY_DEBUG +#define MY_DEBUG // Enable and select radio type attached @@ -45,7 +45,7 @@ //#define MY_RADIO_RFM69 // Set LOW transmit power level as default, if you have an amplified NRF-module and -// power your radio separately with a good regulator you can turn up PA level. +// power your radio separately with a good regulator you can turn up PA level. #define MY_RF24_PA_LEVEL RF24_PA_LOW // Enable serial gateway @@ -56,14 +56,6 @@ #define MY_BAUD_RATE 38400 #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 #define MY_INCLUSION_MODE_FEATURE // Enable Inclusion mode button on gateway @@ -73,30 +65,32 @@ //#define MY_INCLUSION_BUTTON_EXTERNAL_PULLUP // Set inclusion mode duration (in seconds) -#define MY_INCLUSION_MODE_DURATION 60 +#define MY_INCLUSION_MODE_DURATION 60 // 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 //#define MY_DEFAULT_ERR_LED_PIN 4 // Error led pin //#define MY_DEFAULT_RX_LED_PIN 6 // Receive led pin //#define MY_DEFAULT_TX_LED_PIN 5 // the PCB, on board LED -#include +#include -void setup() { +void setup() { // Setup locally attached sensors } void presentation() { - // Present locally attached sensors + // Present locally attached sensors } -void loop() { - // Send locally attached sensor data here +void loop() { + // Send locally attached sensor data here } - - - - - diff --git a/examples/GatewaySerialRS485/GatewaySerialRS485.ino b/examples/GatewaySerialRS485/GatewaySerialRS485.ino index aabd1bc..03c8996 100644 --- a/examples/GatewaySerialRS485/GatewaySerialRS485.ino +++ b/examples/GatewaySerialRS485/GatewaySerialRS485.ino @@ -19,23 +19,22 @@ ******************************* * * DESCRIPTION - * The RS485 Gateway prints data received from sensors on the serial link. + * The RS485 Gateway prints data received from sensors on the serial link. * The gateway accepts input on seral which will be sent out on * the RS485 link. * * Wire connections (OPTIONAL): - * - Inclusion button should be connected between digital pin 3 and GND + * - Inclusion button should be connected between digital pin 3 and GND * - 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): - * - 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 * - 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 - * - * The gateway uses AltSoftSerial to handle two serial links + * - ERR (red) - fast blink on error during transmission error or recieve crc error + * + * The gateway uses AltSoftSerial to handle two serial links * on one Arduino. Use the following pins for RS485 link - * + * * Board Transmit Receive PWM Unusable * ----- -------- ------- ------------ * Teensy 3.0 & 3.1 21 20 22 @@ -46,16 +45,16 @@ * Arduino Mega 46 48 44, 45 * Wiring-S 5 6 4 * Sanguino 13 14 12 - * + * */ // Enable debug prints to serial monitor -#define MY_DEBUG +#define MY_DEBUG // Enable RS485 transport layer #define MY_RS485 -// Define this to enables DE-pin management on defined pin +// Define this to enables DE-pin management on defined pin #define MY_RS485_DE_PIN 2 // Set RS485 baud rate to use @@ -64,39 +63,34 @@ // Enable serial gateway #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 #define MY_INCLUSION_MODE_FEATURE // Enable Inclusion mode button on gateway #define MY_INCLUSION_BUTTON_FEATURE // Set inclusion mode duration (in seconds) -#define MY_INCLUSION_MODE_DURATION 60 +#define MY_INCLUSION_MODE_DURATION 60 // 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_RX_LED_PIN 5 // Receive led pin #define MY_DEFAULT_TX_LED_PIN 6 // the PCB, on board LED -#include +#include -void setup() { +void setup() { // Setup locally attached sensors } void presentation() { - // Present locally attached sensors + // Present locally attached sensors } -void loop() { - // Send locally attached sensor data here +void loop() { + // Send locally attached sensor data here } - - - - - diff --git a/examples/GatewayW5100/GatewayW5100.ino b/examples/GatewayW5100/GatewayW5100.ino index 2074842..0339c52 100644 --- a/examples/GatewayW5100/GatewayW5100.ino +++ b/examples/GatewayW5100/GatewayW5100.ino @@ -42,68 +42,67 @@ */ // Enable debug prints to serial monitor -#define MY_DEBUG +#define MY_DEBUG // Enable and select radio type attached #define MY_RADIO_NRF24 //#define MY_RADIO_RFM69 -// Enable gateway ethernet module type +// Enable gateway ethernet module type #define MY_GATEWAY_W5100 // W5100 Ethernet module SPI enable (optional if using a shield/module that manages SPI_EN signal) -//#define MY_W5100_SPI_EN 4 +//#define MY_W5100_SPI_EN 4 // Enable Soft SPI for NRF radio (note different radio wiring is required) -// The W5100 ethernet module seems to have a hard time co-operate with +// The W5100 ethernet module seems to have a hard time co-operate with // radio on the same spi bus. #if !defined(MY_W5100_SPI_EN) && !defined(ARDUINO_ARCH_SAMD) #define MY_SOFTSPI #define MY_SOFT_SPI_SCK_PIN 14 #define MY_SOFT_SPI_MISO_PIN 16 #define MY_SOFT_SPI_MOSI_PIN 15 -#endif +#endif // When W5100 is connected we have to move CE/CSN pins for NRF radio -#ifndef MY_RF24_CE_PIN +#ifndef MY_RF24_CE_PIN #define MY_RF24_CE_PIN 5 #endif -#ifndef MY_RF24_CS_PIN +#ifndef MY_RF24_CS_PIN #define MY_RF24_CS_PIN 6 #endif -// Enable to UDP +// Enable to UDP //#define MY_USE_UDP #define MY_IP_ADDRESS 192,168,178,66 // If this is disabled, DHCP is used to retrieve address // Renewal period if using DHCP //#define MY_IP_RENEWAL_INTERVAL 60000 // The port to keep open on node server mode / or port to contact in client mode -#define MY_PORT 5003 +#define MY_PORT 5003 + +// Controller ip address. Enables client mode (default is "server" mode). +// Also enable this if MY_USE_UDP is used and you want sensor data sent somewhere. +//#define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 254 -// Controller ip address. Enables client mode (default is "server" mode). -// Also enable this if MY_USE_UDP is used and you want sensor data sent somewhere. -//#define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 254 - // The MAC address can be anything you want but should be unique on your network. // Newer boards have a MAC address printed on the underside of the PCB, which you can (optionally) use. // 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 -// Flash leds on rx/tx/err -#define MY_LEDS_BLINKING_FEATURE -// Set blinking period -#define MY_DEFAULT_LED_BLINK_PERIOD 300 - // Enable inclusion mode #define MY_INCLUSION_MODE_FEATURE // Enable Inclusion mode button on gateway //#define MY_INCLUSION_BUTTON_FEATURE // Set inclusion mode duration (in seconds) -#define MY_INCLUSION_MODE_DURATION 60 +#define MY_INCLUSION_MODE_DURATION 60 // 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 //#define MY_DEFAULT_ERR_LED_PIN 7 // Error led pin //#define MY_DEFAULT_RX_LED_PIN 8 // Receive led pin @@ -123,4 +122,3 @@ void setup() void loop() { } - diff --git a/examples/GatewayW5100MQTTClient/GatewayW5100MQTTClient.ino b/examples/GatewayW5100MQTTClient/GatewayW5100MQTTClient.ino index bbcaa96..59dad45 100644 --- a/examples/GatewayW5100MQTTClient/GatewayW5100MQTTClient.ino +++ b/examples/GatewayW5100MQTTClient/GatewayW5100MQTTClient.ino @@ -20,7 +20,7 @@ * * REVISION HISTORY * Version 1.0 - Henrik Ekblad - * + * * DESCRIPTION * The W5100 MQTT gateway sends radio network (or locally attached sensors) data to your MQTT broker. * The node also listens to MY_MQTT_TOPIC_PREFIX and sends out those messages to the radio network @@ -29,17 +29,17 @@ * - To use the feature, uncomment WITH_LEDS_BLINKING in MyConfig.h * - 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 - * - 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 + * * See http://www.mysensors.org/build/esp8266_gateway for wiring instructions. * nRF24L01+ ESP8266 * VCC VCC - * CE GPIO4 + * CE GPIO4 * CSN/CS GPIO15 * SCK GPIO14 * MISO GPIO12 * MOSI GPIO13 - * + * * Not all ESP8266 modules have all pins available on their external interface. * This code has been tested on an ESP-12 module. * The ESP8266 requires a certain pin configuration to download code, and another one to run code: @@ -48,10 +48,10 @@ * - Connect CH_PD via 10K resistor to VCC * - Connect GPIO2 via 10K resistor to VCC * - Connect GPIO0 via 10K resistor to VCC, and via switch to GND ('bootload switch') - * + * * Inclusion mode button: * - Connect GPIO5 via switch to GND ('inclusion switch') - * + * * Hardware SHA204 signing is currently not supported! * * Make sure to fill in your ssid and WiFi password below for ssid & pass. @@ -59,7 +59,7 @@ // Enable debug prints to serial monitor -#define MY_DEBUG +#define MY_DEBUG // Enables and select radio type (if attached) #define MY_RADIO_NRF24 @@ -75,23 +75,23 @@ #define MY_MQTT_CLIENT_ID "mysensors-1" // W5100 Ethernet module SPI enable (optional if using a shield/module that manages SPI_EN signal) -//#define MY_W5100_SPI_EN 4 +//#define MY_W5100_SPI_EN 4 // Enable Soft SPI for NRF radio (note different radio wiring is required) -// The W5100 ethernet module seems to have a hard time co-operate with +// The W5100 ethernet module seems to have a hard time co-operate with // radio on the same spi bus. #if !defined(MY_W5100_SPI_EN) && !defined(ARDUINO_ARCH_SAMD) #define MY_SOFTSPI #define MY_SOFT_SPI_SCK_PIN 14 #define MY_SOFT_SPI_MISO_PIN 16 #define MY_SOFT_SPI_MOSI_PIN 15 -#endif +#endif // When W5100 is connected we have to move CE/CSN pins for NRF radio -#ifndef MY_RF24_CE_PIN +#ifndef MY_RF24_CE_PIN #define MY_RF24_CE_PIN 5 #endif -#ifndef MY_RF24_CS_PIN +#ifndef MY_RF24_CS_PIN #define MY_RF24_CS_PIN 6 #endif @@ -106,28 +106,27 @@ #define MY_IP_GATEWAY_ADDRESS 192,168,178,1 #define MY_IP_SUBNET_ADDRESS 255,255,255,0 -// MQTT broker ip address or url. Define one or the other. +// MQTT broker ip address or url. Define one or the other. //#define MY_CONTROLLER_URL_ADDRESS "m20.cloudmqtt.com" #define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 68 -// The MQTT broker port to to open -#define MY_PORT 1883 +// The MQTT broker port to to open +#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 #define MY_INCLUSION_MODE_FEATURE // Enable Inclusion mode button on gateway //#define MY_INCLUSION_BUTTON_FEATURE // Set inclusion mode duration (in seconds) -#define MY_INCLUSION_MODE_DURATION 60 +#define MY_INCLUSION_MODE_DURATION 60 // 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 //#define MY_DEFAULT_ERR_LED_PIN 16 // Error led pin //#define MY_DEFAULT_RX_LED_PIN 16 // Receive led pin @@ -137,17 +136,14 @@ #include #include -void setup() { +void setup() { } void presentation() { - // Present locally attached sensors here + // Present locally attached sensors here } void loop() { // Send locally attached sensors data here } - - - diff --git a/examples/SensebenderGatewaySerial/SensebenderGatewaySerial.ino b/examples/SensebenderGatewaySerial/SensebenderGatewaySerial.ino index f8443da..e0d6510 100644 --- a/examples/SensebenderGatewaySerial/SensebenderGatewaySerial.ino +++ b/examples/SensebenderGatewaySerial/SensebenderGatewaySerial.ino @@ -19,33 +19,33 @@ ******************************* * * DESCRIPTION - * 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. * * This GW code is designed for Sensebender GateWay / Arduino Zero * * Wire connections (OPTIONAL): - * - Inclusion button should be connected between digital pin 3 and GND + * - Inclusion button should be connected between digital pin 3 and GND * - 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): - * - 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 * - 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" // Enable debug prints to serial monitor -#define MY_DEBUG +#define MY_DEBUG // Enable and select radio type attached #define MY_RADIO_NRF24 //#define MY_RADIO_RFM69 // Set LOW transmit power level as default, if you have an amplified NRF-module and -// power your radio separately with a good regulator you can turn up PA level. +// power your radio separately with a good regulator you can turn up PA level. #define MY_RF24_PA_LEVEL RF24_PA_HIGH // Enable serial gateway @@ -56,14 +56,6 @@ #define MY_BAUD_RATE 38400 #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 #define MY_INCLUSION_MODE_FEATURE // Enable Inclusion mode button on gateway @@ -73,10 +65,17 @@ //#define MY_INCLUSION_BUTTON_EXTERNAL_PULLUP // Set inclusion mode duration (in seconds) -#define MY_INCLUSION_MODE_DURATION 60 +#define MY_INCLUSION_MODE_DURATION 60 // 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 //#define MY_DEFAULT_ERR_LED_PIN 4 // Error led pin //#define MY_DEFAULT_RX_LED_PIN 6 // Receive led pin @@ -93,16 +92,16 @@ Sd2Card card; static uint8_t num_of_leds = 5; static uint8_t leds[] = {LED_BLUE, LED_RED, LED_GREEN, LED_YELLOW, LED_ORANGE}; -void setup() { +void setup() { // Setup locally attached sensors } void presentation() { - // Present locally attached sensors + // Present locally attached sensors } -void loop() { - // Send locally attached sensor data here +void loop() { + // Send locally attached sensor data here } @@ -142,7 +141,7 @@ void preHwInit() { digitalWrite(LED_YELLOW, HIGH); tests++; } - + if (testEEProm()) { digitalWrite(LED_ORANGE, HIGH); tests++; @@ -155,7 +154,7 @@ void preHwInit() { digitalWrite(leds[i], LOW); } } - } + } else { while (1) { digitalWrite(LED_RED, HIGH); @@ -164,7 +163,7 @@ void preHwInit() { delay(200); } } - + } bool testSha204(){ @@ -243,7 +242,7 @@ bool testEEProm() { delay(500); eeprom_d2 = i2c_eeprom_read_byte(EEPROM_VERIFICATION_ADDRESS); if (eeprom_d1 == eeprom_d2) { - SerialUSB.println("PASSED"); + SerialUSB.println("PASSED"); i2c_eeprom_write_byte(EEPROM_VERIFICATION_ADDRESS, ~eeprom_d1); return true; } diff --git a/keywords.txt b/keywords.txt index 77a2540..b84d949 100644 --- a/keywords.txt +++ b/keywords.txt @@ -52,7 +52,6 @@ MY_PARENT_NODE_IS_STATIC LITERAL1 MY_OTA_FIRMWARE_FEATURE LITERAL1 MY_OTA_FLASH_SS LITERAL1 MY_OTA_FLASH_JDECID LITERAL1 -MY_LEDS_BLINKING_FEATURE LITERAL1 MY_WITH_LEDS_BLINKING_INVERSE LITERAL1 MY_DEFAULT_LED_BLINK_PERIOD LITERAL1 MY_WITH_LEDS_BLINKING_INVERSE LITERAL1 @@ -129,4 +128,4 @@ MY_NODE_UNLOCK_PIN LITERAL1 MY_NODE_LOCK_COUNTER_MAX LITERAL1 MY_SPIFLASH_SST25TYPE LITERAL1 MY_CRITICAL_SECTION LITERAL1 -MY_RX_MESSAGE_BUFFER_SIZE LITERAL1 \ No newline at end of file +MY_RX_MESSAGE_BUFFER_SIZE LITERAL1 From 2049bc44494c66fdc4e41f25fed314f7c62956a4 Mon Sep 17 00:00:00 2001 From: Marcelo Aquino Date: Sat, 20 Aug 2016 07:45:56 -0300 Subject: [PATCH 03/12] Set default port to 1883 when using MQTT gateway (#565) --- MyConfig.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/MyConfig.h b/MyConfig.h index 9582a1d..a186c6c 100644 --- a/MyConfig.h +++ b/MyConfig.h @@ -611,7 +611,11 @@ * @brief The Ethernet TCP/UDP port to open on controller or gateway. */ #ifndef MY_PORT -#define MY_PORT 5003 + #ifdef MY_GATEWAY_MQTT_CLIENT + #define MY_PORT 1883 + #else + #define MY_PORT 5003 + #endif #endif // Static ip address of gateway (if this is disabled, DHCP will be used) From 9304cebddf4243911395e25e5349c61765d71ad5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=B8rch?= Date: Sun, 21 Aug 2016 01:04:49 +0200 Subject: [PATCH 04/12] Change warning to error, so people are notified (#569) * Change warning to error, so people are notified * Added doxygen for dep. MY_LEDS_BLINKING_FEATURE --- MySensors.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/MySensors.h b/MySensors.h index c0fd42a..821af20 100644 --- a/MySensors.h +++ b/MySensors.h @@ -85,7 +85,9 @@ #endif #if defined(MY_LEDS_BLINKING_FEATURE) -#warning MY_LEDS_BLINKING_FEATURE is not working, define MY_DEFAULT_ERR_LED_PIN, MY_DEFAULT_TX_LED_PIN or MY_DEFAULT_RX_LED_PIN in your sketch +#error MY_LEDS_BLINKING_FEATURE is now removed from MySensors core,\ + 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 /** @@ -271,4 +273,5 @@ // This is used to enable disabled macros/definitions to be included in the documentation as well. #if DOXYGEN #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 From 48e90983ac86e8055bb6e5ad8d6173aca89ba3bb Mon Sep 17 00:00:00 2001 From: Marcelo Aquino Date: Sun, 21 Aug 2016 23:42:44 -0300 Subject: [PATCH 05/12] Add random number initialization to MyHw layer --- core/MyHwATMega328.h | 1 + core/MyHwESP8266.h | 3 ++- core/MyHwSAMD.h | 1 + core/MySigningAtsha204Soft.cpp | 2 +- 4 files changed, 5 insertions(+), 2 deletions(-) diff --git a/core/MyHwATMega328.h b/core/MyHwATMega328.h index 8d6c102..0efd911 100644 --- a/core/MyHwATMega328.h +++ b/core/MyHwATMega328.h @@ -63,6 +63,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 diff --git a/core/MyHwESP8266.h b/core/MyHwESP8266.h index ffbcb69..f021b5b 100644 --- a/core/MyHwESP8266.h +++ b/core/MyHwESP8266.h @@ -37,8 +37,9 @@ #define hwDigitalWrite(__pin, __value) (digitalWrite(__pin, __value)) #define hwInit() MY_SERIALDEVICE.begin(MY_BAUD_RATE); MY_SERIALDEVICE.setDebugOutput(true) #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); diff --git a/core/MyHwSAMD.h b/core/MyHwSAMD.h index dce2dba..6df3162 100644 --- a/core/MyHwSAMD.h +++ b/core/MyHwSAMD.h @@ -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); diff --git a/core/MySigningAtsha204Soft.cpp b/core/MySigningAtsha204Soft.cpp index 400895f..740db9d 100644 --- a/core/MySigningAtsha204Soft.cpp +++ b/core/MySigningAtsha204Soft.cpp @@ -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); From ebdaedb5145781780fa2da4fc4c2d48bb2617226 Mon Sep 17 00:00:00 2001 From: Marcelo Aquino Date: Sun, 21 Aug 2016 23:25:11 -0300 Subject: [PATCH 06/12] Add ESP8266 Serial modes SERIAL_TX_ONLY allows to use RX (GPIO3) as a general purpose input/output SERIAL_RX_ONLY allows to use TX (GPIO1) as a general purpose input/output --- MyConfig.h | 22 ++++++++++++++++++++++ core/MyHwESP8266.h | 2 +- keywords.txt | 1 + 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/MyConfig.h b/MyConfig.h index 366a676..2e1d3df 100644 --- a/MyConfig.h +++ b/MyConfig.h @@ -643,6 +643,10 @@ // If MY_CONTROLLER_IP_ADDRESS is left un-defined, gateway acts as server allowing incoming connections. //#define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 254 +/************************************** +* Node Locking +***************************************/ + /** * @defgroup MyLockgrp MyNodeLock * @ingroup internals @@ -699,8 +703,26 @@ #endif /** @}*/ // Node lock group +/********************************** +* ESP8266 Defaults +***********************************/ + +/** + * @def MY_ESP8266_SERIAL_MODE + * @brief Serial modes: SERIAL_FULL, SERIAL_RX_ONLY, SERIAL_TX_ONLY + * + * SERIAL_FULL: Default mode. + * SERIAL_TX_ONLY: allows to use RX (GPIO3) as a general purpose input/output. + * SERIAL_RX_ONLY: allows to use TX (GPIO1) as a general purpose input/output. + */ +#ifndef MY_ESP8266_SERIAL_MODE +#define MY_ESP8266_SERIAL_MODE SERIAL_FULL #endif +/** @}*/ // ESP8266 Defaults + +#endif // MyConfig_h + // Doxygen specific constructs, not included when built normally // This is used to enable disabled macros/definitions to be included in the documentation as well. #if DOXYGEN diff --git a/core/MyHwESP8266.h b/core/MyHwESP8266.h index ffbcb69..3bd6c00 100644 --- a/core/MyHwESP8266.h +++ b/core/MyHwESP8266.h @@ -35,7 +35,7 @@ // Define these as macros to save valuable space #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, SERIAL_8N1, MY_ESP8266_SERIAL_MODE, 1); MY_SERIALDEVICE.setDebugOutput(true) #define hwWatchdogReset() wdt_reset() #define hwReboot() ESP.restart(); #define hwMillis() millis() diff --git a/keywords.txt b/keywords.txt index b84d949..5d8da56 100644 --- a/keywords.txt +++ b/keywords.txt @@ -107,6 +107,7 @@ MY_GATEWAY_MAX_RECEIVE_LENGTH LITERAL1 MY_ESP8266_SSID LITERAL1 MY_ESP8266_PASSWORD LITERAL1 MY_ESP8266_HOSTNAME LITERAL1 +MY_ESP8266_SERIAL_MODE LITERAL1 MY_IP_GATEWAY_ADDRESS LITERAL1 MY_IP_SUBNET_ADDRESS LITERAL1 MY_W5100_SPI_EN LITERAL1 From a6cdec2008760ebf068b16980ea0def0c4c8ae1f Mon Sep 17 00:00:00 2001 From: tekka007 Date: Sun, 14 Aug 2016 20:05:55 +0200 Subject: [PATCH 07/12] Redesign sleep() functions - unified sleeping function _sleep(), including smartSleep - prevent sleeping if transport is not ready - add debug log messages --- MyConfig.h | 16 +++- core/MyHwATMega328.cpp | 6 +- core/MyHwESP8266.cpp | 6 +- core/MyHwSAMD.cpp | 6 +- core/MySensorsCore.cpp | 179 ++++++++++++++++++++++------------------- core/MySensorsCore.h | 120 +++++++++++++++++---------- 6 files changed, 195 insertions(+), 138 deletions(-) diff --git a/MyConfig.h b/MyConfig.h index 9582a1d..ea59ade 100644 --- a/MyConfig.h +++ b/MyConfig.h @@ -153,14 +153,22 @@ // #define MY_REPEATER_FEATURE /** - * @def MY_SMART_SLEEP_WAIT_DURATION - * @brief The wait period before going to sleep when using smartSleep-functions. +* @def MY_SLEEP_TRANSPORT_RECONNECT_TIMEOUT_MS +* @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 * potential buffered messages. */ -#ifndef MY_SMART_SLEEP_WAIT_DURATION -#define MY_SMART_SLEEP_WAIT_DURATION 500 +#ifndef MY_SMART_SLEEP_WAIT_DURATION_MS +#define MY_SMART_SLEEP_WAIT_DURATION_MS (500ul) #endif /********************************** diff --git a/core/MyHwATMega328.cpp b/core/MyHwATMega328.cpp index 100d7ed..59b9526 100644 --- a/core/MyHwATMega328.cpp +++ b/core/MyHwATMega328.cpp @@ -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(_wokeUpByInterrupt); // Clear woke-up-by-interrupt flag, so next sleeps won't return immediately. diff --git a/core/MyHwESP8266.cpp b/core/MyHwESP8266.cpp index 3c10105..1760b68 100644 --- a/core/MyHwESP8266.cpp +++ b/core/MyHwESP8266.cpp @@ -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); diff --git a/core/MyHwSAMD.cpp b/core/MyHwSAMD.cpp index 2d85501..976d4cd 100644 --- a/core/MyHwSAMD.cpp +++ b/core/MyHwSAMD.cpp @@ -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() { diff --git a/core/MySensorsCore.cpp b/core/MySensorsCore.cpp index 8e5a5fa..8fab345 100644 --- a/core/MySensorsCore.cpp +++ b/core/MySensorsCore.cpp @@ -280,12 +280,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) { @@ -444,104 +442,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 @@ -555,6 +567,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 diff --git a/core/MySensorsCore.h b/core/MySensorsCore.h index d9dafa6..f88a028 100644 --- a/core/MySensorsCore.h +++ b/core/MySensorsCore.h @@ -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 #include -#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 /** From f8c6156057ac82ad30ea3ae4677fca245bcbd6a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=B8rch?= Date: Mon, 19 Sep 2016 21:14:15 +0200 Subject: [PATCH 08/12] Updated sketch with analog check (#580) --- .../SensebenderGatewaySerial.ino | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/examples/SensebenderGatewaySerial/SensebenderGatewaySerial.ino b/examples/SensebenderGatewaySerial/SensebenderGatewaySerial.ino index e0d6510..5e9c89c 100644 --- a/examples/SensebenderGatewaySerial/SensebenderGatewaySerial.ino +++ b/examples/SensebenderGatewaySerial/SensebenderGatewaySerial.ino @@ -22,6 +22,8 @@ * 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 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 * * Wire connections (OPTIONAL): @@ -36,7 +38,7 @@ * */ -#define SKETCH_VERSION "0.1" +#define SKETCH_VERSION "0.2" // Enable debug prints to serial monitor #define MY_DEBUG @@ -124,6 +126,7 @@ void preHwInit() { delay(500); } // Wait for USB to be connected, before spewing out data. } + digitalWrite(LED_BLUE, LOW); if (Serial) { Serial.println("Sensebender GateWay test routine"); Serial.print("Mysensors core version : "); @@ -146,7 +149,11 @@ void preHwInit() { digitalWrite(LED_ORANGE, HIGH); tests++; } - if (tests == 3) { + if (testAnalog()) { + digitalWrite(LED_BLUE, HIGH); + tests++; + } + if (tests == 4) { while(1) { for (int i=0; i analog : "); + Serial.print(bat_detect); + if (bat_detect < 400 || bat_detect > 650) { + Serial.println(" Failed"); + return false; + } + Serial.println(" Passed"); + return true; +} + + From ec6b6ea2bfa6d26f556a6e125e36d6cb8e031f5c Mon Sep 17 00:00:00 2001 From: Olivier Date: Mon, 19 Sep 2016 21:31:00 +0200 Subject: [PATCH 09/12] Refactor and doxygenize EEPROM address definitions (#582) --- core/MyEepromAddresses.h | 91 ++++++++++++++++++++++++++++++---------- 1 file changed, 68 insertions(+), 23 deletions(-) diff --git a/core/MyEepromAddresses.h b/core/MyEepromAddresses.h index 3c94be3..417ffa8 100644 --- a/core/MyEepromAddresses.h +++ b/core/MyEepromAddresses.h @@ -6,7 +6,7 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * 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 + +/** @}*/ From 8ccb1ca86dada9ca9a7bbd19eda165b061e5bf15 Mon Sep 17 00:00:00 2001 From: Embedded Innovation Date: Thu, 22 Sep 2016 18:21:02 +0200 Subject: [PATCH 10/12] Fix gateway RX indication Added GW RX indication for MQTT and Serial gateway (PR #585). Only send RX indication when valid message has been received. --- core/MyGatewayTransportEthernet.cpp | 10 +++++++--- core/MyGatewayTransportMQTTClient.cpp | 1 + core/MyGatewayTransportSerial.cpp | 6 +++++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/core/MyGatewayTransportEthernet.cpp b/core/MyGatewayTransportEthernet.cpp index cef41e7..299e339 100644 --- a/core/MyGatewayTransportEthernet.cpp +++ b/core/MyGatewayTransportEthernet.cpp @@ -272,19 +272,23 @@ bool gatewayTransportAvailable() 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; } #else #if defined(MY_GATEWAY_ESP8266) diff --git a/core/MyGatewayTransportMQTTClient.cpp b/core/MyGatewayTransportMQTTClient.cpp index b6ca377..a385382 100644 --- a/core/MyGatewayTransportMQTTClient.cpp +++ b/core/MyGatewayTransportMQTTClient.cpp @@ -131,6 +131,7 @@ void incomingMQTT(char* topic, byte* payload, unsigned int length) { _MQTT_msg.set((const char*)payload); } _MQTT_available = true; + setIndication(INDICATION_GW_RX); } } i++; diff --git a/core/MyGatewayTransportSerial.cpp b/core/MyGatewayTransportSerial.cpp index bbad4b3..74a118e 100644 --- a/core/MyGatewayTransportSerial.cpp +++ b/core/MyGatewayTransportSerial.cpp @@ -58,7 +58,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: From 0c11354a2a9a0b67079b6c2723e9134923e1137a Mon Sep 17 00:00:00 2001 From: Marcelo Aquino Date: Thu, 22 Sep 2016 21:35:22 -0300 Subject: [PATCH 11/12] Fix Client Mode for Ethernet gateway If MY_GATEWAY_CLIENT_MODE or MY_CONTROLLER_URL_ADDRESS are present, set MY_GATEWAY_CLIENT_MODE. MY_USE_UDP requires that MY_GATEWAY_CLIENT_MODE is set. Add some ifdefs to filter some variables not needed in client mode. Using global variables to keep the connection to controller open therefore, no need to reconnect every time we need to send/receive something. Add the remaining code to handle incoming messages from controllers. --- MySensors.h | 12 ++-- core/MyGatewayTransportEthernet.cpp | 99 ++++++++++++++++++++++------- 2 files changed, 84 insertions(+), 27 deletions(-) diff --git a/MySensors.h b/MySensors.h index 821af20..8d5ad27 100644 --- a/MySensors.h +++ b/MySensors.h @@ -141,6 +141,13 @@ #endif // GATEWAY - TRANSPORT +#if defined(MY_CONTROLLER_IP_ADDRESS) || defined(MY_CONTROLLER_URL_ADDRESS) + #define MY_GATEWAY_CLIENT_MODE +#endif +#if defined(MY_USE_UDP) && !defined(MY_GATEWAY_CLIENT_MODE) + #error You must specify MY_CONTROLLER_IP_ADDRESS or MY_CONTROLLER_URL_ADDRESS for UDP +#endif + #if defined(MY_GATEWAY_MQTT_CLIENT) #if defined(MY_RADIO_FEATURE) // We assume that a gateway having a radio also should act as repeater @@ -148,7 +155,7 @@ #endif // GATEWAY - COMMON FUNCTIONS // We only support MQTT Client using W5100 and ESP8266 at the moment - #if !(defined(MY_CONTROLLER_URL_ADDRESS) || defined(MY_CONTROLLER_IP_ADDRESS)) + #if !defined(MY_GATEWAY_CLIENT_MODE) #error You must specify MY_CONTROLLER_IP_ADDRESS or MY_CONTROLLER_URL_ADDRESS #endif @@ -177,9 +184,6 @@ // We assume that a gateway having a radio also should act as repeater #define MY_REPEATER_FEATURE #endif - #if defined(MY_CONTROLLER_IP_ADDRESS) - #define MY_GATEWAY_CLIENT_MODE - #endif #if !defined(MY_PORT) #error You must define MY_PORT (controller or gatway port to open) #endif diff --git a/core/MyGatewayTransportEthernet.cpp b/core/MyGatewayTransportEthernet.cpp index 299e339..c27d501 100644 --- a/core/MyGatewayTransportEthernet.cpp +++ b/core/MyGatewayTransportEthernet.cpp @@ -52,17 +52,19 @@ typedef struct IPAddress _gatewayIp(MY_IP_GATEWAY_ADDRESS); IPAddress _subnetIp(MY_IP_SUBNET_ADDRESS); #endif - static bool clientsConnected[MY_GATEWAY_MAX_CLIENTS]; + #if !defined(MY_GATEWAY_CLIENT_MODE) + static bool clientsConnected[MY_GATEWAY_MAX_CLIENTS]; + #endif #endif #if defined(MY_USE_UDP) EthernetUDP _ethernetServer; -#else +#elif !defined(MY_GATEWAY_CLIENT_MODE) EthernetServer _ethernetServer(_ethernetGatewayPort); #endif -#if defined(MY_GATEWAY_ESP8266) +#if defined(MY_GATEWAY_ESP8266) && !defined(MY_GATEWAY_CLIENT_MODE) static EthernetClient clients[MY_GATEWAY_MAX_CLIENTS]; static inputBuffer inputString[MY_GATEWAY_MAX_CLIENTS]; #else @@ -137,14 +139,29 @@ 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 + client.stop(); + debug(PSTR("Eth: Failed to connect\n")); + } 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 // we have to use pointers due to the constructor of EthernetServer _ethernetServer.begin(); - #endif /* USE_UDP */ + #endif _w5100_spi_en(false); return true; } @@ -157,25 +174,37 @@ bool gatewayTransportSend(MyMessage &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(); #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)) { - #else - if (client.connected() || client.connect(_ethernetControllerIP, MY_PORT)) { - #endif - client.write(_ethernetMsg, strlen(_ethernetMsg)); - } - else { - // connecting to the server failed! - ret = false; - } + if (!client.connect(MY_CONTROLLER_URL_ADDRESS, MY_PORT)) { + #else + if (!client.connect(_ethernetControllerIP, MY_PORT)) { + #endif + // connecting to the server failed! + debug(PSTR("Eth: Failed to connect\n")); + ret = false; + } 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 { + ret = client.write(_ethernetMsg, strlen(_ethernetMsg)) > 0; + } #endif #else // Send message to connected clients @@ -188,16 +217,16 @@ bool gatewayTransportSend(MyMessage &message) } } #else - _ethernetServer.write(_ethernetMsg); + ret = _ethernetServer.write(_ethernetMsg) > 0; #endif - #endif + #endif /* MY_GATEWAY_CLIENT_MODE */ _w5100_spi_en(false); return ret; } -#if defined(MY_GATEWAY_ESP8266) +#if defined(MY_GATEWAY_ESP8266) && !defined(MY_GATEWAY_CLIENT_MODE) bool _readFromClient(uint8_t i) { while (clients[i].connected() && clients[i].available()) { char inChar = clients[i].read(); @@ -290,6 +319,30 @@ bool gatewayTransportAvailable() } 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: Failed to connect\n")); + _w5100_spi_en(false); + return false; + } 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(); + } + } + if (_readFromClient()) { + setIndication(INDICATION_GW_RX); + _w5100_spi_en(false); + return true; + } #else #if defined(MY_GATEWAY_ESP8266) // ESP8266: Go over list of clients and stop any that are no longer connected. @@ -356,7 +409,7 @@ bool gatewayTransportAvailable() } } } - #endif + #endif /* MY_GATEWAY_ESP8266 */ #endif _w5100_spi_en(false); return false; @@ -393,4 +446,4 @@ void gatewayTransportRenewIP() _w5100_spi_en(false); next_time = now + MY_IP_RENEWAL_INTERVAL; } -#endif /* IP_ADDRESS_DHCP */ +#endif From d8c45e9f07c7900632d0c788617a155faca545c9 Mon Sep 17 00:00:00 2001 From: Tom Date: Thu, 29 Sep 2016 20:02:32 +0100 Subject: [PATCH 12/12] V_Light Deprecated Change V_Light for V_Status as V_Light is deprecated as per is ttps://www.mysensors.org/download/serial_api_20 Change S_Light for S_Binary generic. --- examples/RelayActuator/RelayActuator.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/RelayActuator/RelayActuator.ino b/examples/RelayActuator/RelayActuator.ino index 7f82c71..908cb9b 100644 --- a/examples/RelayActuator/RelayActuator.ino +++ b/examples/RelayActuator/RelayActuator.ino @@ -65,7 +65,7 @@ void presentation() for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) { // Register all sensors to gw (they will be created as child devices) - present(sensor, S_LIGHT); + present(sensor, S_BINARY); } } @@ -77,7 +77,7 @@ void loop() void receive(const MyMessage &message) { // We only expect one type of message from controller. But we better check anyway. - if (message.type==V_LIGHT) { + if (message.type==V_STATUS) { // Change relay state digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF); // Store state in eeprom