From 71e8c3f837f174cffc13d3567a1e5881efcb5fad Mon Sep 17 00:00:00 2001 From: sergiu_toporjinschi Date: Sat, 3 Aug 2019 16:41:33 +0300 Subject: [PATCH] * Adapt to platformio last version * Add debug on udp on restart; --- README.md | 9 ++++++++ examples/ESPManager/data/settings.json | 7 +++++- library.properties | 2 +- platformio.ini | 7 +++--- preRelease.py | 11 ++++++--- src/ESPManager.cpp | 31 ++++++++++++++++++++++++++ src/ESPManager.h | 17 ++++++++++++++ 7 files changed, 75 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 24849f0..850380f 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,15 @@ Dependencies: * [ESP8266httpUpdate](https://github.com/esp8266/Arduino/tree/master/libraries/ESP8266httpUpdate) For details using SettingsManager please see the [read.me](https://github.com/SergiuToporjinschi/settingsmanager) file. +## Compile macro flags + >**EM_UDP_DEBUG** - For sending aditional information via UDP, you configure ip and port in your configuration file under the wlan object; +```json +"debugUDP": { + "enabled": true, + "server": "192.168.1.1", + "port": "4321" +} +``` ## Constructor ` ESPManager(); diff --git a/examples/ESPManager/data/settings.json b/examples/ESPManager/data/settings.json index 1abe082..9719e83 100644 --- a/examples/ESPManager/data/settings.json +++ b/examples/ESPManager/data/settings.json @@ -2,7 +2,12 @@ "wlan": { "hostName": "espTest", "ssid": "mySSid", - "password": "myPassword" + "password": "myPassword", + "debugUDP": { + "enabled": true, + "server": "192.168.1.6", + "port": "4321" + } }, "mqtt": { "clientId": "espCID", diff --git a/library.properties b/library.properties index 6454d1e..443b6fd 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=ESPManager -version=3.0.3 +version=3.0.4 author=Sergiu Toporjinschi maintainer=Sergiu Toporjinschi sentence=ESP manager diff --git a/platformio.ini b/platformio.ini index 47046ff..70b988c 100644 --- a/platformio.ini +++ b/platformio.ini @@ -8,13 +8,11 @@ ; Please visit documentation for the other options and examples ; https://docs.platformio.org/page/projectconf.html [platformio] -env_default = nodemcuv2 +default_envs = nodemcuv2 ; src_dir = ./.pio_compile - - [common] -version = "3.0.3" +version = "3.0.4" name = "EspManager" monitor_speed = 115200 examples_folder = examples/ESPManager @@ -27,6 +25,7 @@ lib_deps = Settings Manager@^2.0.7 build_flags = -D VER=\"${common.version}\" + -D EM_UDP_DEBUG -D DEBUGGER !python git_rev_macro.py diff --git a/preRelease.py b/preRelease.py index 1c019f3..97fab4c 100644 --- a/preRelease.py +++ b/preRelease.py @@ -1,9 +1,14 @@ -from platformio import util +try: + import configparser +except ImportError: + import ConfigParser as configparser import glob, shutil, os, sys -print '########### Run release script ###########' -config = util.load_project_config() +print '########### Run release script ###########' +Import("env") +config = configparser.ConfigParser() +config.read("platformio.ini") exampleFolder = config.get("common", "examples_folder") version = config.get("common", "version").replace("\"","") diff --git a/src/ESPManager.cpp b/src/ESPManager.cpp index 2aaf5bc..a7add35 100644 --- a/src/ESPManager.cpp +++ b/src/ESPManager.cpp @@ -100,6 +100,9 @@ void ESPManager::connectToWifi() { delay(100); WiFi.begin(_wlanConf.getMember(F("ssid")).as(), _wlanConf.getMember(F("password")).as()); waitForWiFi(); +#ifdef EM_UDP_DEBUG + initDebugUDP(); +#endif } /** @@ -132,6 +135,34 @@ void ESPManager::waitForWiFi() { DBGLN(WiFi.localIP().toString()); } +#ifdef EM_UDP_DEBUG +void ESPManager::initDebugUDP() { + DBGLN("UDP DEBUG:"); + JsonVariant debugUdp = _wlanConf.getMember(F("debugUDP")); + if (WiFi.status() == WL_CONNECTED && + !debugUdp.isNull() && + !debugUdp.getMember(F("enabled")).isNull() && + debugUdp.getMember(F("enabled")).as() && + !debugUdp.getMember(F("server")).isNull() && + !debugUdp.getMember(F("port")).isNull()) { + + udpDebugIP.fromString(debugUdp.getMember(F("server")).as()); + udpDebugPort = debugUdp.getMember(F("port")).as(); + DBG("port:"); + DBGLN(udpDebugPort); + DBG("ip:"); + DBGLN(udpDebugIP.toString()); + rst_info *resetInfo = ESP.getResetInfoPtr(); + char buff[200] = {0}; + sprintf_P(&buff[0], DEUBG_UDP_MASK_P, resetInfo->exccause, resetInfo->reason, (resetInfo->reason == 0 ? "DEFAULT" : resetInfo->reason == 1 ? "WDT" : resetInfo->reason == 2 ? "EXCEPTION" : resetInfo->reason == 3 ? "SOFT_WDT" : resetInfo->reason == 4 ? "SOFT_RESTART" : resetInfo->reason == 5 ? "DEEP_SLEEP_AWAKE" : resetInfo->reason == 6 ? "EXT_SYS_RST" : "???"), resetInfo->epc1, resetInfo->epc2, resetInfo->epc3, resetInfo->excvaddr, resetInfo->depc); + if (Udp.beginPacket(udpDebugIP, udpDebugPort)) { + Udp.write(buff); + Udp.endPacket(); + } + } +} +#endif + /** Is printing connection status to WiFi if is not connected; */ diff --git a/src/ESPManager.h b/src/ESPManager.h index a87567e..78041b0 100644 --- a/src/ESPManager.h +++ b/src/ESPManager.h @@ -30,6 +30,12 @@ #include #include +#ifdef EM_UDP_DEBUG +# include + +static const char DEUBG_UDP_MASK_P[] PROGMEM = "{\"Exception\":%d,\"flag\":%d,\"flagText\":\"%s\",\"epc1\":\"0x%08x\",\"epc2\":\"0x%08x\",\"epc3\":\"0x%08x\",\"excvaddr\":\"0x%08x\",\"depc\":\"0x%08x\"}"; +#endif + static const char STATUS_FORMAT_P[] PROGMEM = "{\"name\":\"%s\", \"status\":\"%s\"}"; static const char STATUS_ONLINE_P[] PROGMEM = "online"; static const char STATUS_OFFLINE_P[] PROGMEM = "offline"; @@ -100,6 +106,12 @@ class ESPManager { bool retainMsg = false; int qos = 0; +#ifdef EM_UDP_DEBUG + WiFiUDP Udp; + IPAddress udpDebugIP; + uint16_t udpDebugPort; +#endif + std::function beforeWaitingWiFiCon; std::function waitingWiFiCon; std::function afterWaitingWiFiCon; @@ -157,6 +169,11 @@ class ESPManager { //conectivity functions void createConnections(); + +#ifdef EM_UDP_DEBUG + void initDebugUDP(); +#endif + void connectToWifi(); void waitForWiFi(); void debugWiFiStatus();