mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 14:12:16 +03:00
uart working version
This commit is contained in:
@@ -43,7 +43,7 @@
|
||||
},
|
||||
{
|
||||
"type": "h4",
|
||||
"title": "Версия файловой системы: 268"
|
||||
"title": "Версия файловой системы: 270"
|
||||
},
|
||||
{
|
||||
"type": "h4",
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include "Utils/TimeUtils.h"
|
||||
#include "Utils\SerialPrint.h"
|
||||
|
||||
extern void clock_init();
|
||||
extern void clockInit();
|
||||
|
||||
#ifdef ESP8266
|
||||
#include "sntp.h"
|
||||
|
||||
@@ -42,7 +42,7 @@ extern void bme280A_reading();
|
||||
//extern void dhtC_reading();
|
||||
//extern void dhtD_reading();
|
||||
|
||||
extern void handle_time_init();
|
||||
extern void timeInit();
|
||||
extern void stepper();
|
||||
extern void stepperSet();
|
||||
extern void servo_();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
//===========Firmware=============================================================================================================================================
|
||||
#define FIRMWARE_VERSION 268
|
||||
#define FIRMWARE_VERSION 270
|
||||
//#define FLASH_SIZE_1MB
|
||||
#ifdef ESP8266
|
||||
#define FIRMWARE_NAME "esp8266-iotm"
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
extern void loadConfig();
|
||||
extern void all_init();
|
||||
extern void espInit();
|
||||
extern void statistics_init();
|
||||
extern void loadScenario();
|
||||
extern void Device_init();
|
||||
extern void deviceInit();
|
||||
extern void prsets_init();
|
||||
extern void handle_uptime();
|
||||
extern void handle_statistics();
|
||||
|
||||
@@ -50,4 +50,4 @@ int getOffsetInMinutes(int timezone);
|
||||
*/
|
||||
void breakEpochToTime(unsigned long epoch, Time_t& tm);
|
||||
|
||||
void handle_time_init();
|
||||
void timeInit();
|
||||
@@ -4,4 +4,5 @@
|
||||
|
||||
extern String getURL(const String& urls);
|
||||
extern const String getMethodName(AsyncWebServerRequest* request);
|
||||
extern const String getRequestInfo(AsyncWebServerRequest* request);
|
||||
extern const String getRequestInfo(AsyncWebServerRequest* request);
|
||||
extern void wifiSignalInit();
|
||||
@@ -144,6 +144,7 @@ void sensorsInit() {
|
||||
}
|
||||
},
|
||||
nullptr, true);
|
||||
SerialPrint("I", F("Sensors"), F("Sensors Init"));
|
||||
}
|
||||
|
||||
void addKey(String& key, String& keyNumberTable, int number) {
|
||||
|
||||
@@ -10,12 +10,14 @@ void busInit() {
|
||||
tmp = i2c_scan();
|
||||
Serial.println(tmp);
|
||||
jsonWriteStr(configLiveJson, "i2c", tmp);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
Serial.println(tmp);
|
||||
jsonWriteStr(configLiveJson, "i2c", tmp);
|
||||
}
|
||||
},
|
||||
nullptr);
|
||||
SerialPrint("I", F("Bus"), F("Bus Init"));
|
||||
}
|
||||
|
||||
String i2c_scan() {
|
||||
@@ -32,7 +34,8 @@ String i2c_scan() {
|
||||
}
|
||||
if (count == 0) {
|
||||
return "error";
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
return out;
|
||||
}
|
||||
}
|
||||
@@ -3,14 +3,14 @@
|
||||
#include "Global.h"
|
||||
|
||||
Clock* timeNow;
|
||||
void clock_init() {
|
||||
void clockInit() {
|
||||
timeNow = new Clock;
|
||||
timeNow->setNtpPool(jsonReadStr(configSetupJson, "ntp"));
|
||||
timeNow->setTimezone(jsonReadStr(configSetupJson, "timezone").toInt());
|
||||
|
||||
ts.add(
|
||||
TIME_SYNC, 30000, [&](void*) {
|
||||
timeNow->hasSync();
|
||||
},
|
||||
nullptr, true);
|
||||
SerialPrint("I", F("Time"), F("Clock Init"));
|
||||
}
|
||||
|
||||
12
src/Init.cpp
12
src/Init.cpp
@@ -26,17 +26,20 @@ void loadConfig() {
|
||||
|
||||
prex = jsonReadStr(configSetupJson, "mqttPrefix") + "/" + chipId;
|
||||
|
||||
Serial.println(configSetupJson);
|
||||
//Serial.println(configSetupJson);
|
||||
|
||||
serverIP = jsonReadStr(configSetupJson, "serverip");
|
||||
|
||||
SerialPrint("I", F("Conf"), F("Config Json Init"));
|
||||
}
|
||||
|
||||
void all_init() {
|
||||
Device_init();
|
||||
void espInit() {
|
||||
deviceInit();
|
||||
loadScenario();
|
||||
SerialPrint("I", F("esp"), F("esp Init"));
|
||||
}
|
||||
|
||||
void Device_init() {
|
||||
void deviceInit() {
|
||||
|
||||
sensorReadingMap10sec = "";
|
||||
|
||||
@@ -110,6 +113,7 @@ void uptime_init() {
|
||||
handle_uptime();
|
||||
},
|
||||
nullptr, true);
|
||||
SerialPrint("I", F("Uptime"), F("Uptime Init"));
|
||||
}
|
||||
|
||||
void handle_uptime() {
|
||||
|
||||
@@ -9,7 +9,7 @@ static const char* firstLine PROGMEM = "Удалить;Тип элемента;I
|
||||
void itemsListInit() {
|
||||
myNotAsyncActions->add(
|
||||
do_deviceInit, [&](void*) {
|
||||
Device_init();
|
||||
deviceInit();
|
||||
},
|
||||
nullptr);
|
||||
|
||||
@@ -33,6 +33,7 @@ void itemsListInit() {
|
||||
},
|
||||
nullptr);
|
||||
#endif
|
||||
SerialPrint("I", F("Items"), F("Items Init"));
|
||||
}
|
||||
|
||||
void addItem(String name) {
|
||||
|
||||
@@ -75,6 +75,8 @@ void asyncUdpInit() {
|
||||
//},
|
||||
//nullptr, true);
|
||||
|
||||
SerialPrint("I", F("UDP"), "Udp Init");
|
||||
|
||||
}
|
||||
|
||||
bool udpPacketValidation(String& data) {
|
||||
|
||||
@@ -47,6 +47,7 @@ void SsdpInit() {
|
||||
SSDP.setDeviceType(F("upnp:rootdevice"));
|
||||
SSDP.setSchemaURL(F("description.xml"));
|
||||
SSDP.begin();
|
||||
SerialPrint("I", F("SSDP"), F("Ssdp Init"));
|
||||
}
|
||||
|
||||
String xmlNode(String tags, String data) {
|
||||
|
||||
@@ -20,10 +20,11 @@ void uartInit() {
|
||||
myUART->begin(4, 5);
|
||||
#endif
|
||||
}
|
||||
SerialPrint("I", F("UART"), F("UART Init"));
|
||||
}
|
||||
|
||||
void uartHandle() {
|
||||
if (myUART != nullptr) {
|
||||
if (myUART) {
|
||||
if (!jsonReadBool(configSetupJson, "uart")) {
|
||||
return;
|
||||
}
|
||||
@@ -34,7 +35,7 @@ void uartHandle() {
|
||||
incStr += inc;
|
||||
if (inc == '\n') {
|
||||
parse(incStr);
|
||||
incStr = "";
|
||||
incStr = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -46,7 +47,7 @@ void parse(String& incStr) {
|
||||
incStr.replace("\n", "");
|
||||
if (incStr.indexOf("set") != -1) {
|
||||
incStr = deleteBeforeDelimiter(incStr, " ");
|
||||
SerialPrint("I", "UART", incStr);
|
||||
orderBuf += incStr;
|
||||
SerialPrint("I", "=>UART", incStr);
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@ void telegramInit() {
|
||||
else {
|
||||
SerialPrint("E", "Telegram", "Not connected");
|
||||
}
|
||||
SerialPrint("I", F("Telegram"), F("Telegram Init"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ void upgradeInit() {
|
||||
}
|
||||
}
|
||||
};
|
||||
SerialPrint("I", F("Update"), F("Updater Init"));
|
||||
}
|
||||
|
||||
void getLastVersion() {
|
||||
|
||||
@@ -10,9 +10,10 @@ const String filepath(const String& filename) {
|
||||
|
||||
bool fileSystemInit() {
|
||||
if (!LittleFS.begin()) {
|
||||
SerialPrint("[E]","Files","init");
|
||||
SerialPrint("E", F("FS"), F("FS Init ERROR, may be FS was not flashed"));
|
||||
return false;
|
||||
}
|
||||
SerialPrint("I", F("FS"), F("FS Init"));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
#include "Global.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 char* week_days[7] = {"Sun", "Mon", "Tue", "Wed", "Thr", "Fri", "Sat"};
|
||||
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" };
|
||||
|
||||
// String getTimeUnix() {
|
||||
// time_t t;
|
||||
@@ -118,7 +118,8 @@ const String prettySeconds(unsigned long time_s) {
|
||||
|
||||
if (days) {
|
||||
sprintf_P(buf, TIME_FORMAT_WITH_DAYS, days, hours, minutes, seconds);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
sprintf_P(buf, TIME_FORMAT, hours, minutes, seconds);
|
||||
}
|
||||
return String(buf);
|
||||
@@ -138,15 +139,18 @@ unsigned long millis_passed(unsigned long start, unsigned long finish) {
|
||||
unsigned long passed = finish - start;
|
||||
if (passed <= __LONG_MAX__) {
|
||||
result = static_cast<long>(passed);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
result = static_cast<long>((__LONG_MAX__ - finish) + start + 1u);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
unsigned long passed = start - finish;
|
||||
if (passed <= __LONG_MAX__) {
|
||||
result = static_cast<long>(passed);
|
||||
result = -1 * result;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
result = static_cast<long>((__LONG_MAX__ - start) + finish + 1u);
|
||||
result = -1 * result;
|
||||
}
|
||||
@@ -194,16 +198,19 @@ void breakEpochToTime(unsigned long epoch, Time_t& tm) {
|
||||
if (1 == month) { // february
|
||||
if (LEAP_YEAR(year)) {
|
||||
month_length = 29;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
month_length = 28;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
month_length = days_in_month[month];
|
||||
}
|
||||
|
||||
if (time >= month_length) {
|
||||
time -= month_length;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -212,7 +219,7 @@ void breakEpochToTime(unsigned long epoch, Time_t& tm) {
|
||||
tm.valid = (epoch > MIN_DATETIME);
|
||||
}
|
||||
|
||||
void handle_time_init() {
|
||||
void timeInit() {
|
||||
ts.add(
|
||||
TIME, 1000, [&](void*) {
|
||||
String timenow = timeNow->getTimeWOsec();
|
||||
@@ -224,4 +231,5 @@ void handle_time_init() {
|
||||
}
|
||||
},
|
||||
nullptr, true);
|
||||
SerialPrint("I", F("Time"), F("Handle time init"));
|
||||
}
|
||||
|
||||
@@ -8,7 +8,8 @@ String getURL(const String& urls) {
|
||||
int httpCode = http.GET();
|
||||
if (httpCode == HTTP_CODE_OK) {
|
||||
res = http.getString();
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
res = "error";
|
||||
}
|
||||
http.end();
|
||||
@@ -68,9 +69,11 @@ const String getRequestInfo(AsyncWebServerRequest* request) {
|
||||
AsyncWebParameter* p = request->getParam(i);
|
||||
if (p->isFile()) {
|
||||
res += "FILE";
|
||||
} else if (p->isPost()) {
|
||||
}
|
||||
else if (p->isPost()) {
|
||||
res += "POST";
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
res += "GET";
|
||||
}
|
||||
res += ' ';
|
||||
@@ -86,3 +89,34 @@ const String getRequestInfo(AsyncWebServerRequest* request) {
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
#include "Utils/WiFiUtils.h"
|
||||
|
||||
void routerConnect() {
|
||||
|
||||
WiFi.setAutoConnect(false);
|
||||
WiFi.persistent(false);
|
||||
|
||||
setLedStatus(LED_SLOW);
|
||||
WiFi.mode(WIFI_STA);
|
||||
byte tries = 20;
|
||||
|
||||
String _ssid = jsonReadStr(configSetupJson, "routerssid");
|
||||
String _password = jsonReadStr(configSetupJson, "routerpass");
|
||||
//WiFi.persistent(false);
|
||||
|
||||
if (_ssid == "" && _password == "") {
|
||||
WiFi.begin();
|
||||
@@ -39,6 +42,7 @@ void routerConnect() {
|
||||
setLedStatus(LED_OFF);
|
||||
mqttInit();
|
||||
}
|
||||
SerialPrint("I", F("WIFI"), F("Network Init"));
|
||||
}
|
||||
|
||||
bool startAPMode() {
|
||||
|
||||
@@ -25,6 +25,7 @@ void initSt() {
|
||||
},
|
||||
nullptr, true);
|
||||
}
|
||||
SerialPrint("I", F("Stat"), F("Stat Init"));
|
||||
}
|
||||
|
||||
void decide() {
|
||||
|
||||
@@ -311,7 +311,7 @@ void web_init() {
|
||||
// itemsLine = request->getParam("line")->value();
|
||||
// }
|
||||
// delElementFlag = true;
|
||||
// Device_init();
|
||||
// deviceInit();
|
||||
// request->redirect("/?setn.device");
|
||||
//});
|
||||
|
||||
@@ -360,6 +360,8 @@ void web_init() {
|
||||
myNotAsyncActions->make(do_UPGRADE);
|
||||
request->send(200, "text/html");
|
||||
});
|
||||
|
||||
SerialPrint("I", F("Web"), F("WebAdmin Init"));
|
||||
}
|
||||
|
||||
void setConfigParam(const char* param, const String& value) {
|
||||
|
||||
@@ -75,6 +75,8 @@ void init() {
|
||||
initOta();
|
||||
initMDNS();
|
||||
initWS();
|
||||
|
||||
SerialPrint("I", F("HTTP"), F("HttpServer Init"));
|
||||
}
|
||||
|
||||
void onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventType type, void *arg, uint8_t *data, size_t len) {
|
||||
|
||||
@@ -22,8 +22,10 @@ ButtonOut::~ButtonOut() {}
|
||||
void ButtonOut::execute(String state) {
|
||||
if (_type == "UART") {
|
||||
if (jsonReadBool(configSetupJson, "uart")) {
|
||||
if (myUART != nullptr) {
|
||||
myUART->print(_key + " " + state);
|
||||
if (myUART) {
|
||||
String msg = _key + " " + state;
|
||||
myUART->print(msg);
|
||||
SerialPrint("I", "<=UART", msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
91
src/main.cpp
91
src/main.cpp
@@ -29,116 +29,48 @@ Timings metric;
|
||||
boolean initialized = false;
|
||||
|
||||
void setup() {
|
||||
WiFi.setAutoConnect(false);
|
||||
WiFi.persistent(false);
|
||||
|
||||
Serial.begin(115200);
|
||||
Serial.flush();
|
||||
Serial.println();
|
||||
Serial.println(F("--------------started----------------"));
|
||||
|
||||
setChipId();
|
||||
|
||||
myNotAsyncActions = new NotAsync(do_LAST);
|
||||
myScenario = new Scenario();
|
||||
|
||||
//=========================================initialisation==============================================================
|
||||
setChipId();
|
||||
fileSystemInit();
|
||||
SerialPrint("I", F("FS"), F("FS Init"));
|
||||
|
||||
SerialPrint("I", F("UART"), F("UART Init"));
|
||||
uartInit();
|
||||
|
||||
loadConfig();
|
||||
SerialPrint("I", F("Conf"), F("Config Init"));
|
||||
|
||||
clock_init();
|
||||
SerialPrint("I", F("Time"), F("Clock Init"));
|
||||
|
||||
handle_time_init();
|
||||
SerialPrint("I", F("Time"), F("Handle time init"));
|
||||
|
||||
sensorsInit();
|
||||
SerialPrint("I", F("Sensors"), F("Sensors Init"));
|
||||
|
||||
uartInit();
|
||||
clockInit();
|
||||
timeInit();
|
||||
sensorsInit(); //Will be remooved
|
||||
itemsListInit();
|
||||
SerialPrint("I", F("Items"), F("Items Init"));
|
||||
|
||||
all_init();
|
||||
SerialPrint("I", F("Init"), F("Init Init"));
|
||||
|
||||
espInit();
|
||||
routerConnect();
|
||||
SerialPrint("I", F("WIFI"), F("Network Init"));
|
||||
|
||||
telegramInit();
|
||||
SerialPrint("I", F("Telegram"), F("Telegram Init"));
|
||||
|
||||
uptime_init();
|
||||
SerialPrint("I", F("Uptime"), F("Uptime Init"));
|
||||
|
||||
upgradeInit();
|
||||
SerialPrint("I", F("Update"), F("Updater Init"));
|
||||
|
||||
HttpServer::init();
|
||||
SerialPrint("I", F("HTTP"), F("HttpServer Init"));
|
||||
|
||||
web_init();
|
||||
SerialPrint("I", F("Web"), F("WebAdmin Init"));
|
||||
|
||||
initSt();
|
||||
SerialPrint("I", F("Stat"), F("Stat Init"));
|
||||
|
||||
busInit();
|
||||
#ifdef UDP_ENABLED
|
||||
SerialPrint("I", F("UDP"), "Udp Init");
|
||||
asyncUdpInit();
|
||||
#endif
|
||||
|
||||
SerialPrint("I", F("Bus"), F("Bus Init"));
|
||||
busInit();
|
||||
|
||||
|
||||
|
||||
#ifdef SSDP_ENABLED
|
||||
SerialPrint("I", F("SSDP"), F("Ssdp Init"));
|
||||
SsdpInit();
|
||||
#endif
|
||||
|
||||
//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;
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void loop() {
|
||||
if (!initialized) {
|
||||
return;
|
||||
@@ -154,7 +86,6 @@ void loop() {
|
||||
myButtonIn.loop();
|
||||
myScenario->loop();
|
||||
loopCmdExecute();
|
||||
//loopSerial();
|
||||
|
||||
myNotAsyncActions->loop();
|
||||
ts.update();
|
||||
|
||||
Reference in New Issue
Block a user