From 6a36350a1ba8a05c5d85369c09a282395d915971 Mon Sep 17 00:00:00 2001 From: Lukasz Date: Sat, 21 Aug 2021 14:06:46 +0200 Subject: [PATCH 1/5] experiments --- MyConfig.h | 4 +- MySensors.h | 2 +- core/MyGatewayTransport.cpp | 1 + core/MyGatewayTransport.h | 2 + core/MyGatewayTransportEthernet.cpp | 56 ++++++++++++++++++++++++- core/MySensorsCore.cpp | 64 +++++++++++++++++++++-------- keywords.txt | 1 + 7 files changed, 109 insertions(+), 21 deletions(-) diff --git a/MyConfig.h b/MyConfig.h index c519f2745..f8c0f1707 100755 --- a/MyConfig.h +++ b/MyConfig.h @@ -1441,6 +1441,7 @@ //#define MY_GATEWAY_W5100 //#define MY_GATEWAY_ENC28J60 //#define MY_GATEWAY_ESP8266 +//#define MY_GATEWAY_BRIDGE //#define MY_GATEWAY_ESP32 //#define MY_GATEWAY_LINUX //#define MY_GATEWAY_TINYGSM @@ -2217,7 +2218,7 @@ * MY_IS_GATEWAY is true when @ref MY_GATEWAY_FEATURE is set. * MY_NODE_TYPE contain a string describing the class of sketch/node (gateway/repeater/node). */ -#if defined(MY_GATEWAY_SERIAL) || defined(MY_GATEWAY_W5100) || defined(MY_GATEWAY_ENC28J60) || defined(MY_GATEWAY_ESP8266) || defined(MY_GATEWAY_ESP32)|| defined(MY_GATEWAY_LINUX) || defined(MY_GATEWAY_MQTT_CLIENT) || defined(MY_GATEWAY_TINYGSM) +#if defined(MY_GATEWAY_SERIAL) || defined(MY_GATEWAY_W5100) || defined(MY_GATEWAY_ENC28J60) || defined(MY_GATEWAY_ESP8266) || defined(MY_GATEWAY_BRIDGE) || defined(MY_GATEWAY_ESP32)|| defined(MY_GATEWAY_LINUX) || defined(MY_GATEWAY_MQTT_CLIENT) || defined(MY_GATEWAY_TINYGSM) #define MY_GATEWAY_FEATURE #define MY_IS_GATEWAY (true) #define MY_NODE_TYPE "GW" @@ -2391,6 +2392,7 @@ #define MY_INCLUSION_BUTTON_EXTERNAL_PULLUP #define MY_INCLUSION_LED_PIN #define MY_GATEWAY_W5100 +#define MY_GATEWAY_BRIDGE #define MY_GATEWAY_ENC28J60 #define MY_GATEWAY_ESP8266 #define MY_GATEWAY_ESP32 diff --git a/MySensors.h b/MySensors.h index f7d109a72..1dd81a117 100644 --- a/MySensors.h +++ b/MySensors.h @@ -230,7 +230,7 @@ MY_DEFAULT_RX_LED_PIN in your sketch instead to enable LEDs #define MY_REPEATER_FEATURE #endif -#if defined(MY_GATEWAY_ESP8266) || defined(MY_GATEWAY_ESP32) +#if defined(MY_GATEWAY_ESP8266) || defined(MY_GATEWAY_ESP32) || defined(MY_GATEWAY_BRIDGE) // GATEWAY - ESP8266 / ESP32 #include "core/MyGatewayTransportEthernet.cpp" #elif defined(MY_GATEWAY_LINUX) diff --git a/core/MyGatewayTransport.cpp b/core/MyGatewayTransport.cpp index 37aa71328..51aadade0 100644 --- a/core/MyGatewayTransport.cpp +++ b/core/MyGatewayTransport.cpp @@ -27,6 +27,7 @@ extern MyMessage _msgTmp; inline void gatewayTransportProcess(void) { + //Serial.print("gatewayTransportProcess entered\n"); if (gatewayTransportAvailable()) { _msg = gatewayTransportReceive(); if (_msg.getDestination() == GATEWAY_ADDRESS) { diff --git a/core/MyGatewayTransport.h b/core/MyGatewayTransport.h index cfb34b48a..4b7ec1a0c 100644 --- a/core/MyGatewayTransport.h +++ b/core/MyGatewayTransport.h @@ -96,6 +96,8 @@ void gatewayTransportProcess(void); */ bool gatewayTransportInit(void); +void PrintLF(void); + /** * @brief Send message to controller * @param message to send diff --git a/core/MyGatewayTransportEthernet.cpp b/core/MyGatewayTransportEthernet.cpp index fb148687d..8af9f8fdc 100644 --- a/core/MyGatewayTransportEthernet.cpp +++ b/core/MyGatewayTransportEthernet.cpp @@ -95,12 +95,20 @@ typedef struct { #define EthernetUDP WiFiUDP #endif +#if defined(MY_GATEWAY_BRIDGE) +#define EthernetServer BridgeServer +#define EthernetClient BridgeClient +#define EthernetUDP BridgeUDP +#endif + #if defined(MY_GATEWAY_CLIENT_MODE) #if defined(MY_USE_UDP) EthernetUDP _ethernetServer; #endif /* End of MY_USE_UDP */ #elif defined(MY_GATEWAY_LINUX) /* Elif part of MY_GATEWAY_CLIENT_MODE */ EthernetServer _ethernetServer(_ethernetGatewayPort, MY_GATEWAY_MAX_CLIENTS); +#elif defined(MY_GATEWAY_BRIDGE) /* Elif part of MY_GATEWAY_BRIDGE */ +EthernetServer _ethernetServer; // Bridge server port is hardcoded as: 5555 #else /* Else part of MY_GATEWAY_CLIENT_MODE */ EthernetServer _ethernetServer(_ethernetGatewayPort); #endif /* End of MY_GATEWAY_CLIENT_MODE */ @@ -116,6 +124,9 @@ static EthernetClient client = EthernetClient(); static EthernetClient clients[MY_GATEWAY_MAX_CLIENTS]; static bool clientsConnected[MY_GATEWAY_MAX_CLIENTS]; static inputBuffer inputString[MY_GATEWAY_MAX_CLIENTS]; +#elif defined (MY_GATEWAY_BRIDGE) +static EthernetClient client = EthernetClient(); +static inputBuffer inputString; #else /* Else part of MY_GATEWAY_CLIENT_MODE */ static EthernetClient client = EthernetClient(); static inputBuffer inputString; @@ -156,8 +167,20 @@ void gatewayTransportRenewIP(void) } #endif +static bool bBridge = false; +static bool bBridgeListen = false; + +void PrintLF() +{ + GATEWAY_DEBUG(PSTR("BRIDGE: %d\n"), bBridge); + GATEWAY_DEBUG(PSTR("BRIDGE LISTEN: %d\n"), bBridgeListen); +} + bool gatewayTransportInit(void) { + + GATEWAY_DEBUG("gatewayTransportInit\n"); + Serial.print("LF# gatewayTransportInit\n"); _w5100_spi_en(true); #if defined(MY_GATEWAY_ESP8266) || defined(MY_GATEWAY_ESP32) @@ -179,6 +202,13 @@ bool gatewayTransportInit(void) GATEWAY_DEBUG(PSTR("GWT:TIN:IP: %s\n"), WiFi.localIP().toString().c_str()); #elif defined(MY_GATEWAY_LINUX) // Nothing to do here +#elif defined(MY_GATEWAY_BRIDGE) + GATEWAY_DEBUG("Init Bridge\n"); + pinMode(13, OUTPUT); + digitalWrite(13, LOW); + Bridge.begin(); + digitalWrite(13, HIGH); + bBridge = true; #else #if defined(MY_IP_GATEWAY_ADDRESS) && defined(MY_IP_SUBNET_ADDRESS) // DNS server set to gateway ip @@ -200,7 +230,7 @@ bool gatewayTransportInit(void) delay(1000); #endif /* MY_GATEWAY_ESP8266 / MY_GATEWAY_ESP32 */ -#if defined(MY_GATEWAY_CLIENT_MODE) +#if defined(MY_GATEWAY_CLIENT_MODE) // LF# for Bridge? #if defined(MY_USE_UDP) _ethernetServer.begin(_ethernetGatewayPort); #else /* Else part of MY_USE_UDP */ @@ -227,7 +257,13 @@ bool gatewayTransportInit(void) _ethernetServer.begin(_ethernetGatewayIP); #else // we have to use pointers due to the constructor of EthernetServer +#if defined (MY_GATEWAY_BRIDGE) + bBridgeListen = true; + _ethernetServer.noListenOnLocalhost(); + Serial.print("LF# MY_GATEWAY_BRIDGE noListenOnLocalhost\n"); +#endif _ethernetServer.begin(); + Serial.print("LF# MY_GATEWAY_BRIDGE begin\n"); #endif /* End of MY_GATEWAY_LINUX && MY_IP_ADDRESS */ #endif /* End of MY_GATEWAY_CLIENT_MODE */ @@ -359,6 +395,8 @@ bool _readFromClient(void) bool gatewayTransportAvailable(void) { + GATEWAY_DEBUG(PSTR("gatewayTransportAvailable ethernet\n")); + Serial.print("gatewayTransportAvailable ethernet\n"); _w5100_spi_en(true); #if !defined(MY_IP_ADDRESS) && defined(MY_GATEWAY_W5100) // renew IP address using DHCP @@ -444,12 +482,18 @@ bool gatewayTransportAvailable(void) return true; } } -#else /* Else part of MY_GATEWAY_ESP8266 || MY_GATEWAY_LINUX */ +#else /* Else part of MY_GATEWAY_ESP8266 || MY_GATEWAY_LINUX || MY_GATEWAY_BRIDGE */ // W5100/ENC module does not have hasClient-method. We can only serve one client at the time. +#if defined (MY_GATEWAY_BRIDGE) + //Serial.print("gatewayTransportAvailable MY_GATEWAY_BRIDGE accept\n"); + EthernetClient newclient = _ethernetServer.accept(); +#else EthernetClient newclient = _ethernetServer.available(); +#endif // if a new client connects make sure to dispose any previous existing sockets if (newclient) { if (client != newclient) { + Serial.print("NEW CLIENT!!!"); client.stop(); client = newclient; GATEWAY_DEBUG(PSTR("GWT:TSA:ETH OK\n")); @@ -459,6 +503,10 @@ bool gatewayTransportAvailable(void) presentNode(); } } + else + { + //Serial.print("gatewayTransportAvailable MY_GATEWAY_BRIDGE NEW client null\n"); + } if (client) { if (!client.connected()) { GATEWAY_DEBUG(PSTR("!GWT:TSA:ETH FAIL\n")); @@ -471,6 +519,10 @@ bool gatewayTransportAvailable(void) } } } + else + { + //Serial.print("gatewayTransportAvailable MY_GATEWAY_BRIDGE client null\n"); + } #endif /* End of MY_GATEWAY_ESP8266 || MY_GATEWAY_LINUX */ #endif /* End of MY_GATEWAY_CLIENT_MODE */ _w5100_spi_en(false); diff --git a/core/MySensorsCore.cpp b/core/MySensorsCore.cpp index 6e4b79ac7..64022e9f2 100644 --- a/core/MySensorsCore.cpp +++ b/core/MySensorsCore.cpp @@ -56,22 +56,26 @@ void _callbackTransportReady(void) void _process(void) { + //CORE_DEBUG(PSTR("_process 0\n")); #if defined(MY_DEBUG_VERBOSE_CORE) if (processLock) { CORE_DEBUG(PSTR("!MCO:PRO:RC=%" PRIu8 "\n"), processLock); // recursive call detected } processLock++; + //CORE_DEBUG(PSTR("_process 1\n")); #endif doYield(); - + //CORE_DEBUG(PSTR("_process 2\n")); #if defined(MY_INCLUSION_MODE_FEATURE) inclusionProcess(); #endif #if defined(MY_GATEWAY_FEATURE) + //CORE_DEBUG(PSTR("_process 3\n")); gatewayTransportProcess(); + //CORE_DEBUG(PSTR("_process 4\n")); #endif - + //CORE_DEBUG(PSTR("_process 5\n")); #if defined(MY_SENSOR_NETWORK) transportProcess(); #endif @@ -83,10 +87,12 @@ void _process(void) #if defined(MY_DEBUG_VERBOSE_CORE) processLock--; #endif + //CORE_DEBUG(PSTR("_process --\n")); } void _infiniteLoop(void) { + CORE_DEBUG(PSTR("_infiniteLoop\n")); #if defined(__linux__) exit(1); #else @@ -98,6 +104,7 @@ void _infiniteLoop(void) void _begin(void) { + CORE_DEBUG(PSTR("_begin LF#0")); #if defined(MY_CORE_ONLY) // initialize HW and run setup if present (void)hwInit(); @@ -121,23 +128,23 @@ void _begin(void) #if defined(F_CPU) CORE_DEBUG(PSTR("MCO:BGN:INIT " MY_NODE_TYPE ",CP=" MY_CAPABILITIES ",FQ=%" PRIu16 ",REL=%" - PRIu8 ",VER=" - MYSENSORS_LIBRARY_VERSION "\n"), (uint16_t)(F_CPU/1000000UL), - MYSENSORS_LIBRARY_VERSION_PRERELEASE_NUMBER); + PRIu8 ",VER=" + MYSENSORS_LIBRARY_VERSION "\n"), (uint16_t)(F_CPU / 1000000UL), + MYSENSORS_LIBRARY_VERSION_PRERELEASE_NUMBER); #else CORE_DEBUG(PSTR("MCO:BGN:INIT " MY_NODE_TYPE ",CP=" MY_CAPABILITIES ",FQ=NA,REL=%" - PRIu8 ",VER=" - MYSENSORS_LIBRARY_VERSION "\n"), MYSENSORS_LIBRARY_VERSION_PRERELEASE_NUMBER); + PRIu8 ",VER=" + MYSENSORS_LIBRARY_VERSION "\n"), MYSENSORS_LIBRARY_VERSION_PRERELEASE_NUMBER); #endif if (!hwInitResult) { CORE_DEBUG(PSTR("!MCO:BGN:HW ERR\n")); setIndication(INDICATION_ERR_HW_INIT); _infiniteLoop(); } - + CORE_DEBUG(PSTR("LOLOLOL 1\n")); // set defaults _coreConfig.presentationSent = false; - + CORE_DEBUG(PSTR("LOLOLOL\n")); // Call sketch before() (if defined) if (before) { CORE_DEBUG(PSTR("MCO:BGN:BFR\n")); // before callback @@ -147,13 +154,13 @@ void _begin(void) #if defined(MY_DEFAULT_TX_LED_PIN) || defined(MY_DEFAULT_RX_LED_PIN) || defined(MY_DEFAULT_ERR_LED_PIN) ledsInit(); #endif - + CORE_DEBUG(PSTR("LOLOLOL 2\n")); signerInit(); - + CORE_DEBUG(PSTR("LOLOLOL 3\n")); // Read latest received controller configuration from EEPROM // Note: _coreConfig.isMetric is bool, hence empty EEPROM (=0xFF) evaluates to true (default) - hwReadConfigBlock((void *)&_coreConfig.controllerConfig, (void *)EEPROM_CONTROLLER_CONFIG_ADDRESS, - sizeof(controllerConfig_t)); + hwReadConfigBlock((void*)&_coreConfig.controllerConfig, (void*)EEPROM_CONTROLLER_CONFIG_ADDRESS, + sizeof(controllerConfig_t)); #if defined(MY_OTA_FIRMWARE_FEATURE) // Read firmware config from EEPROM, i.e. type, version, CRC, blocks @@ -172,12 +179,14 @@ void _begin(void) #endif _checkNodeLock(); - + CORE_DEBUG(PSTR("LOLOLOL 4\n")); #if defined(MY_GATEWAY_FEATURE) + CORE_DEBUG(PSTR("MCO:BGN:INIT YES MY gateway\n")); #if defined(MY_INCLUSION_BUTTON_FEATURE) inclusionInit(); #endif - + bool initialisedGateway = false; + CORE_DEBUG(PSTR("LOLOLOL 5\n")); // initialise the transport driver if (!gatewayTransportInit()) { setIndication(INDICATION_ERR_INIT_GWTRANSPORT); @@ -185,8 +194,14 @@ void _begin(void) // Nothing more we can do _infiniteLoop(); } + else + { + initialisedGateway = true; + } +#else + CORE_DEBUG(PSTR("MCO:BGN:INIT No MY gateway\n")); #endif - +CORE_DEBUG(PSTR("LOLOLOL 6\n")); // Call sketch setup() (if defined) if (setup) { CORE_DEBUG(PSTR("MCO:BGN:STP\n")); // setup callback @@ -198,10 +213,21 @@ void _begin(void) #else // no sensor network defined, call presentation & registration _callbackTransportReady(); - CORE_DEBUG(PSTR("MCO:BGN:INIT OK,TSP=NA\n")); + CORE_DEBUG(PSTR("LOLOLOL 7\n")); + CORE_DEBUG(PSTR("MCO:BGN:INIT OK,TSP=NA LF#2\n")); + if (initialisedGateway) + { + CORE_DEBUG(PSTR("initialisedGateway O!\n")); + PrintLF(); + } + else + { + CORE_DEBUG(PSTR("NOT initialisedGateway -1!\n")); + } #endif // reset wdt before handing over to loop hwWatchdogReset(); + CORE_DEBUG(PSTR("after hwWatchdogReset\n")); } @@ -563,6 +589,7 @@ void wait(const uint32_t waitingMS) #endif const uint32_t enteringMS = hwMillis(); while (hwMillis() - enteringMS < waitingMS) { + CORE_DEBUG(PSTR("Pre process 1")); _process(); } #if defined(MY_DEBUG_VERBOSE_CORE) @@ -584,6 +611,7 @@ bool wait(const uint32_t waitingMS, const mysensors_command_t cmd) _msg.setCommand(C_INVALID_7); bool expectedResponse = false; while ((hwMillis() - enteringMS < waitingMS) && !expectedResponse) { + CORE_DEBUG(PSTR("Pre process 2")); _process(); expectedResponse = (_msg.getCommand() == cmd); } @@ -607,6 +635,7 @@ bool wait(const uint32_t waitingMS, const mysensors_command_t cmd, const uint8_t _msg.setCommand(C_INVALID_7); bool expectedResponse = false; while ( (hwMillis() - enteringMS < waitingMS) && !expectedResponse ) { + CORE_DEBUG(PSTR("Pre process 3")); _process(); expectedResponse = (_msg.getCommand() == cmd && _msg.getType() == msgType); } @@ -661,6 +690,7 @@ int8_t _sleep(const uint32_t sleepingMS, const bool smartSleep, const uint8_t in uint32_t sleepDeltaMS = 0; while (!isTransportReady() && (sleepDeltaMS < sleepingTimeMS) && (sleepDeltaMS < MY_SLEEP_TRANSPORT_RECONNECT_TIMEOUT_MS)) { + CORE_DEBUG(PSTR("Pre process 4")); _process(); sleepDeltaMS = hwMillis() - sleepEnterMS; } diff --git a/keywords.txt b/keywords.txt index 70f5885e2..bf84e964a 100755 --- a/keywords.txt +++ b/keywords.txt @@ -250,6 +250,7 @@ MY_GATEWAY_CLIENT_MODE LITERAL1 MY_GATEWAY_ENC28J60 LITERAL1 MY_GATEWAY_ESP32 LITERAL1 MY_GATEWAY_ESP8266 LITERAL1 +MY_GATEWAY_BRIDGE LITERAL1 MY_GATEWAY_MQTT_CLIENT LITERAL1 MY_GATEWAY_SERIAL LITERAL1 MY_GATEWAY_W5100 LITERAL1 From f28d56b1949b9f9b20b51417195689acad1bdc86 Mon Sep 17 00:00:00 2001 From: Lukasz Date: Sun, 22 Aug 2021 13:36:08 +0200 Subject: [PATCH 2/5] working handshake --- core/MyGatewayTransportEthernet.cpp | 30 ++++++++++++++++++----------- core/MySensorsCore.cpp | 4 +++- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/core/MyGatewayTransportEthernet.cpp b/core/MyGatewayTransportEthernet.cpp index 8af9f8fdc..55900361a 100644 --- a/core/MyGatewayTransportEthernet.cpp +++ b/core/MyGatewayTransportEthernet.cpp @@ -108,7 +108,7 @@ EthernetUDP _ethernetServer; #elif defined(MY_GATEWAY_LINUX) /* Elif part of MY_GATEWAY_CLIENT_MODE */ EthernetServer _ethernetServer(_ethernetGatewayPort, MY_GATEWAY_MAX_CLIENTS); #elif defined(MY_GATEWAY_BRIDGE) /* Elif part of MY_GATEWAY_BRIDGE */ -EthernetServer _ethernetServer; // Bridge server port is hardcoded as: 5555 +EthernetServer _ethernetServer = EthernetServer(_ethernetGatewayPort); #else /* Else part of MY_GATEWAY_CLIENT_MODE */ EthernetServer _ethernetServer(_ethernetGatewayPort); #endif /* End of MY_GATEWAY_CLIENT_MODE */ @@ -272,11 +272,13 @@ bool gatewayTransportInit(void) } // cppcheck-suppress constParameter -bool gatewayTransportSend(MyMessage &message) +bool gatewayTransportSend(MyMessage& message) { + Serial.print("LF# gatewayTransportSend\n"); int nbytes = 0; - char *_ethernetMessage = protocolMyMessage2Serial(message); - + char* _ethernetMessage = protocolMyMessage2Serial(message); + Serial.print(_ethernetMessage); + Serial.print("\n"); setIndication(INDICATION_GW_TX); _w5100_spi_en(true); @@ -287,7 +289,7 @@ bool gatewayTransportSend(MyMessage &message) #else _ethernetServer.beginPacket(_ethernetControllerIP, MY_PORT); #endif /* End of MY_CONTROLLER_URL_ADDRESS */ - _ethernetServer.write((uint8_t *)_ethernetMessage, strlen(_ethernetMessage)); + _ethernetServer.write((uint8_t*)_ethernetMessage, strlen(_ethernetMessage)); // returns 1 if the packet was sent successfully nbytes = _ethernetServer.endPacket(); #else /* Else part of MY_USE_UDP */ @@ -303,23 +305,29 @@ bool gatewayTransportSend(MyMessage &message) gatewayTransportSend(buildGw(_msgTmp, I_GATEWAY_READY).set(MSG_GW_STARTUP_COMPLETE)); _w5100_spi_en(true); presentNode(); - } else { + } + else { // connecting to the server failed! GATEWAY_DEBUG(PSTR("!GWT:TPS:ETH FAIL\n")); _w5100_spi_en(false); return false; } - } - nbytes = client.write((const uint8_t *)_ethernetMessage, strlen(_ethernetMessage)); + } + nbytes = client.write((const uint8_t*)_ethernetMessage, strlen(_ethernetMessage)); #endif /* End of MY_USE_UDP */ #else /* Else part of MY_GATEWAY_CLIENT_MODE */ // Send message to connected clients #if defined(MY_GATEWAY_ESP8266) || defined(MY_GATEWAY_ESP32) for (uint8_t i = 0; i < ARRAY_SIZE(clients); i++) { if (clients[i] && clients[i].connected()) { - nbytes += clients[i].write((uint8_t *)_ethernetMessage, strlen(_ethernetMessage)); + nbytes += clients[i].write((uint8_t*)_ethernetMessage, strlen(_ethernetMessage)); } } +#elif defined(MY_GATEWAY_BRIDGE) + if (client && client.connected()) + { + nbytes += client.write((uint8_t*)_ethernetMessage, strlen(_ethernetMessage)); + } #else /* Else part of MY_GATEWAY_ESPxx*/ nbytes = _ethernetServer.write(_ethernetMessage); #endif /* End of MY_GATEWAY_ESPxx */ @@ -395,8 +403,8 @@ bool _readFromClient(void) bool gatewayTransportAvailable(void) { - GATEWAY_DEBUG(PSTR("gatewayTransportAvailable ethernet\n")); - Serial.print("gatewayTransportAvailable ethernet\n"); + //GATEWAY_DEBUG(PSTR("gatewayTransportAvailable ethernet\n")); + //Serial.print("gatewayTransportAvailable ethernet\n"); _w5100_spi_en(true); #if !defined(MY_IP_ADDRESS) && defined(MY_GATEWAY_W5100) // renew IP address using DHCP diff --git a/core/MySensorsCore.cpp b/core/MySensorsCore.cpp index 64022e9f2..054bd5ab3 100644 --- a/core/MySensorsCore.cpp +++ b/core/MySensorsCore.cpp @@ -666,9 +666,11 @@ void sleepHandler(bool sleep) int8_t _sleep(const uint32_t sleepingMS, const bool smartSleep, const uint8_t interrupt1, const uint8_t mode1, const uint8_t interrupt2, const uint8_t mode2) { + /* CORE_DEBUG(PSTR("MCO:SLP:MS=%" PRIu32 ",SMS=%" PRIu8 ",I1=%" PRIu8 ",M1=%" PRIu8 ",I2=%" PRIu8 ",M2=%" PRIu8 "\n"), sleepingMS, smartSleep, interrupt1, mode1, interrupt2, mode2); + */ // repeater feature: sleeping not possible #if defined(MY_REPEATER_FEATURE) (void)smartSleep; @@ -765,7 +767,7 @@ int8_t _sleep(const uint32_t sleepingMS, const bool smartSleep, const uint8_t in sleepHandler(false); setIndication(INDICATION_WAKEUP); - CORE_DEBUG(PSTR("MCO:SLP:WUP=%" PRIi8 "\n"), result); // sleep wake-up + //CORE_DEBUG(PSTR("MCO:SLP:WUP=%" PRIi8 "\n"), result); // sleep wake-up #if defined(MY_SENSOR_NETWORK) transportReInitialise(); #endif From 4816f548a62156971629213ff10d4136ba3cce66 Mon Sep 17 00:00:00 2001 From: Lukasz Date: Sun, 22 Aug 2021 20:35:54 +0200 Subject: [PATCH 3/5] removed debug logging --- core/MyGatewayTransport.cpp | 1 - core/MyGatewayTransport.h | 2 -- core/MyGatewayTransportEthernet.cpp | 33 ++++------------------ core/MySensorsCore.cpp | 43 +++-------------------------- 4 files changed, 10 insertions(+), 69 deletions(-) diff --git a/core/MyGatewayTransport.cpp b/core/MyGatewayTransport.cpp index 51aadade0..37aa71328 100644 --- a/core/MyGatewayTransport.cpp +++ b/core/MyGatewayTransport.cpp @@ -27,7 +27,6 @@ extern MyMessage _msgTmp; inline void gatewayTransportProcess(void) { - //Serial.print("gatewayTransportProcess entered\n"); if (gatewayTransportAvailable()) { _msg = gatewayTransportReceive(); if (_msg.getDestination() == GATEWAY_ADDRESS) { diff --git a/core/MyGatewayTransport.h b/core/MyGatewayTransport.h index 4b7ec1a0c..cfb34b48a 100644 --- a/core/MyGatewayTransport.h +++ b/core/MyGatewayTransport.h @@ -96,8 +96,6 @@ void gatewayTransportProcess(void); */ bool gatewayTransportInit(void); -void PrintLF(void); - /** * @brief Send message to controller * @param message to send diff --git a/core/MyGatewayTransportEthernet.cpp b/core/MyGatewayTransportEthernet.cpp index 55900361a..51c69e9b2 100644 --- a/core/MyGatewayTransportEthernet.cpp +++ b/core/MyGatewayTransportEthernet.cpp @@ -167,20 +167,8 @@ void gatewayTransportRenewIP(void) } #endif -static bool bBridge = false; -static bool bBridgeListen = false; - -void PrintLF() -{ - GATEWAY_DEBUG(PSTR("BRIDGE: %d\n"), bBridge); - GATEWAY_DEBUG(PSTR("BRIDGE LISTEN: %d\n"), bBridgeListen); -} - bool gatewayTransportInit(void) { - - GATEWAY_DEBUG("gatewayTransportInit\n"); - Serial.print("LF# gatewayTransportInit\n"); _w5100_spi_en(true); #if defined(MY_GATEWAY_ESP8266) || defined(MY_GATEWAY_ESP32) @@ -208,7 +196,6 @@ bool gatewayTransportInit(void) digitalWrite(13, LOW); Bridge.begin(); digitalWrite(13, HIGH); - bBridge = true; #else #if defined(MY_IP_GATEWAY_ADDRESS) && defined(MY_IP_SUBNET_ADDRESS) // DNS server set to gateway ip @@ -258,12 +245,9 @@ bool gatewayTransportInit(void) #else // we have to use pointers due to the constructor of EthernetServer #if defined (MY_GATEWAY_BRIDGE) - bBridgeListen = true; _ethernetServer.noListenOnLocalhost(); - Serial.print("LF# MY_GATEWAY_BRIDGE noListenOnLocalhost\n"); #endif _ethernetServer.begin(); - Serial.print("LF# MY_GATEWAY_BRIDGE begin\n"); #endif /* End of MY_GATEWAY_LINUX && MY_IP_ADDRESS */ #endif /* End of MY_GATEWAY_CLIENT_MODE */ @@ -274,7 +258,6 @@ bool gatewayTransportInit(void) // cppcheck-suppress constParameter bool gatewayTransportSend(MyMessage& message) { - Serial.print("LF# gatewayTransportSend\n"); int nbytes = 0; char* _ethernetMessage = protocolMyMessage2Serial(message); Serial.print(_ethernetMessage); @@ -305,13 +288,12 @@ bool gatewayTransportSend(MyMessage& message) gatewayTransportSend(buildGw(_msgTmp, I_GATEWAY_READY).set(MSG_GW_STARTUP_COMPLETE)); _w5100_spi_en(true); presentNode(); - } - else { - // connecting to the server failed! - GATEWAY_DEBUG(PSTR("!GWT:TPS:ETH FAIL\n")); - _w5100_spi_en(false); - return false; - } + } else { + // connecting to the server failed! + GATEWAY_DEBUG(PSTR("!GWT:TPS:ETH FAIL\n")); + _w5100_spi_en(false); + return false; + } } nbytes = client.write((const uint8_t*)_ethernetMessage, strlen(_ethernetMessage)); #endif /* End of MY_USE_UDP */ @@ -403,8 +385,6 @@ bool _readFromClient(void) bool gatewayTransportAvailable(void) { - //GATEWAY_DEBUG(PSTR("gatewayTransportAvailable ethernet\n")); - //Serial.print("gatewayTransportAvailable ethernet\n"); _w5100_spi_en(true); #if !defined(MY_IP_ADDRESS) && defined(MY_GATEWAY_W5100) // renew IP address using DHCP @@ -501,7 +481,6 @@ bool gatewayTransportAvailable(void) // if a new client connects make sure to dispose any previous existing sockets if (newclient) { if (client != newclient) { - Serial.print("NEW CLIENT!!!"); client.stop(); client = newclient; GATEWAY_DEBUG(PSTR("GWT:TSA:ETH OK\n")); diff --git a/core/MySensorsCore.cpp b/core/MySensorsCore.cpp index 054bd5ab3..d96a6a3d1 100644 --- a/core/MySensorsCore.cpp +++ b/core/MySensorsCore.cpp @@ -56,26 +56,20 @@ void _callbackTransportReady(void) void _process(void) { - //CORE_DEBUG(PSTR("_process 0\n")); #if defined(MY_DEBUG_VERBOSE_CORE) if (processLock) { CORE_DEBUG(PSTR("!MCO:PRO:RC=%" PRIu8 "\n"), processLock); // recursive call detected } processLock++; - //CORE_DEBUG(PSTR("_process 1\n")); #endif doYield(); - //CORE_DEBUG(PSTR("_process 2\n")); #if defined(MY_INCLUSION_MODE_FEATURE) inclusionProcess(); #endif #if defined(MY_GATEWAY_FEATURE) - //CORE_DEBUG(PSTR("_process 3\n")); gatewayTransportProcess(); - //CORE_DEBUG(PSTR("_process 4\n")); #endif - //CORE_DEBUG(PSTR("_process 5\n")); #if defined(MY_SENSOR_NETWORK) transportProcess(); #endif @@ -87,12 +81,10 @@ void _process(void) #if defined(MY_DEBUG_VERBOSE_CORE) processLock--; #endif - //CORE_DEBUG(PSTR("_process --\n")); } void _infiniteLoop(void) { - CORE_DEBUG(PSTR("_infiniteLoop\n")); #if defined(__linux__) exit(1); #else @@ -104,7 +96,6 @@ void _infiniteLoop(void) void _begin(void) { - CORE_DEBUG(PSTR("_begin LF#0")); #if defined(MY_CORE_ONLY) // initialize HW and run setup if present (void)hwInit(); @@ -129,7 +120,7 @@ void _begin(void) #if defined(F_CPU) CORE_DEBUG(PSTR("MCO:BGN:INIT " MY_NODE_TYPE ",CP=" MY_CAPABILITIES ",FQ=%" PRIu16 ",REL=%" PRIu8 ",VER=" - MYSENSORS_LIBRARY_VERSION "\n"), (uint16_t)(F_CPU / 1000000UL), + MYSENSORS_LIBRARY_VERSION "\n"), (uint16_t)(F_CPU/1000000UL), MYSENSORS_LIBRARY_VERSION_PRERELEASE_NUMBER); #else CORE_DEBUG(PSTR("MCO:BGN:INIT " MY_NODE_TYPE ",CP=" MY_CAPABILITIES ",FQ=NA,REL=%" @@ -141,10 +132,8 @@ void _begin(void) setIndication(INDICATION_ERR_HW_INIT); _infiniteLoop(); } - CORE_DEBUG(PSTR("LOLOLOL 1\n")); // set defaults _coreConfig.presentationSent = false; - CORE_DEBUG(PSTR("LOLOLOL\n")); // Call sketch before() (if defined) if (before) { CORE_DEBUG(PSTR("MCO:BGN:BFR\n")); // before callback @@ -154,9 +143,7 @@ void _begin(void) #if defined(MY_DEFAULT_TX_LED_PIN) || defined(MY_DEFAULT_RX_LED_PIN) || defined(MY_DEFAULT_ERR_LED_PIN) ledsInit(); #endif - CORE_DEBUG(PSTR("LOLOLOL 2\n")); signerInit(); - CORE_DEBUG(PSTR("LOLOLOL 3\n")); // Read latest received controller configuration from EEPROM // Note: _coreConfig.isMetric is bool, hence empty EEPROM (=0xFF) evaluates to true (default) hwReadConfigBlock((void*)&_coreConfig.controllerConfig, (void*)EEPROM_CONTROLLER_CONFIG_ADDRESS, @@ -179,14 +166,11 @@ void _begin(void) #endif _checkNodeLock(); - CORE_DEBUG(PSTR("LOLOLOL 4\n")); #if defined(MY_GATEWAY_FEATURE) CORE_DEBUG(PSTR("MCO:BGN:INIT YES MY gateway\n")); #if defined(MY_INCLUSION_BUTTON_FEATURE) inclusionInit(); #endif - bool initialisedGateway = false; - CORE_DEBUG(PSTR("LOLOLOL 5\n")); // initialise the transport driver if (!gatewayTransportInit()) { setIndication(INDICATION_ERR_INIT_GWTRANSPORT); @@ -194,14 +178,10 @@ void _begin(void) // Nothing more we can do _infiniteLoop(); } - else - { - initialisedGateway = true; - } + #else CORE_DEBUG(PSTR("MCO:BGN:INIT No MY gateway\n")); #endif -CORE_DEBUG(PSTR("LOLOLOL 6\n")); // Call sketch setup() (if defined) if (setup) { CORE_DEBUG(PSTR("MCO:BGN:STP\n")); // setup callback @@ -213,17 +193,7 @@ CORE_DEBUG(PSTR("LOLOLOL 6\n")); #else // no sensor network defined, call presentation & registration _callbackTransportReady(); - CORE_DEBUG(PSTR("LOLOLOL 7\n")); - CORE_DEBUG(PSTR("MCO:BGN:INIT OK,TSP=NA LF#2\n")); - if (initialisedGateway) - { - CORE_DEBUG(PSTR("initialisedGateway O!\n")); - PrintLF(); - } - else - { - CORE_DEBUG(PSTR("NOT initialisedGateway -1!\n")); - } + CORE_DEBUG(PSTR("MCO:BGN:INIT OK,TSP=NA\n")); #endif // reset wdt before handing over to loop hwWatchdogReset(); @@ -589,7 +559,6 @@ void wait(const uint32_t waitingMS) #endif const uint32_t enteringMS = hwMillis(); while (hwMillis() - enteringMS < waitingMS) { - CORE_DEBUG(PSTR("Pre process 1")); _process(); } #if defined(MY_DEBUG_VERBOSE_CORE) @@ -611,7 +580,6 @@ bool wait(const uint32_t waitingMS, const mysensors_command_t cmd) _msg.setCommand(C_INVALID_7); bool expectedResponse = false; while ((hwMillis() - enteringMS < waitingMS) && !expectedResponse) { - CORE_DEBUG(PSTR("Pre process 2")); _process(); expectedResponse = (_msg.getCommand() == cmd); } @@ -635,7 +603,6 @@ bool wait(const uint32_t waitingMS, const mysensors_command_t cmd, const uint8_t _msg.setCommand(C_INVALID_7); bool expectedResponse = false; while ( (hwMillis() - enteringMS < waitingMS) && !expectedResponse ) { - CORE_DEBUG(PSTR("Pre process 3")); _process(); expectedResponse = (_msg.getCommand() == cmd && _msg.getType() == msgType); } @@ -666,11 +633,9 @@ void sleepHandler(bool sleep) int8_t _sleep(const uint32_t sleepingMS, const bool smartSleep, const uint8_t interrupt1, const uint8_t mode1, const uint8_t interrupt2, const uint8_t mode2) { - /* CORE_DEBUG(PSTR("MCO:SLP:MS=%" PRIu32 ",SMS=%" PRIu8 ",I1=%" PRIu8 ",M1=%" PRIu8 ",I2=%" PRIu8 ",M2=%" PRIu8 "\n"), sleepingMS, smartSleep, interrupt1, mode1, interrupt2, mode2); - */ // repeater feature: sleeping not possible #if defined(MY_REPEATER_FEATURE) (void)smartSleep; @@ -767,7 +732,7 @@ int8_t _sleep(const uint32_t sleepingMS, const bool smartSleep, const uint8_t in sleepHandler(false); setIndication(INDICATION_WAKEUP); - //CORE_DEBUG(PSTR("MCO:SLP:WUP=%" PRIi8 "\n"), result); // sleep wake-up + CORE_DEBUG(PSTR("MCO:SLP:WUP=%" PRIi8 "\n"), result); // sleep wake-up #if defined(MY_SENSOR_NETWORK) transportReInitialise(); #endif From db8a116b764e35851ee1b1cd3f842cb57bf0bff6 Mon Sep 17 00:00:00 2001 From: Lukasz Date: Sun, 22 Aug 2021 20:42:13 +0200 Subject: [PATCH 4/5] removed debug logging pt.2 --- core/MyGatewayTransportEthernet.cpp | 9 +-------- core/MySensorsCore.cpp | 29 ++++++++++++++++------------- 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/core/MyGatewayTransportEthernet.cpp b/core/MyGatewayTransportEthernet.cpp index 51c69e9b2..710a6c444 100644 --- a/core/MyGatewayTransportEthernet.cpp +++ b/core/MyGatewayTransportEthernet.cpp @@ -490,10 +490,7 @@ bool gatewayTransportAvailable(void) presentNode(); } } - else - { - //Serial.print("gatewayTransportAvailable MY_GATEWAY_BRIDGE NEW client null\n"); - } + if (client) { if (!client.connected()) { GATEWAY_DEBUG(PSTR("!GWT:TSA:ETH FAIL\n")); @@ -506,10 +503,6 @@ bool gatewayTransportAvailable(void) } } } - else - { - //Serial.print("gatewayTransportAvailable MY_GATEWAY_BRIDGE client null\n"); - } #endif /* End of MY_GATEWAY_ESP8266 || MY_GATEWAY_LINUX */ #endif /* End of MY_GATEWAY_CLIENT_MODE */ _w5100_spi_en(false); diff --git a/core/MySensorsCore.cpp b/core/MySensorsCore.cpp index d96a6a3d1..6e4b79ac7 100644 --- a/core/MySensorsCore.cpp +++ b/core/MySensorsCore.cpp @@ -63,6 +63,7 @@ void _process(void) processLock++; #endif doYield(); + #if defined(MY_INCLUSION_MODE_FEATURE) inclusionProcess(); #endif @@ -70,6 +71,7 @@ void _process(void) #if defined(MY_GATEWAY_FEATURE) gatewayTransportProcess(); #endif + #if defined(MY_SENSOR_NETWORK) transportProcess(); #endif @@ -119,21 +121,23 @@ void _begin(void) #if defined(F_CPU) CORE_DEBUG(PSTR("MCO:BGN:INIT " MY_NODE_TYPE ",CP=" MY_CAPABILITIES ",FQ=%" PRIu16 ",REL=%" - PRIu8 ",VER=" - MYSENSORS_LIBRARY_VERSION "\n"), (uint16_t)(F_CPU/1000000UL), - MYSENSORS_LIBRARY_VERSION_PRERELEASE_NUMBER); + PRIu8 ",VER=" + MYSENSORS_LIBRARY_VERSION "\n"), (uint16_t)(F_CPU/1000000UL), + MYSENSORS_LIBRARY_VERSION_PRERELEASE_NUMBER); #else CORE_DEBUG(PSTR("MCO:BGN:INIT " MY_NODE_TYPE ",CP=" MY_CAPABILITIES ",FQ=NA,REL=%" - PRIu8 ",VER=" - MYSENSORS_LIBRARY_VERSION "\n"), MYSENSORS_LIBRARY_VERSION_PRERELEASE_NUMBER); + PRIu8 ",VER=" + MYSENSORS_LIBRARY_VERSION "\n"), MYSENSORS_LIBRARY_VERSION_PRERELEASE_NUMBER); #endif if (!hwInitResult) { CORE_DEBUG(PSTR("!MCO:BGN:HW ERR\n")); setIndication(INDICATION_ERR_HW_INIT); _infiniteLoop(); } + // set defaults _coreConfig.presentationSent = false; + // Call sketch before() (if defined) if (before) { CORE_DEBUG(PSTR("MCO:BGN:BFR\n")); // before callback @@ -143,11 +147,13 @@ void _begin(void) #if defined(MY_DEFAULT_TX_LED_PIN) || defined(MY_DEFAULT_RX_LED_PIN) || defined(MY_DEFAULT_ERR_LED_PIN) ledsInit(); #endif + signerInit(); + // Read latest received controller configuration from EEPROM // Note: _coreConfig.isMetric is bool, hence empty EEPROM (=0xFF) evaluates to true (default) - hwReadConfigBlock((void*)&_coreConfig.controllerConfig, (void*)EEPROM_CONTROLLER_CONFIG_ADDRESS, - sizeof(controllerConfig_t)); + hwReadConfigBlock((void *)&_coreConfig.controllerConfig, (void *)EEPROM_CONTROLLER_CONFIG_ADDRESS, + sizeof(controllerConfig_t)); #if defined(MY_OTA_FIRMWARE_FEATURE) // Read firmware config from EEPROM, i.e. type, version, CRC, blocks @@ -166,11 +172,12 @@ void _begin(void) #endif _checkNodeLock(); + #if defined(MY_GATEWAY_FEATURE) - CORE_DEBUG(PSTR("MCO:BGN:INIT YES MY gateway\n")); #if defined(MY_INCLUSION_BUTTON_FEATURE) inclusionInit(); #endif + // initialise the transport driver if (!gatewayTransportInit()) { setIndication(INDICATION_ERR_INIT_GWTRANSPORT); @@ -178,10 +185,8 @@ void _begin(void) // Nothing more we can do _infiniteLoop(); } - -#else - CORE_DEBUG(PSTR("MCO:BGN:INIT No MY gateway\n")); #endif + // Call sketch setup() (if defined) if (setup) { CORE_DEBUG(PSTR("MCO:BGN:STP\n")); // setup callback @@ -197,7 +202,6 @@ void _begin(void) #endif // reset wdt before handing over to loop hwWatchdogReset(); - CORE_DEBUG(PSTR("after hwWatchdogReset\n")); } @@ -657,7 +661,6 @@ int8_t _sleep(const uint32_t sleepingMS, const bool smartSleep, const uint8_t in uint32_t sleepDeltaMS = 0; while (!isTransportReady() && (sleepDeltaMS < sleepingTimeMS) && (sleepDeltaMS < MY_SLEEP_TRANSPORT_RECONNECT_TIMEOUT_MS)) { - CORE_DEBUG(PSTR("Pre process 4")); _process(); sleepDeltaMS = hwMillis() - sleepEnterMS; } From d4f9d18cf2d1bac78f9c3657cbea962fbd479d50 Mon Sep 17 00:00:00 2001 From: Lukasz Date: Tue, 24 Aug 2021 18:17:56 +0200 Subject: [PATCH 5/5] removed led indication of Bridge.begin(). warnings and errors added --- core/MyGatewayTransportEthernet.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/core/MyGatewayTransportEthernet.cpp b/core/MyGatewayTransportEthernet.cpp index 710a6c444..37de90fbd 100644 --- a/core/MyGatewayTransportEthernet.cpp +++ b/core/MyGatewayTransportEthernet.cpp @@ -58,7 +58,11 @@ extern MyMessage _msgTmp; #endif #if defined(MY_IP_ADDRESS) +#if defined(MY_GATEWAY_BRIDGE) +#warning MY_IP_ADDRESS not used when Brigde gateway is configured, define IP Address in OpenWrt settings instead! +#else #define _ethernetGatewayIP IPAddress(MY_IP_ADDRESS) +#endif #if defined(MY_IP_GATEWAY_ADDRESS) #define _gatewayIp IPAddress(MY_IP_GATEWAY_ADDRESS) #elif defined(MY_GATEWAY_ESP8266) || defined(MY_GATEWAY_ESP32) @@ -102,6 +106,9 @@ typedef struct { #endif #if defined(MY_GATEWAY_CLIENT_MODE) +#if defined (MY_GATEWAY_BRIDGE) +#error Client mode is not supported when MY_GATEWAY_BRIDGE is used! +#endif #if defined(MY_USE_UDP) EthernetUDP _ethernetServer; #endif /* End of MY_USE_UDP */ @@ -191,11 +198,8 @@ bool gatewayTransportInit(void) #elif defined(MY_GATEWAY_LINUX) // Nothing to do here #elif defined(MY_GATEWAY_BRIDGE) - GATEWAY_DEBUG("Init Bridge\n"); - pinMode(13, OUTPUT); - digitalWrite(13, LOW); + GATEWAY_DEBUG(PSTR("GWT:TIN:BRIDGE BEGIN...\n")); Bridge.begin(); - digitalWrite(13, HIGH); #else #if defined(MY_IP_GATEWAY_ADDRESS) && defined(MY_IP_SUBNET_ADDRESS) // DNS server set to gateway ip