diff --git a/libraries/MySensors/MyConfig.h b/libraries/MySensors/MyConfig.h index 8f4a999..3e12d2a 100644 --- a/libraries/MySensors/MyConfig.h +++ b/libraries/MySensors/MyConfig.h @@ -48,6 +48,8 @@ #define MY_BAUD_RATE 115200 #endif +// Disables over-the-air reset of node +//#define MY_DISABLE_REMOTE_RESET /********************************** * Radio selection and node config diff --git a/libraries/MySensors/MySensor.h b/libraries/MySensors/MySensor.h index c33308a..c026ef9 100644 --- a/libraries/MySensors/MySensor.h +++ b/libraries/MySensors/MySensor.h @@ -200,19 +200,10 @@ #endif +#include "core/MyCapabilities.h" #include "core/MyMessage.cpp" #include "core/MySensorCore.cpp" -extern void setup(); -// Optional sketch functions called by MySensors library -void receive(const MyMessage &message) __attribute__((weak)); -void receiveTime(unsigned long) __attribute__((weak)); -void presentation() __attribute__((weak)); -extern "C" void setup() __attribute__((weak)); -extern "C" void loop() __attribute__((weak)); -extern "C" void loop2() __attribute__((weak)); - - #include #if defined(MY_GATEWAY_ESP8266) diff --git a/libraries/MySensors/core/MyGatewayTransportMQTTClient.cpp b/libraries/MySensors/core/MyGatewayTransportMQTTClient.cpp index 6575533..039eb7c 100644 --- a/libraries/MySensors/core/MyGatewayTransportMQTTClient.cpp +++ b/libraries/MySensors/core/MyGatewayTransportMQTTClient.cpp @@ -71,7 +71,7 @@ void incomingMQTT(char* topic, byte* payload, switch (i) { case 0: { // Topic prefix - if (strcmp_P(str, MY_MQTT_SUBSCRIBE_TOPIC_PREFIX) != 0) { + if (strcmp(str, MY_MQTT_SUBSCRIBE_TOPIC_PREFIX) != 0) { // Message not for us or malformed! return; } diff --git a/libraries/MySensors/core/MyMainDefault.cpp b/libraries/MySensors/core/MyMainDefault.cpp index f4f0ee8..467302d 100644 --- a/libraries/MySensors/core/MyMainDefault.cpp +++ b/libraries/MySensors/core/MyMainDefault.cpp @@ -1,11 +1,11 @@ // Initialize library and handle sketch functions like we want to + int main(void) { init(); #if defined(USBCON) USBDevice.attach(); #endif _begin(); // Startup MySensors library - if (setup) setup(); // Call sketch setup for(;;) { _process(); // Process incoming data diff --git a/libraries/MySensors/core/MyMainESP8266.cpp b/libraries/MySensors/core/MyMainESP8266.cpp index 158ca74..98470eb 100644 --- a/libraries/MySensors/core/MyMainESP8266.cpp +++ b/libraries/MySensors/core/MyMainESP8266.cpp @@ -83,7 +83,6 @@ static void loop_wrapper() { static bool setup_done = false; if(!setup_done) { _begin(); // Startup MySensors library - setup(); setup_done = true; } preloop_update_frequency(); diff --git a/libraries/MySensors/core/MySensorCore.cpp b/libraries/MySensors/core/MySensorCore.cpp index 202d1c8..a68d296 100644 --- a/libraries/MySensors/core/MySensorCore.cpp +++ b/libraries/MySensors/core/MySensorCore.cpp @@ -64,7 +64,7 @@ void _begin() { hwInit(); #endif - debug(PSTR("Starting " MY_NODE_TYPE " (" LIBRARY_VERSION ")\n")); + debug(PSTR("Starting " MY_NODE_TYPE " (" MY_CAPABILIIES ", " LIBRARY_VERSION ")\n")); #if defined(MY_RADIO_FEATURE) _failedTransmissions = 0; @@ -157,6 +157,11 @@ void _begin() { } #endif + // Call sketch setup + if (setup) + setup(); + + #if defined(MY_RADIO_FEATURE) transportPresentNode(); #endif @@ -235,26 +240,31 @@ void _processInternalMessages() { bool isMetric; uint8_t type = _msg.type; - if (type == I_REBOOT) { - // Requires MySensors or other bootloader with watchdogs enabled - hwReboot(); - } else if (type == I_CONFIG) { + #if !defined(MY_DISABLE_REMOTE_RESET) + if (type == I_REBOOT) { + // Requires MySensors or other bootloader with watchdogs enabled + hwReboot(); + } else + #endif + if (type == I_CONFIG) { // Pick up configuration from controller (currently only metric/imperial) // and store it in eeprom if changed if (_msg.getString() == NULL) { - isMetric = true; - } else { - isMetric = _msg.getString()[0] == 'M' ; - } + isMetric = true; + } else { + isMetric = _msg.getString()[0] == 'M'; + } _cc.isMetric = isMetric; hwWriteConfig(EEPROM_CONTROLLER_CONFIG_ADDRESS, isMetric); } else if (type == I_PRESENTATION) { - // Re-send node presentation to controller - #if defined(MY_RADIO_FEATURE) - transportPresentNode(); - #endif - if (presentation) - presentation(); + if (!mGetAck(_msg)) { + // Re-send node presentation to controller + #if defined(MY_RADIO_FEATURE) + transportPresentNode(); + #endif + if (presentation) + presentation(); + } } else if (type == I_HEARTBEAT) { if (!mGetAck(_msg)) { // Send heartbeat ack message back to sender (with the same payload) @@ -267,7 +277,8 @@ void _processInternalMessages() { } } else if (type == I_TIME && receiveTime) { // Deliver time to callback - receiveTime(_msg.getULong()); + if (receiveTime) + receiveTime(_msg.getULong()); } #if defined(MY_REPEATER_FEATURE) if (type == I_CHILDREN && _msg.getString()[0] == 'C') { diff --git a/libraries/MySensors/core/MySensorCore.h b/libraries/MySensors/core/MySensorCore.h index 30edd42..5a3ade6 100644 --- a/libraries/MySensors/core/MySensorCore.h +++ b/libraries/MySensors/core/MySensorCore.h @@ -229,6 +229,9 @@ extern MyMessage _msgTmp; // Buffer for temporary messages (acks and nonces amo void receive(const MyMessage &message) __attribute__((weak)); void receiveTime(unsigned long) __attribute__((weak)); void presentation() __attribute__((weak)); +void setup() __attribute__((weak)); +void loop() __attribute__((weak)); + // Inline function and macros static inline MyMessage& build(MyMessage &msg, uint8_t sender, uint8_t destination, uint8_t sensor, uint8_t command, uint8_t type, bool enableAck) { diff --git a/libraries/MySensors/examples/RFIDLockSensor/RFIDLockSensor.ino b/libraries/MySensors/examples/RFIDLockSensor/RFIDLockSensor.ino index b074fdc..554a6ba 100644 --- a/libraries/MySensors/examples/RFIDLockSensor/RFIDLockSensor.ino +++ b/libraries/MySensors/examples/RFIDLockSensor/RFIDLockSensor.ino @@ -135,7 +135,7 @@ void loop() { boolean valid = false; // Compare this key to the valid once registered here in sketch for (int i=0;i