Skip to content

Commit

Permalink
* Adapt to platformio last version
Browse files Browse the repository at this point in the history
* Add debug on udp on restart;
  • Loading branch information
SergiuToporjinschi committed Aug 3, 2019
1 parent bac4923 commit 71e8c3f
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 9 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
7 changes: 6 additions & 1 deletion examples/ESPManager/data/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=ESPManager
version=3.0.3
version=3.0.4
author=Sergiu Toporjinschi
maintainer=Sergiu Toporjinschi
sentence=ESP manager
Expand Down
7 changes: 3 additions & 4 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
11 changes: 8 additions & 3 deletions preRelease.py
Original file line number Diff line number Diff line change
@@ -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("\"","")
Expand Down
31 changes: 31 additions & 0 deletions src/ESPManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ void ESPManager::connectToWifi() {
delay(100);
WiFi.begin(_wlanConf.getMember(F("ssid")).as<char *>(), _wlanConf.getMember(F("password")).as<char *>());
waitForWiFi();
#ifdef EM_UDP_DEBUG
initDebugUDP();
#endif
}

/**
Expand Down Expand Up @@ -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<boolean>() &&
!debugUdp.getMember(F("server")).isNull() &&
!debugUdp.getMember(F("port")).isNull()) {

udpDebugIP.fromString(debugUdp.getMember(F("server")).as<char *>());
udpDebugPort = debugUdp.getMember(F("port")).as<unsigned short>();
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;
*/
Expand Down
17 changes: 17 additions & 0 deletions src/ESPManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@
#include <pgmspace.h>
#include <stdlib.h>

#ifdef EM_UDP_DEBUG
# include <WiFiUdp.h>

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";
Expand Down Expand Up @@ -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<void()> beforeWaitingWiFiCon;
std::function<void()> waitingWiFiCon;
std::function<void()> afterWaitingWiFiCon;
Expand Down Expand Up @@ -157,6 +169,11 @@ class ESPManager {

//conectivity functions
void createConnections();

#ifdef EM_UDP_DEBUG
void initDebugUDP();
#endif

void connectToWifi();
void waitForWiFi();
void debugWiFiStatus();
Expand Down

0 comments on commit 71e8c3f

Please sign in to comment.