Skip to content

Commit

Permalink
no message
Browse files Browse the repository at this point in the history
  • Loading branch information
SergiuToporjinschi committed Oct 7, 2019
1 parent 6b4b7ea commit b45ff04
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 112 deletions.
35 changes: 19 additions & 16 deletions examples/ESPManager/ESPManager.ino
Original file line number Diff line number Diff line change
@@ -1,28 +1,36 @@
/*
ESPManager
/*
espManager
Copyright (C) 2018 by Sergiu Toporjinschi <sergiu dot toporjinschi at gmail dot com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
the Free Software Foundation version 3.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
along with this program. If not, see <https://spdx.org/licenses/GPL-3.0-only.html>.
Ctrl+k > open data folder, edit settings.json from data folder
Set values from wlan and mqtt
All rights reserved
*/

#ifdef DEBUGGER
# include "debug_macro.h"
Print *dbg = &Serial;
#endif

#include "ESPManager.h"
#include "SettingsManager.h"
#include "SoftwareSerial.h"
#include <Arduino.h>
#include <ArduinoJson.h>

char *readTemp(const char *msg);
void onCall(const char *msg);

Expand All @@ -36,13 +44,9 @@ char *readTemp(const char *msg);

void setup() {
Serial.begin(115200);
#if defined(DEBUG_SETTINGS) || defined(DEBUG_ESPMANAGER)
# ifdef DEBUG_SETTINGS
conf.setDebugger(&Serial);
# endif
# ifdef DEBUG_ESPMANAGER
man.setDebugger(&Serial);
# endif

#ifdef DEBUGGER
dbg = &Serial;
#endif

//Reading configuration from json file
Expand Down Expand Up @@ -134,5 +138,4 @@ char *onGetConf(JsonVariant params) {
char *retSettings = (char *)malloc(1000 * sizeof(char));
strcpy(retSettings, settings);
return retSettings;
//man.sendMsg("IOT/espTest/getconf", settings);
};
};
26 changes: 16 additions & 10 deletions library.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
{
"name": "espManager",
"version": "3.1.2",
"license": "GPL-3.0-only",
"description": "A wrapper for connection an ESP8266-01 to wifi, mqtt and create a small comunication",
"keywords": "ESP, ESP8266, IOT, WIFI, OTA",
"repository": {
"type": "git",
"url": "https://github.com/SergiuToporjinschi/espmanager"
},
"keywords": "ESP, ESP8266, IOT, WIFI, OTA",
"Authors": "Sergiu Toporjinschi",
"version": "3.1.1",
"frameworks": "*",
"platforms": "espressif8266",
"dependencies": {
"ArduinoJson": "^6.10.0"
"authors": {
"name": "Sergiu Toporjinschi",
"maintainer": true
},
"examples": [
"examples/*.cpp"
]
"frameworks": "arduino",
"platforms": [
"espressif8266",
"espressif32"
],
"dependencies": {
"ArduinoJson": "^6.10.0",
"SketchLogger": "^1.0.7",
"Settings Manager": "^2.1.0"
}
}
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.1.1
version=3.1.2
author=Sergiu Toporjinschi
maintainer=Sergiu Toporjinschi
sentence=ESP manager
Expand Down
65 changes: 26 additions & 39 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,72 +12,59 @@
; src_dir = ./.pio_compile

[common]
version = "3.1.0"
version = "2.1.2"
name = "EspManager"
examples_folder = "examples/ESPManager"
build_flags =
-D VER=\"${common.version}\"
-D EM_UDP_DEBUG
; !python git_rev_macro.py

[env]
lib_extra_dirs =
; E:/IOT/Projects/PlatformIO/SketchLogger
E:/IOT/Projects/PlatformIO

monitor_speed = 115200
examples_folder = examples/ESPManager
monitor_port = COM3
upload_speed = 115200
upload_port = COM3

framework = arduino
platform = espressif8266
extra_scripts = pre:preRelease.py
; extra_scripts = pre:preRelease.py
lib_deps =
ArduinoJson@^6.10.1
SketchLogger@^1.0.0
617
Settings Manager@^2.1.0
MQTT
build_flags =
-D VER=\"${common.version}\"
-D EM_UDP_DEBUG
!python git_rev_macro.py
; MQTT


#############################
########## ESP-01 ###########
#############################
## ESP-01 ######################################
[env:esp01_1m]
platform = espressif8266
monitor_speed = ${common.monitor_speed}
framework = ${common.framework}
lib_deps = ${common.lib_deps}
extra_scripts = ${common.extra_scripts}
board = esp01_1m
upload_protocol = esptool
board_build.flash_mode = dout
build_flags =
${common.build_flags}
-Wl,-Teagle.flash.1m64.ld



## Node MCU DEBUG ##############################
[env:nodemcuv_DEBUG]
board_build.flash_mode = qio
platform = espressif8266
monitor_speed = ${common.monitor_speed}
framework = ${common.framework}
lib_deps = ${common.lib_deps}
extra_scripts = ${common.extra_scripts}
board = nodemcu
monitor_port = COM11
monitor_speed = 9600
; lib_extra_dirs = E:/IOT/Projects/PlatformIO/SettingsManager
board_build.flash_mode = qio
build_flags =
-D DEBUG_ESPMANAGER
-D DEBUG_SETTINGS
-D DEBUGGER
${common.build_flags}
-Wl,-Teagle.flash.4m1m.ld



#############################
############ MCU ############
#############################
## Node MCU ######################################
[env:nodemcuv]
board_build.flash_mode = qio
platform = espressif8266
board = nodemcu
monitor_speed = ${common.monitor_speed}
monitor_port = COM3
framework = ${common.framework}
lib_deps = ${common.lib_deps}
extra_scripts = ${common.extra_scripts}
board_build.flash_mode = qio
build_flags =
${common.build_flags}
-Wl,-Teagle.flash.4m1m.ld
47 changes: 14 additions & 33 deletions src/ESPManager.cpp
Original file line number Diff line number Diff line change
@@ -1,39 +1,28 @@
/*
ESPManager
/*
espManager
Copyright (C) 2018 by Sergiu Toporjinschi <sergiu dot toporjinschi at gmail dot com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
the Free Software Foundation version 3.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
along with this program. If not, see <https://spdx.org/licenses/GPL-3.0-only.html>.
All rights reserved
*/
#include "ESPManager.h"

//=================[ DEBUG_ESPMANAGER ]================
#ifdef DEBUG_ESPMANAGER
# define DBG(x) \
this->debug->print(x); \
this->debug->flush();
# define DBGLN(x, ...) \
this->debug->printf("[%s](%d): ", __FILE__, __LINE__); \
this->debug->printf(x, ##__VA_ARGS__); \
this->debug->println(""); \
this->debug->flush();
#else
# define DBG(X)
# define DBGLN(X, ...)
#endif // DEBUG_ESPMANAGER
//=================[ DEBUG_ESPMANAGER ]================
#include "debug_macro.h"

#include "ESPManager.h"

ADC_MODE(ADC_VCC);

Expand Down Expand Up @@ -132,7 +121,7 @@ void ESPManager::waitForWiFi() {
}
int waitingTime = millis();
while (WiFi.status() != WL_CONNECTED && millis() - waitingTime < 30000) {
DBG("#");
DBGLN("#");
if (this->waitingWiFiCon != nullptr) {
this->waitingWiFiCon();
}
Expand All @@ -142,7 +131,6 @@ void ESPManager::waitForWiFi() {
DBGLN("hasAfter");
this->afterWaitingWiFiCon();
}
// DBGLN("");
if (WiFi.status() != WL_CONNECTED) {
debugWiFiStatus();
ESP.restart();
Expand Down Expand Up @@ -180,7 +168,7 @@ void ESPManager::initDebugUDP() {
Is printing connection status to WiFi if is not connected;
*/
void ESPManager::debugWiFiStatus() {
#ifdef DEBUG_ESPMANAGER
#ifdef DEBUGGER
int wiFiStatus = WiFi.status();
DBGLN("WiFi status: %i, %s", wiFiStatus, wiFiStatus == WL_CONNECTED ? " CONNECTED" : (wiFiStatus == WL_CONNECT_FAILED ? " FAILED" : (wiFiStatus == WL_DISCONNECTED ? " DISCONNECTED" : (wiFiStatus == WL_CONNECTION_LOST ? " CONNECTION_LOST " : ""))));
#endif
Expand Down Expand Up @@ -253,7 +241,7 @@ void ESPManager::connectToMQTT() {
this->beforeWaitingMQTTCon();
}
while (!mqttCli.connect(clientId, user, password)) {
DBG("_");
DBGLN("_");
if (this->waitingMQTTCon != nullptr) {
this->waitingMQTTCon();
}
Expand Down Expand Up @@ -303,7 +291,6 @@ void ESPManager::subscribeCMD() {
void ESPManager::loopIt() {
mqttCli.loop();
delay(10);
//delay(settings.getInt("esp.delayTime")); // <- fixes some issues with WiFi stability

if (WiFi.status() != WL_CONNECTED || !mqttCli.connected()) {
DBGLN("Not connected to MQTT reconnect ...");
Expand Down Expand Up @@ -394,7 +381,7 @@ void ESPManager::executeCommands(const char *topic, const char *payload) {
}

void ESPManager::addIncomingEventHandler(const char *topic, eventIncomingHandler handler) {
#ifndef DEBUG_SERIAL
#ifndef DEBUGER
if (topic == nullptr) {
DBGLN("To subscribe, topic is mandatory");
}
Expand Down Expand Up @@ -529,12 +516,6 @@ void ESPManager::cmdUpdate(const char *respTopic, JsonVariant params) {
}
// ---==[ END Commands ]==---

#ifdef DEBUG_ESPMANAGER
void ESPManager::setDebugger(Print *print) {
debug = print;
}
#endif //DEBUG_ESPMANAGER

ESPManager::~ESPManager() {
// delete cbBind;
delete &mqttCli;
Expand Down
21 changes: 8 additions & 13 deletions src/ESPManager.h
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
/*
ESPManager
/*
espManager
Copyright (C) 2018 by Sergiu Toporjinschi <sergiu dot toporjinschi at gmail dot com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
the Free Software Foundation version 3.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
along with this program. If not, see <https://spdx.org/licenses/GPL-3.0-only.html>.
All rights reserved
*/

#ifndef ESPManager_h
#define ESPManager_h
#include "Macro.h"
Expand All @@ -32,7 +35,6 @@

#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

Expand Down Expand Up @@ -100,18 +102,11 @@ class ESPManager {

void addCommand(const char *cmd, cmdFunction handler);

#ifdef DEBUG_ESPMANAGER
void setDebugger(Print *print);
#endif //DEBUG_ESPMANAGER

private:
const char *version = VER;
const char *sketchVersion = nullptr;
bool retainMsg = false;
int qos = 0;
#ifdef DEBUG_ESPMANAGER
Print *debug = &Serial;
#endif //DEBUG_ESPMANAGER
#ifdef EM_UDP_DEBUG
WiFiUDP Udp;
IPAddress udpDebugIP;
Expand Down
Loading

0 comments on commit b45ff04

Please sign in to comment.