uart working version

This commit is contained in:
Dmitry Borisenko
2020-12-10 19:12:15 +03:00
parent d17112b3ff
commit f487a691fb
26 changed files with 119 additions and 118 deletions

View File

@@ -43,7 +43,7 @@
}, },
{ {
"type": "h4", "type": "h4",
"title": "Версия файловой системы: 268" "title": "Версия файловой системы: 270"
}, },
{ {
"type": "h4", "type": "h4",

View File

@@ -5,7 +5,7 @@
#include "Utils/TimeUtils.h" #include "Utils/TimeUtils.h"
#include "Utils\SerialPrint.h" #include "Utils\SerialPrint.h"
extern void clock_init(); extern void clockInit();
#ifdef ESP8266 #ifdef ESP8266
#include "sntp.h" #include "sntp.h"

View File

@@ -42,7 +42,7 @@ extern void bme280A_reading();
//extern void dhtC_reading(); //extern void dhtC_reading();
//extern void dhtD_reading(); //extern void dhtD_reading();
extern void handle_time_init(); extern void timeInit();
extern void stepper(); extern void stepper();
extern void stepperSet(); extern void stepperSet();
extern void servo_(); extern void servo_();

View File

@@ -1,7 +1,7 @@
#pragma once #pragma once
//===========Firmware============================================================================================================================================= //===========Firmware=============================================================================================================================================
#define FIRMWARE_VERSION 268 #define FIRMWARE_VERSION 270
//#define FLASH_SIZE_1MB //#define FLASH_SIZE_1MB
#ifdef ESP8266 #ifdef ESP8266
#define FIRMWARE_NAME "esp8266-iotm" #define FIRMWARE_NAME "esp8266-iotm"

View File

@@ -1,10 +1,10 @@
#pragma once #pragma once
extern void loadConfig(); extern void loadConfig();
extern void all_init(); extern void espInit();
extern void statistics_init(); extern void statistics_init();
extern void loadScenario(); extern void loadScenario();
extern void Device_init(); extern void deviceInit();
extern void prsets_init(); extern void prsets_init();
extern void handle_uptime(); extern void handle_uptime();
extern void handle_statistics(); extern void handle_statistics();

View File

@@ -50,4 +50,4 @@ int getOffsetInMinutes(int timezone);
*/ */
void breakEpochToTime(unsigned long epoch, Time_t& tm); void breakEpochToTime(unsigned long epoch, Time_t& tm);
void handle_time_init(); void timeInit();

View File

@@ -5,3 +5,4 @@
extern String getURL(const String& urls); extern String getURL(const String& urls);
extern const String getMethodName(AsyncWebServerRequest* request); extern const String getMethodName(AsyncWebServerRequest* request);
extern const String getRequestInfo(AsyncWebServerRequest* request); extern const String getRequestInfo(AsyncWebServerRequest* request);
extern void wifiSignalInit();

View File

@@ -144,6 +144,7 @@ void sensorsInit() {
} }
}, },
nullptr, true); nullptr, true);
SerialPrint("I", F("Sensors"), F("Sensors Init"));
} }
void addKey(String& key, String& keyNumberTable, int number) { void addKey(String& key, String& keyNumberTable, int number) {

View File

@@ -10,12 +10,14 @@ void busInit() {
tmp = i2c_scan(); tmp = i2c_scan();
Serial.println(tmp); Serial.println(tmp);
jsonWriteStr(configLiveJson, "i2c", tmp); jsonWriteStr(configLiveJson, "i2c", tmp);
} else { }
else {
Serial.println(tmp); Serial.println(tmp);
jsonWriteStr(configLiveJson, "i2c", tmp); jsonWriteStr(configLiveJson, "i2c", tmp);
} }
}, },
nullptr); nullptr);
SerialPrint("I", F("Bus"), F("Bus Init"));
} }
String i2c_scan() { String i2c_scan() {
@@ -32,7 +34,8 @@ String i2c_scan() {
} }
if (count == 0) { if (count == 0) {
return "error"; return "error";
} else { }
else {
return out; return out;
} }
} }

View File

@@ -3,14 +3,14 @@
#include "Global.h" #include "Global.h"
Clock* timeNow; Clock* timeNow;
void clock_init() { void clockInit() {
timeNow = new Clock; timeNow = new Clock;
timeNow->setNtpPool(jsonReadStr(configSetupJson, "ntp")); timeNow->setNtpPool(jsonReadStr(configSetupJson, "ntp"));
timeNow->setTimezone(jsonReadStr(configSetupJson, "timezone").toInt()); timeNow->setTimezone(jsonReadStr(configSetupJson, "timezone").toInt());
ts.add( ts.add(
TIME_SYNC, 30000, [&](void*) { TIME_SYNC, 30000, [&](void*) {
timeNow->hasSync(); timeNow->hasSync();
}, },
nullptr, true); nullptr, true);
SerialPrint("I", F("Time"), F("Clock Init"));
} }

View File

@@ -26,17 +26,20 @@ void loadConfig() {
prex = jsonReadStr(configSetupJson, "mqttPrefix") + "/" + chipId; prex = jsonReadStr(configSetupJson, "mqttPrefix") + "/" + chipId;
Serial.println(configSetupJson); //Serial.println(configSetupJson);
serverIP = jsonReadStr(configSetupJson, "serverip"); serverIP = jsonReadStr(configSetupJson, "serverip");
SerialPrint("I", F("Conf"), F("Config Json Init"));
} }
void all_init() { void espInit() {
Device_init(); deviceInit();
loadScenario(); loadScenario();
SerialPrint("I", F("esp"), F("esp Init"));
} }
void Device_init() { void deviceInit() {
sensorReadingMap10sec = ""; sensorReadingMap10sec = "";
@@ -110,6 +113,7 @@ void uptime_init() {
handle_uptime(); handle_uptime();
}, },
nullptr, true); nullptr, true);
SerialPrint("I", F("Uptime"), F("Uptime Init"));
} }
void handle_uptime() { void handle_uptime() {

View File

@@ -9,7 +9,7 @@ static const char* firstLine PROGMEM = "Удалить;Тип элемента;I
void itemsListInit() { void itemsListInit() {
myNotAsyncActions->add( myNotAsyncActions->add(
do_deviceInit, [&](void*) { do_deviceInit, [&](void*) {
Device_init(); deviceInit();
}, },
nullptr); nullptr);
@@ -33,6 +33,7 @@ void itemsListInit() {
}, },
nullptr); nullptr);
#endif #endif
SerialPrint("I", F("Items"), F("Items Init"));
} }
void addItem(String name) { void addItem(String name) {

View File

@@ -75,6 +75,8 @@ void asyncUdpInit() {
//}, //},
//nullptr, true); //nullptr, true);
SerialPrint("I", F("UDP"), "Udp Init");
} }
bool udpPacketValidation(String& data) { bool udpPacketValidation(String& data) {

View File

@@ -47,6 +47,7 @@ void SsdpInit() {
SSDP.setDeviceType(F("upnp:rootdevice")); SSDP.setDeviceType(F("upnp:rootdevice"));
SSDP.setSchemaURL(F("description.xml")); SSDP.setSchemaURL(F("description.xml"));
SSDP.begin(); SSDP.begin();
SerialPrint("I", F("SSDP"), F("Ssdp Init"));
} }
String xmlNode(String tags, String data) { String xmlNode(String tags, String data) {

View File

@@ -20,10 +20,11 @@ void uartInit() {
myUART->begin(4, 5); myUART->begin(4, 5);
#endif #endif
} }
SerialPrint("I", F("UART"), F("UART Init"));
} }
void uartHandle() { void uartHandle() {
if (myUART != nullptr) { if (myUART) {
if (!jsonReadBool(configSetupJson, "uart")) { if (!jsonReadBool(configSetupJson, "uart")) {
return; return;
} }
@@ -46,7 +47,7 @@ void parse(String& incStr) {
incStr.replace("\n", ""); incStr.replace("\n", "");
if (incStr.indexOf("set") != -1) { if (incStr.indexOf("set") != -1) {
incStr = deleteBeforeDelimiter(incStr, " "); incStr = deleteBeforeDelimiter(incStr, " ");
SerialPrint("I", "UART", incStr);
orderBuf += incStr; orderBuf += incStr;
SerialPrint("I", "=>UART", incStr);
} }
} }

View File

@@ -19,6 +19,7 @@ void telegramInit() {
else { else {
SerialPrint("E", "Telegram", "Not connected"); SerialPrint("E", "Telegram", "Not connected");
} }
SerialPrint("I", F("Telegram"), F("Telegram Init"));
} }
} }

View File

@@ -31,6 +31,7 @@ void upgradeInit() {
} }
} }
}; };
SerialPrint("I", F("Update"), F("Updater Init"));
} }
void getLastVersion() { void getLastVersion() {

View File

@@ -10,9 +10,10 @@ const String filepath(const String& filename) {
bool fileSystemInit() { bool fileSystemInit() {
if (!LittleFS.begin()) { if (!LittleFS.begin()) {
SerialPrint("[E]","Files","init"); SerialPrint("E", F("FS"), F("FS Init ERROR, may be FS was not flashed"));
return false; return false;
} }
SerialPrint("I", F("FS"), F("FS Init"));
return true; return true;
} }

View File

@@ -2,8 +2,8 @@
#include "Global.h" #include "Global.h"
#include "Utils/StringUtils.h" #include "Utils/StringUtils.h"
static const uint8_t days_in_month[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; static const uint8_t days_in_month[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
static const char* week_days[7] = {"Sun", "Mon", "Tue", "Wed", "Thr", "Fri", "Sat"}; static const char* week_days[7] = { "Sun", "Mon", "Tue", "Wed", "Thr", "Fri", "Sat" };
// String getTimeUnix() { // String getTimeUnix() {
// time_t t; // time_t t;
@@ -118,7 +118,8 @@ const String prettySeconds(unsigned long time_s) {
if (days) { if (days) {
sprintf_P(buf, TIME_FORMAT_WITH_DAYS, days, hours, minutes, seconds); sprintf_P(buf, TIME_FORMAT_WITH_DAYS, days, hours, minutes, seconds);
} else { }
else {
sprintf_P(buf, TIME_FORMAT, hours, minutes, seconds); sprintf_P(buf, TIME_FORMAT, hours, minutes, seconds);
} }
return String(buf); return String(buf);
@@ -138,15 +139,18 @@ unsigned long millis_passed(unsigned long start, unsigned long finish) {
unsigned long passed = finish - start; unsigned long passed = finish - start;
if (passed <= __LONG_MAX__) { if (passed <= __LONG_MAX__) {
result = static_cast<long>(passed); result = static_cast<long>(passed);
} else { }
else {
result = static_cast<long>((__LONG_MAX__ - finish) + start + 1u); result = static_cast<long>((__LONG_MAX__ - finish) + start + 1u);
} }
} else { }
else {
unsigned long passed = start - finish; unsigned long passed = start - finish;
if (passed <= __LONG_MAX__) { if (passed <= __LONG_MAX__) {
result = static_cast<long>(passed); result = static_cast<long>(passed);
result = -1 * result; result = -1 * result;
} else { }
else {
result = static_cast<long>((__LONG_MAX__ - start) + finish + 1u); result = static_cast<long>((__LONG_MAX__ - start) + finish + 1u);
result = -1 * result; result = -1 * result;
} }
@@ -194,16 +198,19 @@ void breakEpochToTime(unsigned long epoch, Time_t& tm) {
if (1 == month) { // february if (1 == month) { // february
if (LEAP_YEAR(year)) { if (LEAP_YEAR(year)) {
month_length = 29; month_length = 29;
} else { }
else {
month_length = 28; month_length = 28;
} }
} else { }
else {
month_length = days_in_month[month]; month_length = days_in_month[month];
} }
if (time >= month_length) { if (time >= month_length) {
time -= month_length; time -= month_length;
} else { }
else {
break; break;
} }
} }
@@ -212,7 +219,7 @@ void breakEpochToTime(unsigned long epoch, Time_t& tm) {
tm.valid = (epoch > MIN_DATETIME); tm.valid = (epoch > MIN_DATETIME);
} }
void handle_time_init() { void timeInit() {
ts.add( ts.add(
TIME, 1000, [&](void*) { TIME, 1000, [&](void*) {
String timenow = timeNow->getTimeWOsec(); String timenow = timeNow->getTimeWOsec();
@@ -224,4 +231,5 @@ void handle_time_init() {
} }
}, },
nullptr, true); nullptr, true);
SerialPrint("I", F("Time"), F("Handle time init"));
} }

View File

@@ -8,7 +8,8 @@ String getURL(const String& urls) {
int httpCode = http.GET(); int httpCode = http.GET();
if (httpCode == HTTP_CODE_OK) { if (httpCode == HTTP_CODE_OK) {
res = http.getString(); res = http.getString();
} else { }
else {
res = "error"; res = "error";
} }
http.end(); http.end();
@@ -68,9 +69,11 @@ const String getRequestInfo(AsyncWebServerRequest* request) {
AsyncWebParameter* p = request->getParam(i); AsyncWebParameter* p = request->getParam(i);
if (p->isFile()) { if (p->isFile()) {
res += "FILE"; res += "FILE";
} else if (p->isPost()) { }
else if (p->isPost()) {
res += "POST"; res += "POST";
} else { }
else {
res += "GET"; res += "GET";
} }
res += ' '; res += ' ';
@@ -86,3 +89,34 @@ const String getRequestInfo(AsyncWebServerRequest* request) {
} }
return res; return res;
} }
void wifiSignalInit() {
ts.add(
SYGNAL, 1000 * 60, [&](void*) {
SerialPrint("I", "System", printMemoryStatus());
switch (RSSIquality()) {
case 0:
jsonWriteStr(configSetupJson, F("signal"), F("Уровень WiFi сигнала: <font color='red'>не подключено к роутеру</font>"));
break;
case 1:
jsonWriteStr(configSetupJson, F("signal"), F("Уровень WiFi сигнала: <font color='red'>нет сигнала</font>"));
break;
case 2:
jsonWriteStr(configSetupJson, F("signal"), F("Уровень WiFi сигнала: <font color='red'>очень низкий</font>"));
break;
case 3:
jsonWriteStr(configSetupJson, F("signal"), F("Уровень WiFi сигнала: <font color='orange'>низкий</font>"));
break;
case 4:
jsonWriteStr(configSetupJson, F("signal"), F("Уровень WiFi сигнала: <font color='green'>хороший</font>"));
break;
case 5:
jsonWriteStr(configSetupJson, F("signal"), F("Уровень WiFi сигнала: <font color='green'>очень хороший</font>"));
break;
case 6:
jsonWriteStr(configSetupJson, F("signal"), F("Уровень WiFi сигнала: <font color='green'>отличный</font>"));
break;
}
},
nullptr, true);
}

View File

@@ -1,13 +1,16 @@
#include "Utils/WiFiUtils.h" #include "Utils/WiFiUtils.h"
void routerConnect() { void routerConnect() {
WiFi.setAutoConnect(false);
WiFi.persistent(false);
setLedStatus(LED_SLOW); setLedStatus(LED_SLOW);
WiFi.mode(WIFI_STA); WiFi.mode(WIFI_STA);
byte tries = 20; byte tries = 20;
String _ssid = jsonReadStr(configSetupJson, "routerssid"); String _ssid = jsonReadStr(configSetupJson, "routerssid");
String _password = jsonReadStr(configSetupJson, "routerpass"); String _password = jsonReadStr(configSetupJson, "routerpass");
//WiFi.persistent(false);
if (_ssid == "" && _password == "") { if (_ssid == "" && _password == "") {
WiFi.begin(); WiFi.begin();
@@ -39,6 +42,7 @@ void routerConnect() {
setLedStatus(LED_OFF); setLedStatus(LED_OFF);
mqttInit(); mqttInit();
} }
SerialPrint("I", F("WIFI"), F("Network Init"));
} }
bool startAPMode() { bool startAPMode() {

View File

@@ -25,6 +25,7 @@ void initSt() {
}, },
nullptr, true); nullptr, true);
} }
SerialPrint("I", F("Stat"), F("Stat Init"));
} }
void decide() { void decide() {

View File

@@ -311,7 +311,7 @@ void web_init() {
// itemsLine = request->getParam("line")->value(); // itemsLine = request->getParam("line")->value();
// } // }
// delElementFlag = true; // delElementFlag = true;
// Device_init(); // deviceInit();
// request->redirect("/?setn.device"); // request->redirect("/?setn.device");
//}); //});
@@ -360,6 +360,8 @@ void web_init() {
myNotAsyncActions->make(do_UPGRADE); myNotAsyncActions->make(do_UPGRADE);
request->send(200, "text/html"); request->send(200, "text/html");
}); });
SerialPrint("I", F("Web"), F("WebAdmin Init"));
} }
void setConfigParam(const char* param, const String& value) { void setConfigParam(const char* param, const String& value) {

View File

@@ -75,6 +75,8 @@ void init() {
initOta(); initOta();
initMDNS(); initMDNS();
initWS(); initWS();
SerialPrint("I", F("HTTP"), F("HttpServer Init"));
} }
void onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventType type, void *arg, uint8_t *data, size_t len) { void onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventType type, void *arg, uint8_t *data, size_t len) {

View File

@@ -22,8 +22,10 @@ ButtonOut::~ButtonOut() {}
void ButtonOut::execute(String state) { void ButtonOut::execute(String state) {
if (_type == "UART") { if (_type == "UART") {
if (jsonReadBool(configSetupJson, "uart")) { if (jsonReadBool(configSetupJson, "uart")) {
if (myUART != nullptr) { if (myUART) {
myUART->print(_key + " " + state); String msg = _key + " " + state;
myUART->print(msg);
SerialPrint("I", "<=UART", msg);
} }
} }
} }

View File

@@ -29,116 +29,48 @@ Timings metric;
boolean initialized = false; boolean initialized = false;
void setup() { void setup() {
WiFi.setAutoConnect(false);
WiFi.persistent(false);
Serial.begin(115200); Serial.begin(115200);
Serial.flush(); Serial.flush();
Serial.println(); Serial.println();
Serial.println(F("--------------started----------------")); Serial.println(F("--------------started----------------"));
setChipId();
myNotAsyncActions = new NotAsync(do_LAST); myNotAsyncActions = new NotAsync(do_LAST);
myScenario = new Scenario(); myScenario = new Scenario();
//=========================================initialisation==============================================================
setChipId();
fileSystemInit(); fileSystemInit();
SerialPrint("I", F("FS"), F("FS Init"));
SerialPrint("I", F("UART"), F("UART Init"));
uartInit();
loadConfig(); loadConfig();
SerialPrint("I", F("Conf"), F("Config Init")); uartInit();
clockInit();
clock_init(); timeInit();
SerialPrint("I", F("Time"), F("Clock Init")); sensorsInit(); //Will be remooved
handle_time_init();
SerialPrint("I", F("Time"), F("Handle time init"));
sensorsInit();
SerialPrint("I", F("Sensors"), F("Sensors Init"));
itemsListInit(); itemsListInit();
SerialPrint("I", F("Items"), F("Items Init")); espInit();
all_init();
SerialPrint("I", F("Init"), F("Init Init"));
routerConnect(); routerConnect();
SerialPrint("I", F("WIFI"), F("Network Init"));
telegramInit(); telegramInit();
SerialPrint("I", F("Telegram"), F("Telegram Init"));
uptime_init(); uptime_init();
SerialPrint("I", F("Uptime"), F("Uptime Init"));
upgradeInit(); upgradeInit();
SerialPrint("I", F("Update"), F("Updater Init"));
HttpServer::init(); HttpServer::init();
SerialPrint("I", F("HTTP"), F("HttpServer Init"));
web_init(); web_init();
SerialPrint("I", F("Web"), F("WebAdmin Init"));
initSt(); initSt();
SerialPrint("I", F("Stat"), F("Stat Init")); busInit();
#ifdef UDP_ENABLED #ifdef UDP_ENABLED
SerialPrint("I", F("UDP"), "Udp Init");
asyncUdpInit(); asyncUdpInit();
#endif #endif
SerialPrint("I", F("Bus"), F("Bus Init"));
busInit();
#ifdef SSDP_ENABLED #ifdef SSDP_ENABLED
SerialPrint("I", F("SSDP"), F("Ssdp Init"));
SsdpInit(); SsdpInit();
#endif #endif
//esp_log_level_set("esp_littlefs", ESP_LOG_NONE); //esp_log_level_set("esp_littlefs", ESP_LOG_NONE);
ts.add(
SYGNAL, 1000 * 60, [&](void*) {
SerialPrint("I", "System", printMemoryStatus());
switch (RSSIquality()) {
case 0:
jsonWriteStr(configSetupJson, F("signal"), F("Уровень WiFi сигнала: <font color='red'>не подключено к роутеру</font>"));
break;
case 1:
jsonWriteStr(configSetupJson, F("signal"), F("Уровень WiFi сигнала: <font color='red'>нет сигнала</font>"));
break;
case 2:
jsonWriteStr(configSetupJson, F("signal"), F("Уровень WiFi сигнала: <font color='red'>очень низкий</font>"));
break;
case 3:
jsonWriteStr(configSetupJson, F("signal"), F("Уровень WiFi сигнала: <font color='orange'>низкий</font>"));
break;
case 4:
jsonWriteStr(configSetupJson, F("signal"), F("Уровень WiFi сигнала: <font color='green'>хороший</font>"));
break;
case 5:
jsonWriteStr(configSetupJson, F("signal"), F("Уровень WiFi сигнала: <font color='green'>очень хороший</font>"));
break;
case 6:
jsonWriteStr(configSetupJson, F("signal"), F("Уровень WiFi сигнала: <font color='green'>отличный</font>"));
break;
}
},
nullptr, true);
just_load = false; just_load = false;
initialized = true; initialized = true;
} }
void loop() { void loop() {
if (!initialized) { if (!initialized) {
return; return;
@@ -154,7 +86,6 @@ void loop() {
myButtonIn.loop(); myButtonIn.loop();
myScenario->loop(); myScenario->loop();
loopCmdExecute(); loopCmdExecute();
//loopSerial();
myNotAsyncActions->loop(); myNotAsyncActions->loop();
ts.update(); ts.update();