mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-30 20:09:14 +03:00
LittleFS, and some mprovements
This commit is contained in:
@@ -43,7 +43,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "h4",
|
"type": "h4",
|
||||||
"title": "SPIFFS version: 2.3.4"
|
"title": "LittleFS version: 2.3.4"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "hr"
|
"type": "hr"
|
||||||
@@ -109,7 +109,6 @@
|
|||||||
"action": "/set?sceninit",
|
"action": "/set?sceninit",
|
||||||
"class": "btn btn-block btn-default"
|
"class": "btn btn-block btn-default"
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
"type": "link",
|
"type": "link",
|
||||||
"title": "Инструкция к системе автоматизации",
|
"title": "Инструкция к системе автоматизации",
|
||||||
@@ -131,7 +130,6 @@
|
|||||||
"style": "position:fixed;top:50%;left:50%;width:400px;margin-left:-200px;text-align:center;",
|
"style": "position:fixed;top:50%;left:50%;width:400px;margin-left:-200px;text-align:center;",
|
||||||
"class": "hidden"
|
"class": "hidden"
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
"type": "button",
|
"type": "button",
|
||||||
"title": "Обновить прошивку устройства",
|
"title": "Обновить прошивку устройства",
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
#include <ESP32Servo.h>
|
#include <ESP32Servo.h>
|
||||||
#include <HTTPClient.h>
|
#include <HTTPClient.h>
|
||||||
#include <HTTPUpdate.h>
|
#include <HTTPUpdate.h>
|
||||||
#include <SPIFFS.h>
|
#include <LittleFS.h>
|
||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
#include <analogWrite.h>
|
#include <analogWrite.h>
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
#include <ESP8266HTTPUpdateServer.h>
|
#include <ESP8266HTTPUpdateServer.h>
|
||||||
#include <ESPAsyncWebServer.h>
|
#include <ESPAsyncWebServer.h>
|
||||||
|
#include <LittleFS.h>
|
||||||
#include <SPIFFSEditor.h>
|
#include <SPIFFSEditor.h>
|
||||||
|
|
||||||
#include "Consts.h"
|
#include "Consts.h"
|
||||||
@@ -56,9 +57,6 @@ extern AsyncWebServer server;
|
|||||||
|
|
||||||
extern DallasTemperature sensors;
|
extern DallasTemperature sensors;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Global vars
|
* Global vars
|
||||||
*/
|
*/
|
||||||
@@ -82,14 +80,13 @@ enum { ROUTER_SEARCHING,
|
|||||||
UDP_DB,
|
UDP_DB,
|
||||||
TEST };
|
TEST };
|
||||||
|
|
||||||
|
|
||||||
extern boolean just_load;
|
extern boolean just_load;
|
||||||
|
|
||||||
extern String configSetupJson; //все настройки
|
extern String configSetupJson; //все настройки
|
||||||
extern String configLiveJson; //все данные с датчиков (связан с mqtt)
|
extern String configLiveJson; //все данные с датчиков (связан с mqtt)
|
||||||
extern String configOptionJson; //для трансфера
|
extern String configOptionJson; //для трансфера
|
||||||
|
|
||||||
extern String chipID;
|
extern String chipId;
|
||||||
extern String prex;
|
extern String prex;
|
||||||
extern String all_widgets;
|
extern String all_widgets;
|
||||||
extern String scenario;
|
extern String scenario;
|
||||||
@@ -187,6 +184,7 @@ extern void clean_log_date();
|
|||||||
extern void choose_log_date_and_send();
|
extern void choose_log_date_and_send();
|
||||||
|
|
||||||
// Main
|
// Main
|
||||||
|
extern void setChipId();
|
||||||
extern void getMemoryLoad(String text);
|
extern void getMemoryLoad(String text);
|
||||||
extern void saveConfig();
|
extern void saveConfig();
|
||||||
extern String getURL(const String &urls);
|
extern String getURL(const String &urls);
|
||||||
|
|||||||
@@ -7,24 +7,24 @@
|
|||||||
* Чтение строки из файла
|
* Чтение строки из файла
|
||||||
* возвращает стоку из файла в которой есть искомое слово found
|
* возвращает стоку из файла в которой есть искомое слово found
|
||||||
*/
|
*/
|
||||||
String readFileString(const String& filename, const String& str_to_found);
|
String readFileString(const String filename, const String to_find);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Добовление строки в файл
|
* Добовление строки в файл
|
||||||
*/
|
*/
|
||||||
String addFile(const String& fileName, const String& str);
|
String addFile(const String filename, const String str);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Запись строки в файл
|
* Запись строки в файл
|
||||||
*/
|
*/
|
||||||
String writeFile(const String& fileName, const String& str);
|
String writeFile(const String filename, const String str);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Чтение файла в строку
|
* Чтение файла в строку
|
||||||
*/
|
*/
|
||||||
String readFile(const String& fileName, size_t len);
|
String readFile(const String filename, size_t max_size);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Размер файла
|
* Размер файла
|
||||||
*/
|
*/
|
||||||
String sizeFile(const String& fileName);
|
String getFileSize(const String filename);
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
#include <TZ.h>
|
||||||
|
|
||||||
void Time_Init();
|
void Time_Init();
|
||||||
|
|
||||||
@@ -23,11 +24,14 @@ String getTimeUnix();
|
|||||||
*/
|
*/
|
||||||
boolean getUnixTimeStr(String&);
|
boolean getUnixTimeStr(String&);
|
||||||
|
|
||||||
String GetTimeWOsec();
|
String getTimeWOsec();
|
||||||
|
|
||||||
String GetDate();
|
/*
|
||||||
|
* Получение даты
|
||||||
|
*/
|
||||||
|
String getDate();
|
||||||
|
|
||||||
String GetDataDigital();
|
String getDateDigitalFormated();
|
||||||
|
|
||||||
int timeToMin(String Time);
|
int timeToMin(String Time);
|
||||||
|
|
||||||
|
|||||||
@@ -1,24 +1,26 @@
|
|||||||
#ifndef SPIFFSEditor_H_
|
#ifndef SPIFFSEditor_H_
|
||||||
#define SPIFFSEditor_H_
|
#define SPIFFSEditor_H_
|
||||||
#include <ESPAsyncWebServer.h>
|
#include <ESPAsyncWebServer.h>
|
||||||
|
#include <LittleFS.h>
|
||||||
|
|
||||||
class SPIFFSEditor: public AsyncWebHandler {
|
class SPIFFSEditor : public AsyncWebHandler {
|
||||||
private:
|
private:
|
||||||
fs::FS _fs;
|
fs::FS _fs;
|
||||||
String _username;
|
String _username;
|
||||||
String _password;
|
String _password;
|
||||||
bool _authenticated;
|
bool _authenticated;
|
||||||
uint32_t _startTime;
|
uint32_t _startTime;
|
||||||
public:
|
|
||||||
|
public:
|
||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
SPIFFSEditor(const fs::FS& fs, const String& username=String(), const String& password=String());
|
SPIFFSEditor(const fs::FS& fs, const String& username = String(), const String& password = String());
|
||||||
#else
|
#else
|
||||||
SPIFFSEditor(const String& username=String(), const String& password=String(), const fs::FS& fs=SPIFFS);
|
SPIFFSEditor(const String& username = String(), const String& password = String(), const fs::FS& fs = LittleFS);
|
||||||
#endif
|
#endif
|
||||||
virtual bool canHandle(AsyncWebServerRequest *request) override final;
|
virtual bool canHandle(AsyncWebServerRequest* request) override final;
|
||||||
virtual void handleRequest(AsyncWebServerRequest *request) override final;
|
virtual void handleRequest(AsyncWebServerRequest* request) override final;
|
||||||
virtual void handleUpload(AsyncWebServerRequest *request, const String& filename, size_t index, uint8_t *data, size_t len, bool final) override final;
|
virtual void handleUpload(AsyncWebServerRequest* request, const String& filename, size_t index, uint8_t* data, size_t len, bool final) override final;
|
||||||
virtual bool isRequestHandlerTrivial() override final {return false;}
|
virtual bool isRequestHandlerTrivial() override final { return false; }
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -274,12 +274,14 @@ void inputDigit() {
|
|||||||
jsonWriteStr(configLiveJson, "digit" + number, start_state);
|
jsonWriteStr(configLiveJson, "digit" + number, start_state);
|
||||||
createWidget(widget_name, page_name, page_number, "widgets/widget.inputNum.json", "digit" + number);
|
createWidget(widget_name, page_name, page_number, "widgets/widget.inputNum.json", "digit" + number);
|
||||||
}
|
}
|
||||||
|
|
||||||
void digitSet() {
|
void digitSet() {
|
||||||
String number = sCmd.next();
|
String number = sCmd.next();
|
||||||
String value = sCmd.next();
|
String value = sCmd.next();
|
||||||
jsonWriteStr(configLiveJson, "digit" + number, value);
|
jsonWriteStr(configLiveJson, "digit" + number, value);
|
||||||
sendSTATUS("digit" + number, value);
|
sendSTATUS("digit" + number, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
//=====================================================================================================================================
|
//=====================================================================================================================================
|
||||||
//=========================================Добавление окна ввода времени===============================================================
|
//=========================================Добавление окна ввода времени===============================================================
|
||||||
void inputTime() {
|
void inputTime() {
|
||||||
@@ -294,6 +296,7 @@ void inputTime() {
|
|||||||
jsonWriteStr(configLiveJson, "time" + number, start_state);
|
jsonWriteStr(configLiveJson, "time" + number, start_state);
|
||||||
createWidget(widget_name, page_name, page_number, "widgets/widget.inputTime.json", "time" + number);
|
createWidget(widget_name, page_name, page_number, "widgets/widget.inputTime.json", "time" + number);
|
||||||
}
|
}
|
||||||
|
|
||||||
void timeSet() {
|
void timeSet() {
|
||||||
String number = sCmd.next();
|
String number = sCmd.next();
|
||||||
String value = sCmd.next();
|
String value = sCmd.next();
|
||||||
@@ -334,7 +337,7 @@ void textSet() {
|
|||||||
text.replace("#", " ");
|
text.replace("#", " ");
|
||||||
String time = getTime();
|
String time = getTime();
|
||||||
time.replace(":", ".");
|
time.replace(":", ".");
|
||||||
text = text + " " + GetDataDigital() + " " + time;
|
text = text + " " + getDateDigitalFormated() + " " + time;
|
||||||
}
|
}
|
||||||
|
|
||||||
jsonWriteStr(configLiveJson, "text" + number, text);
|
jsonWriteStr(configLiveJson, "text" + number, text);
|
||||||
|
|||||||
@@ -1,40 +0,0 @@
|
|||||||
#include "Global.h"
|
|
||||||
|
|
||||||
void File_system_init() {
|
|
||||||
|
|
||||||
Serial.begin(115200);
|
|
||||||
//Serial.setDebugOutput(true);
|
|
||||||
Serial.println("--------------started----------------");
|
|
||||||
//--------------------------------------------------------------
|
|
||||||
SPIFFS.begin();
|
|
||||||
configSetupJson = readFile("config.json", 4096);
|
|
||||||
configSetupJson.replace(" ", "");
|
|
||||||
configSetupJson.replace("\r\n", "");
|
|
||||||
Serial.println(configSetupJson);
|
|
||||||
//jsonWriteStr(configLiveJson, "name", jsonReadStr(configSetupJson, "name"));
|
|
||||||
//jsonWriteStr(configLiveJson, "lang", jsonReadStr(configSetupJson, "lang"));
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef ESP32
|
|
||||||
uint32_t chipID_u = ESP.getEfuseMac();
|
|
||||||
chipID = String(chipID_u);
|
|
||||||
jsonWriteStr(configSetupJson, "chipID", chipID);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef ESP8266
|
|
||||||
chipID = String( ESP.getChipId() ) + "-" + String(ESP.getFlashChipId());
|
|
||||||
jsonWriteStr(configSetupJson, "chipID", chipID);
|
|
||||||
Serial.setDebugOutput(0);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
jsonWriteStr(configSetupJson, "firmware_version", firmware_version);
|
|
||||||
|
|
||||||
prex = jsonReadStr(configSetupJson, "mqttPrefix") + "/" + chipID;
|
|
||||||
Serial.println(chipID);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void get_esp_info() {
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -11,6 +11,8 @@ AsyncWebSocket ws;
|
|||||||
|
|
||||||
TickerScheduler ts(TEST + 1);
|
TickerScheduler ts(TEST + 1);
|
||||||
|
|
||||||
|
WiFiClient espClient;
|
||||||
|
|
||||||
PubSubClient client_mqtt(espClient);
|
PubSubClient client_mqtt(espClient);
|
||||||
|
|
||||||
StringCommand sCmd;
|
StringCommand sCmd;
|
||||||
@@ -19,10 +21,6 @@ AsyncWebServer server(80);
|
|||||||
|
|
||||||
DallasTemperature sensors;
|
DallasTemperature sensors;
|
||||||
|
|
||||||
WiFiClient espClient;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Global vars
|
* Global vars
|
||||||
*/
|
*/
|
||||||
@@ -35,11 +33,11 @@ String configLiveJson = "{}";
|
|||||||
String configOptionJson = "{}";
|
String configOptionJson = "{}";
|
||||||
|
|
||||||
// Mqtt
|
// Mqtt
|
||||||
String chipID = "";
|
String chipId = "";
|
||||||
String prex;
|
String prex = "";
|
||||||
String all_widgets = "";
|
String all_widgets = "";
|
||||||
String scenario;
|
String scenario = "";
|
||||||
String order_loop;
|
String order_loop = "";
|
||||||
|
|
||||||
// Sensors
|
// Sensors
|
||||||
String analog_value_names_list;
|
String analog_value_names_list;
|
||||||
|
|||||||
20
src/Init.cpp
20
src/Init.cpp
@@ -7,6 +7,24 @@ UptimeInterval myUptime(10);
|
|||||||
void handle_uptime();
|
void handle_uptime();
|
||||||
void handle_statistics();
|
void handle_statistics();
|
||||||
|
|
||||||
|
void File_system_init() {
|
||||||
|
if (!LittleFS.begin()) {
|
||||||
|
Serial.println("[E] LittleFS");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
configSetupJson = readFile("config.json", 4096);
|
||||||
|
configSetupJson.replace(" ", "");
|
||||||
|
configSetupJson.replace("\r\n", "");
|
||||||
|
|
||||||
|
jsonWriteStr(configSetupJson, "chipID", chipId);
|
||||||
|
jsonWriteStr(configSetupJson, "firmware_version", firmware_version);
|
||||||
|
|
||||||
|
prex = jsonReadStr(configSetupJson, "mqttPrefix") + "/" + chipId;
|
||||||
|
|
||||||
|
Serial.println(configSetupJson);
|
||||||
|
}
|
||||||
|
|
||||||
void All_init() {
|
void All_init() {
|
||||||
Device_init();
|
Device_init();
|
||||||
Scenario_init();
|
Scenario_init();
|
||||||
@@ -47,7 +65,7 @@ void Device_init() {
|
|||||||
#ifdef layout_in_ram
|
#ifdef layout_in_ram
|
||||||
all_widgets = "";
|
all_widgets = "";
|
||||||
#else
|
#else
|
||||||
SPIFFS.remove("/layout.txt");
|
LittleFS.remove("/layout.txt");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
txtExecution("firmware.c.txt");
|
txtExecution("firmware.c.txt");
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ void logging() {
|
|||||||
LOG1, period_min.toInt() * 1000 * 60, [&](void*) {
|
LOG1, period_min.toInt() * 1000 * 60, [&](void*) {
|
||||||
String tmp_buf_1 = selectFromMarkerToMarker(logging_value_names_list, ",", 0);
|
String tmp_buf_1 = selectFromMarkerToMarker(logging_value_names_list, ",", 0);
|
||||||
deleteOldDate("log." + tmp_buf_1 + ".txt", jsonReadInt(configOptionJson, tmp_buf_1 + "_c"), jsonReadStr(configLiveJson, tmp_buf_1));
|
deleteOldDate("log." + tmp_buf_1 + ".txt", jsonReadInt(configOptionJson, tmp_buf_1 + "_c"), jsonReadStr(configLiveJson, tmp_buf_1));
|
||||||
Serial.println("[i] LOGGING for sensor '" + tmp_buf_1 + "' done");
|
Serial.println("[I] LOGGING for sensor '" + tmp_buf_1 + "' done");
|
||||||
},
|
},
|
||||||
nullptr, false);
|
nullptr, false);
|
||||||
}
|
}
|
||||||
@@ -31,7 +31,7 @@ void logging() {
|
|||||||
LOG2, period_min.toInt() * 1000 * 60, [&](void*) {
|
LOG2, period_min.toInt() * 1000 * 60, [&](void*) {
|
||||||
String tmp_buf_2 = selectFromMarkerToMarker(logging_value_names_list, ",", 1);
|
String tmp_buf_2 = selectFromMarkerToMarker(logging_value_names_list, ",", 1);
|
||||||
deleteOldDate("log." + tmp_buf_2 + ".txt", jsonReadInt(configOptionJson, tmp_buf_2 + "_c"), jsonReadStr(configLiveJson, tmp_buf_2));
|
deleteOldDate("log." + tmp_buf_2 + ".txt", jsonReadInt(configOptionJson, tmp_buf_2 + "_c"), jsonReadStr(configLiveJson, tmp_buf_2));
|
||||||
Serial.println("[i] LOGGING for sensor '" + tmp_buf_2 + "' done");
|
Serial.println("[I] LOGGING for sensor '" + tmp_buf_2 + "' done");
|
||||||
},
|
},
|
||||||
nullptr, false);
|
nullptr, false);
|
||||||
}
|
}
|
||||||
@@ -40,7 +40,7 @@ void logging() {
|
|||||||
LOG3, period_min.toInt() * 1000 * 60, [&](void*) {
|
LOG3, period_min.toInt() * 1000 * 60, [&](void*) {
|
||||||
String tmp_buf_3 = selectFromMarkerToMarker(logging_value_names_list, ",", 2);
|
String tmp_buf_3 = selectFromMarkerToMarker(logging_value_names_list, ",", 2);
|
||||||
deleteOldDate("log." + tmp_buf_3 + ".txt", jsonReadInt(configOptionJson, tmp_buf_3 + "_c"), jsonReadStr(configLiveJson, tmp_buf_3));
|
deleteOldDate("log." + tmp_buf_3 + ".txt", jsonReadInt(configOptionJson, tmp_buf_3 + "_c"), jsonReadStr(configLiveJson, tmp_buf_3));
|
||||||
Serial.println("[i] LOGGING for sensor '" + tmp_buf_3 + "' done");
|
Serial.println("[I] LOGGING for sensor '" + tmp_buf_3 + "' done");
|
||||||
},
|
},
|
||||||
nullptr, false);
|
nullptr, false);
|
||||||
}
|
}
|
||||||
@@ -49,7 +49,7 @@ void logging() {
|
|||||||
LOG4, period_min.toInt() * 1000 * 60, [&](void*) {
|
LOG4, period_min.toInt() * 1000 * 60, [&](void*) {
|
||||||
String tmp_buf_4 = selectFromMarkerToMarker(logging_value_names_list, ",", 3);
|
String tmp_buf_4 = selectFromMarkerToMarker(logging_value_names_list, ",", 3);
|
||||||
deleteOldDate("log." + tmp_buf_4 + ".txt", jsonReadInt(configOptionJson, tmp_buf_4 + "_c"), jsonReadStr(configLiveJson, tmp_buf_4));
|
deleteOldDate("log." + tmp_buf_4 + ".txt", jsonReadInt(configOptionJson, tmp_buf_4 + "_c"), jsonReadStr(configLiveJson, tmp_buf_4));
|
||||||
Serial.println("[i] LOGGING for sensor '" + tmp_buf_4 + "' done");
|
Serial.println("[I] LOGGING for sensor '" + tmp_buf_4 + "' done");
|
||||||
},
|
},
|
||||||
nullptr, false);
|
nullptr, false);
|
||||||
}
|
}
|
||||||
@@ -58,7 +58,7 @@ void logging() {
|
|||||||
LOG5, period_min.toInt() * 1000 * 60, [&](void*) {
|
LOG5, period_min.toInt() * 1000 * 60, [&](void*) {
|
||||||
String tmp_buf_5 = selectFromMarkerToMarker(logging_value_names_list, ",", 4);
|
String tmp_buf_5 = selectFromMarkerToMarker(logging_value_names_list, ",", 4);
|
||||||
deleteOldDate("log." + tmp_buf_5 + ".txt", jsonReadInt(configOptionJson, tmp_buf_5 + "_c"), jsonReadStr(configLiveJson, tmp_buf_5));
|
deleteOldDate("log." + tmp_buf_5 + ".txt", jsonReadInt(configOptionJson, tmp_buf_5 + "_c"), jsonReadStr(configLiveJson, tmp_buf_5));
|
||||||
Serial.println("[i] LOGGING for sensor '" + tmp_buf_5 + "' done");
|
Serial.println("[I] LOGGING for sensor '" + tmp_buf_5 + "' done");
|
||||||
},
|
},
|
||||||
nullptr, false);
|
nullptr, false);
|
||||||
}
|
}
|
||||||
@@ -71,11 +71,11 @@ void deleteOldDate(String file, int seted_number_of_lines, String date_to_add) {
|
|||||||
Serial.println("=====> [i] in log file " + file + " " + current_number_of_lines + " lines");
|
Serial.println("=====> [i] in log file " + file + " " + current_number_of_lines + " lines");
|
||||||
|
|
||||||
if (current_number_of_lines > seted_number_of_lines + 1) {
|
if (current_number_of_lines > seted_number_of_lines + 1) {
|
||||||
SPIFFS.remove("/" + file);
|
LittleFS.remove("/" + file);
|
||||||
current_number_of_lines = 0;
|
current_number_of_lines = 0;
|
||||||
}
|
}
|
||||||
if (current_number_of_lines == 0) {
|
if (current_number_of_lines == 0) {
|
||||||
SPIFFS.remove("/" + file);
|
LittleFS.remove("/" + file);
|
||||||
current_number_of_lines = 0;
|
current_number_of_lines = 0;
|
||||||
}
|
}
|
||||||
if (current_number_of_lines > seted_number_of_lines) {
|
if (current_number_of_lines > seted_number_of_lines) {
|
||||||
@@ -133,7 +133,7 @@ void sendLogData(String file, String topic) {
|
|||||||
Serial.println(json_array);
|
Serial.println(json_array);
|
||||||
sendCHART(topic, json_array);
|
sendCHART(topic, json_array);
|
||||||
json_array = "";
|
json_array = "";
|
||||||
getMemoryLoad("[i] after send log date");
|
getMemoryLoad("[I] after send log date");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,14 +152,14 @@ void sendLogData(String file, String topic) {
|
|||||||
//Serial.println(final_line);
|
//Serial.println(final_line);
|
||||||
sendCHART(topic, final_line);
|
sendCHART(topic, final_line);
|
||||||
}
|
}
|
||||||
getMemoryLoad("[i] after send log date");
|
getMemoryLoad("[I] after send log date");
|
||||||
*/
|
*/
|
||||||
//=========================================Очистка данных===================================================================================
|
//=========================================Очистка данных===================================================================================
|
||||||
void clean_log_date() {
|
void clean_log_date() {
|
||||||
String all_line = logging_value_names_list;
|
String all_line = logging_value_names_list;
|
||||||
while (all_line.length() != 0) {
|
while (all_line.length() != 0) {
|
||||||
String tmp = selectToMarker(all_line, ",");
|
String tmp = selectToMarker(all_line, ",");
|
||||||
SPIFFS.remove("/log." + tmp + ".txt");
|
LittleFS.remove("/log." + tmp + ".txt");
|
||||||
all_line = deleteBeforeDelimiter(all_line, ",");
|
all_line = deleteBeforeDelimiter(all_line, ",");
|
||||||
}
|
}
|
||||||
all_line = "";
|
all_line = "";
|
||||||
|
|||||||
35
src/Mqtt.cpp
35
src/Mqtt.cpp
@@ -60,16 +60,16 @@ boolean MQTT_Connecting() {
|
|||||||
if (WiFi.status() == WL_CONNECTED) {
|
if (WiFi.status() == WL_CONNECTED) {
|
||||||
if (!client_mqtt.connected()) {
|
if (!client_mqtt.connected()) {
|
||||||
Serial.println("[V] Connecting to MQTT server commenced");
|
Serial.println("[V] Connecting to MQTT server commenced");
|
||||||
if (client_mqtt.connect(chipID.c_str(), jsonReadStr(configSetupJson, "mqttUser").c_str(), jsonReadStr(configSetupJson, "mqttPass").c_str())) {
|
if (client_mqtt.connect(chipId.c_str(), jsonReadStr(configSetupJson, "mqttUser").c_str(), jsonReadStr(configSetupJson, "mqttPass").c_str())) {
|
||||||
Serial.println("[VV] MQTT connected");
|
Serial.println("[VV] MQTT connected");
|
||||||
led_blink("off");
|
led_blink("off");
|
||||||
client_mqtt.setCallback(callback);
|
client_mqtt.setCallback(callback);
|
||||||
client_mqtt.subscribe(jsonReadStr(configSetupJson, "mqttPrefix").c_str()); // Для приема получения HELLOW и подтверждения связи
|
client_mqtt.subscribe(jsonReadStr(configSetupJson, "mqttPrefix").c_str()); // Для приема получения HELLOW и подтверждения связи
|
||||||
client_mqtt.subscribe((jsonReadStr(configSetupJson, "mqttPrefix") + "/" + chipID + "/+/control").c_str()); // Подписываемся на топики control
|
client_mqtt.subscribe((jsonReadStr(configSetupJson, "mqttPrefix") + "/" + chipId + "/+/control").c_str()); // Подписываемся на топики control
|
||||||
client_mqtt.subscribe((jsonReadStr(configSetupJson, "mqttPrefix") + "/" + chipID + "/order").c_str()); // Подписываемся на топики order
|
client_mqtt.subscribe((jsonReadStr(configSetupJson, "mqttPrefix") + "/" + chipId + "/order").c_str()); // Подписываемся на топики order
|
||||||
client_mqtt.subscribe((jsonReadStr(configSetupJson, "mqttPrefix") + "/" + chipID + "/update").c_str());
|
client_mqtt.subscribe((jsonReadStr(configSetupJson, "mqttPrefix") + "/" + chipId + "/update").c_str());
|
||||||
client_mqtt.subscribe((jsonReadStr(configSetupJson, "mqttPrefix") + "/" + chipID + "/devc").c_str());
|
client_mqtt.subscribe((jsonReadStr(configSetupJson, "mqttPrefix") + "/" + chipId + "/devc").c_str());
|
||||||
client_mqtt.subscribe((jsonReadStr(configSetupJson, "mqttPrefix") + "/" + chipID + "/devs").c_str());
|
client_mqtt.subscribe((jsonReadStr(configSetupJson, "mqttPrefix") + "/" + chipId + "/devs").c_str());
|
||||||
Serial.println("[V] Callback set, subscribe done");
|
Serial.println("[V] Callback set, subscribe done");
|
||||||
res = true;
|
res = true;
|
||||||
} else {
|
} else {
|
||||||
@@ -142,7 +142,7 @@ void outcoming_date() {
|
|||||||
|
|
||||||
//======================================CONFIG==================================================
|
//======================================CONFIG==================================================
|
||||||
boolean sendMQTT(String end_of_topik, String data) {
|
boolean sendMQTT(String end_of_topik, String data) {
|
||||||
String topik = jsonReadStr(configSetupJson, "mqttPrefix") + "/" + chipID + "/" + end_of_topik;
|
String topik = jsonReadStr(configSetupJson, "mqttPrefix") + "/" + chipId + "/" + end_of_topik;
|
||||||
boolean send_status = client_mqtt.beginPublish(topik.c_str(), data.length(), false);
|
boolean send_status = client_mqtt.beginPublish(topik.c_str(), data.length(), false);
|
||||||
client_mqtt.print(data);
|
client_mqtt.print(data);
|
||||||
client_mqtt.endPublish();
|
client_mqtt.endPublish();
|
||||||
@@ -150,7 +150,7 @@ boolean sendMQTT(String end_of_topik, String data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
boolean sendCHART(String topik, String data) {
|
boolean sendCHART(String topik, String data) {
|
||||||
topik = jsonReadStr(configSetupJson, "mqttPrefix") + "/" + chipID + "/" + topik + "/" + "status";
|
topik = jsonReadStr(configSetupJson, "mqttPrefix") + "/" + chipId + "/" + topik + "/" + "status";
|
||||||
boolean send_status = client_mqtt.beginPublish(topik.c_str(), data.length(), false);
|
boolean send_status = client_mqtt.beginPublish(topik.c_str(), data.length(), false);
|
||||||
client_mqtt.print(data);
|
client_mqtt.print(data);
|
||||||
client_mqtt.endPublish();
|
client_mqtt.endPublish();
|
||||||
@@ -158,14 +158,14 @@ boolean sendCHART(String topik, String data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
boolean sendCHART_test(String topik, String data) {
|
boolean sendCHART_test(String topik, String data) {
|
||||||
topik = jsonReadStr(configSetupJson, "mqttPrefix") + "/" + chipID + "/" + topik + "/" + "status";
|
topik = jsonReadStr(configSetupJson, "mqttPrefix") + "/" + chipId + "/" + topik + "/" + "status";
|
||||||
boolean send_status = client_mqtt.publish(topik.c_str(), data.c_str(), false);
|
boolean send_status = client_mqtt.publish(topik.c_str(), data.c_str(), false);
|
||||||
return send_status;
|
return send_status;
|
||||||
}
|
}
|
||||||
|
|
||||||
//======================================STATUS==================================================
|
//======================================STATUS==================================================
|
||||||
void sendSTATUS(String topik, String state) {
|
void sendSTATUS(String topik, String state) {
|
||||||
topik = jsonReadStr(configSetupJson, "mqttPrefix") + "/" + chipID + "/" + topik + "/" + "status";
|
topik = jsonReadStr(configSetupJson, "mqttPrefix") + "/" + chipId + "/" + topik + "/" + "status";
|
||||||
String json_ = "{}";
|
String json_ = "{}";
|
||||||
jsonWriteStr(json_, "status", state);
|
jsonWriteStr(json_, "status", state);
|
||||||
client_mqtt.publish(topik.c_str(), json_.c_str(), false);
|
client_mqtt.publish(topik.c_str(), json_.c_str(), false);
|
||||||
@@ -198,20 +198,21 @@ void sendAllWigets() {
|
|||||||
Serial.println("[V] " + line);
|
Serial.println("[V] " + line);
|
||||||
psn_1 = psn_2 + 1;
|
psn_1 = psn_2 + 1;
|
||||||
} while (psn_2 + 2 < all_widgets.length());
|
} while (psn_2 + 2 < all_widgets.length());
|
||||||
getMemoryLoad("[i] after send all widgets");
|
getMemoryLoad("[I] after send all widgets");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef layout_in_ram
|
#ifndef layout_in_ram
|
||||||
void sendAllWigets() {
|
void sendAllWigets() {
|
||||||
File configFile = SPIFFS.open("/layout.txt", "r");
|
auto file = LittleFS.open("/layout.txt", "r");
|
||||||
if (!configFile) {
|
if (!file) {
|
||||||
|
Serial.println("[e] on open layout.txt");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
configFile.seek(0, SeekSet); //поставим курсор в начало файла
|
file.seek(0, SeekSet); //поставим курсор в начало файла
|
||||||
while (configFile.position() != configFile.size()) {
|
while (file.position() != file.size()) {
|
||||||
String widget_to_send = configFile.readStringUntil('\n');
|
String widget_to_send = file.readStringUntil('\n');
|
||||||
Serial.println("[V] " + widget_to_send);
|
Serial.println("[V] " + widget_to_send);
|
||||||
sendMQTT("config", widget_to_send);
|
sendMQTT("config", widget_to_send);
|
||||||
}
|
}
|
||||||
@@ -221,7 +222,7 @@ void sendAllWigets() {
|
|||||||
void sendAllData() { //берет строку json и ключи превращает в топики а значения колючей в них посылает
|
void sendAllData() { //берет строку json и ключи превращает в топики а значения колючей в них посылает
|
||||||
|
|
||||||
String current_config = configLiveJson; //{"name":"MODULES","lang":"","ip":"192.168.43.60","DS":"34.00","rel1":"1","rel2":"1"}
|
String current_config = configLiveJson; //{"name":"MODULES","lang":"","ip":"192.168.43.60","DS":"34.00","rel1":"1","rel2":"1"}
|
||||||
getMemoryLoad("[i] after send all date");
|
getMemoryLoad("[I] after send all date");
|
||||||
current_config.replace("{", "");
|
current_config.replace("{", "");
|
||||||
current_config.replace("}", ""); //"name":"MODULES","lang":"","ip":"192.168.43.60","DS":"34.00","rel1":"1","rel2":"1"
|
current_config.replace("}", ""); //"name":"MODULES","lang":"","ip":"192.168.43.60","DS":"34.00","rel1":"1","rel2":"1"
|
||||||
current_config += ","; //"name":"MODULES","lang":"","ip":"192.168.43.60","DS":"34.00","rel1":"1","rel2":"1",
|
current_config += ","; //"name":"MODULES","lang":"","ip":"192.168.43.60","DS":"34.00","rel1":"1","rel2":"1",
|
||||||
|
|||||||
@@ -147,12 +147,12 @@ void ultrasonic_reading() {
|
|||||||
jsonWriteInt(configLiveJson, levelPr_value_name, level);
|
jsonWriteInt(configLiveJson, levelPr_value_name, level);
|
||||||
eventGen(levelPr_value_name, "");
|
eventGen(levelPr_value_name, "");
|
||||||
sendSTATUS(levelPr_value_name, String(level));
|
sendSTATUS(levelPr_value_name, String(level));
|
||||||
Serial.println("[i] sensor '" + levelPr_value_name + "' data: " + String(level));
|
Serial.println("[I] sensor '" + levelPr_value_name + "' data: " + String(level));
|
||||||
|
|
||||||
jsonWriteInt(configLiveJson, ultrasonicCm_value_name, distance_cm);
|
jsonWriteInt(configLiveJson, ultrasonicCm_value_name, distance_cm);
|
||||||
eventGen(ultrasonicCm_value_name, "");
|
eventGen(ultrasonicCm_value_name, "");
|
||||||
sendSTATUS(ultrasonicCm_value_name, String(distance_cm));
|
sendSTATUS(ultrasonicCm_value_name, String(distance_cm));
|
||||||
Serial.println("[i] sensor '" + ultrasonicCm_value_name + "' data: " + String(distance_cm));
|
Serial.println("[I] sensor '" + ultrasonicCm_value_name + "' data: " + String(distance_cm));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -202,7 +202,7 @@ void analog_reading1() {
|
|||||||
jsonWriteInt(configLiveJson, value_name, analog);
|
jsonWriteInt(configLiveJson, value_name, analog);
|
||||||
eventGen(value_name, "");
|
eventGen(value_name, "");
|
||||||
sendSTATUS(value_name, String(analog));
|
sendSTATUS(value_name, String(analog));
|
||||||
Serial.println("[i] sensor '" + value_name + "' data: " + String(analog));
|
Serial.println("[I] sensor '" + value_name + "' data: " + String(analog));
|
||||||
}
|
}
|
||||||
|
|
||||||
void analog_reading2() {
|
void analog_reading2() {
|
||||||
@@ -221,7 +221,7 @@ void analog_reading2() {
|
|||||||
jsonWriteInt(configLiveJson, value_name, analog);
|
jsonWriteInt(configLiveJson, value_name, analog);
|
||||||
eventGen(value_name, "");
|
eventGen(value_name, "");
|
||||||
sendSTATUS(value_name, String(analog));
|
sendSTATUS(value_name, String(analog));
|
||||||
Serial.println("[i] sensor '" + value_name + "' data: " + String(analog));
|
Serial.println("[I] sensor '" + value_name + "' data: " + String(analog));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
//=========================================================================================================================================
|
//=========================================================================================================================================
|
||||||
@@ -250,7 +250,7 @@ void dallas_reading() {
|
|||||||
jsonWriteStr(configLiveJson, "dallas", String(temp));
|
jsonWriteStr(configLiveJson, "dallas", String(temp));
|
||||||
eventGen("dallas", "");
|
eventGen("dallas", "");
|
||||||
sendSTATUS("dallas", String(temp));
|
sendSTATUS("dallas", String(temp));
|
||||||
Serial.println("[i] sensor 'dallas' send date " + String(temp));
|
Serial.println("[I] sensor 'dallas' send date " + String(temp));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
//=========================================================================================================================================
|
//=========================================================================================================================================
|
||||||
@@ -289,7 +289,7 @@ void dhtT_reading() {
|
|||||||
eventGen(dhtT_value_name, "");
|
eventGen(dhtT_value_name, "");
|
||||||
jsonWriteStr(configLiveJson, dhtT_value_name, String(value));
|
jsonWriteStr(configLiveJson, dhtT_value_name, String(value));
|
||||||
sendSTATUS(dhtT_value_name, String(value));
|
sendSTATUS(dhtT_value_name, String(value));
|
||||||
Serial.println("[i] sensor '" + dhtT_value_name + "' data: " + String(value));
|
Serial.println("[I] sensor '" + dhtT_value_name + "' data: " + String(value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -327,7 +327,7 @@ void dhtH_reading() {
|
|||||||
eventGen(dhtH_value_name, "");
|
eventGen(dhtH_value_name, "");
|
||||||
jsonWriteStr(configLiveJson, dhtH_value_name, String(value));
|
jsonWriteStr(configLiveJson, dhtH_value_name, String(value));
|
||||||
sendSTATUS(dhtH_value_name, String(value));
|
sendSTATUS(dhtH_value_name, String(value));
|
||||||
Serial.println("[i] sensor '" + dhtH_value_name + "' data: " + String(value));
|
Serial.println("[I] sensor '" + dhtH_value_name + "' data: " + String(value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -352,7 +352,7 @@ void dhtP_reading() {
|
|||||||
eventGen("dhtPerception", "");
|
eventGen("dhtPerception", "");
|
||||||
sendSTATUS("dhtPerception", final_line);
|
sendSTATUS("dhtPerception", final_line);
|
||||||
if (client_mqtt.connected()) {
|
if (client_mqtt.connected()) {
|
||||||
Serial.println("[i] sensor 'dhtPerception' data: " + final_line);
|
Serial.println("[I] sensor 'dhtPerception' data: " + final_line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -409,7 +409,7 @@ void dhtC_reading() {
|
|||||||
jsonWriteStr(configLiveJson, "dhtComfort", final_line);
|
jsonWriteStr(configLiveJson, "dhtComfort", final_line);
|
||||||
eventGen("dhtComfort", "");
|
eventGen("dhtComfort", "");
|
||||||
sendSTATUS("dhtComfort", final_line);
|
sendSTATUS("dhtComfort", final_line);
|
||||||
Serial.println("[i] sensor 'dhtComfort' send date " + final_line);
|
Serial.println("[I] sensor 'dhtComfort' send date " + final_line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -468,7 +468,7 @@ void dhtD_reading() {
|
|||||||
jsonWriteInt(configLiveJson, "dhtDewpoint", value);
|
jsonWriteInt(configLiveJson, "dhtDewpoint", value);
|
||||||
eventGen("dhtDewpoint", "");
|
eventGen("dhtDewpoint", "");
|
||||||
sendSTATUS("dhtDewpoint", String(value));
|
sendSTATUS("dhtDewpoint", String(value));
|
||||||
Serial.println("[i] sensor 'dhtDewpoint' data: " + String(value));
|
Serial.println("[I] sensor 'dhtDewpoint' data: " + String(value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -504,7 +504,7 @@ void bmp280T_reading() {
|
|||||||
jsonWriteStr(configLiveJson, bmp280T_value_name, String(value));
|
jsonWriteStr(configLiveJson, bmp280T_value_name, String(value));
|
||||||
eventGen(bmp280T_value_name, "");
|
eventGen(bmp280T_value_name, "");
|
||||||
sendSTATUS(bmp280T_value_name, String(value));
|
sendSTATUS(bmp280T_value_name, String(value));
|
||||||
Serial.println("[i] sensor '" + bmp280T_value_name + "' data: " + String(value));
|
Serial.println("[I] sensor '" + bmp280T_value_name + "' data: " + String(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
//bmp280P press1 0x76 Давление#bmp280 Датчики any-data 2
|
//bmp280P press1 0x76 Давление#bmp280 Датчики any-data 2
|
||||||
@@ -536,7 +536,7 @@ void bmp280P_reading() {
|
|||||||
jsonWriteStr(configLiveJson, bmp280P_value_name, String(value));
|
jsonWriteStr(configLiveJson, bmp280P_value_name, String(value));
|
||||||
eventGen(bmp280P_value_name, "");
|
eventGen(bmp280P_value_name, "");
|
||||||
sendSTATUS(bmp280P_value_name, String(value));
|
sendSTATUS(bmp280P_value_name, String(value));
|
||||||
Serial.println("[i] sensor '" + bmp280P_value_name + "' data: " + String(value));
|
Serial.println("[I] sensor '" + bmp280P_value_name + "' data: " + String(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
//=========================================================================================================================================
|
//=========================================================================================================================================
|
||||||
@@ -561,7 +561,7 @@ void bme280T_reading() {
|
|||||||
jsonWriteStr(configLiveJson, bme280T_value_name, String(value));
|
jsonWriteStr(configLiveJson, bme280T_value_name, String(value));
|
||||||
eventGen(bme280T_value_name, "");
|
eventGen(bme280T_value_name, "");
|
||||||
sendSTATUS(bme280T_value_name, String(value));
|
sendSTATUS(bme280T_value_name, String(value));
|
||||||
Serial.println("[i] sensor '" + bme280T_value_name + "' data: " + String(value));
|
Serial.println("[I] sensor '" + bme280T_value_name + "' data: " + String(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
//bme280P pres1 0x76 Давление#bmp280 Датчики any-data 1
|
//bme280P pres1 0x76 Давление#bmp280 Датчики any-data 1
|
||||||
@@ -585,7 +585,7 @@ void bme280P_reading() {
|
|||||||
jsonWriteStr(configLiveJson, bme280P_value_name, String(value));
|
jsonWriteStr(configLiveJson, bme280P_value_name, String(value));
|
||||||
eventGen(bme280P_value_name, "");
|
eventGen(bme280P_value_name, "");
|
||||||
sendSTATUS(bme280P_value_name, String(value));
|
sendSTATUS(bme280P_value_name, String(value));
|
||||||
Serial.println("[i] sensor '" + bme280P_value_name + "' data: " + String(value));
|
Serial.println("[I] sensor '" + bme280P_value_name + "' data: " + String(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
//bme280H hum1 0x76 Влажность#bmp280 Датчики any-data 1
|
//bme280H hum1 0x76 Влажность#bmp280 Датчики any-data 1
|
||||||
@@ -608,7 +608,7 @@ void bme280H_reading() {
|
|||||||
jsonWriteStr(configLiveJson, bme280H_value_name, String(value));
|
jsonWriteStr(configLiveJson, bme280H_value_name, String(value));
|
||||||
eventGen(bme280H_value_name, "");
|
eventGen(bme280H_value_name, "");
|
||||||
sendSTATUS(bme280H_value_name, String(value));
|
sendSTATUS(bme280H_value_name, String(value));
|
||||||
Serial.println("[i] sensor '" + bme280H_value_name + "' data: " + String(value));
|
Serial.println("[I] sensor '" + bme280H_value_name + "' data: " + String(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
//bme280A altit1 0x76 Высота#bmp280 Датчики any-data 1
|
//bme280A altit1 0x76 Высота#bmp280 Датчики any-data 1
|
||||||
@@ -631,5 +631,5 @@ void bme280A_reading() {
|
|||||||
jsonWriteStr(configLiveJson, bme280A_value_name, String(value));
|
jsonWriteStr(configLiveJson, bme280A_value_name, String(value));
|
||||||
eventGen(bme280A_value_name, "");
|
eventGen(bme280A_value_name, "");
|
||||||
sendSTATUS(bme280A_value_name, String(value));
|
sendSTATUS(bme280A_value_name, String(value));
|
||||||
Serial.println("[i] sensor '" + bme280A_value_name + "' data: " + String(value));
|
Serial.println("[I] sensor '" + bme280A_value_name + "' data: " + String(value));
|
||||||
}
|
}
|
||||||
|
|||||||
105
src/Upgrade.cpp
105
src/Upgrade.cpp
@@ -1,88 +1,85 @@
|
|||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
void initUpgrade() {
|
void initUpgrade() {
|
||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
if (WiFi.status() == WL_CONNECTED) last_version = getURL("http://91.204.228.124:1100/update/esp8266/version.txt");
|
if (WiFi.status() == WL_CONNECTED) last_version = getURL("http://91.204.228.124:1100/update/esp8266/version.txt");
|
||||||
#endif
|
#endif
|
||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
if (WiFi.status() == WL_CONNECTED) last_version = getURL("http://91.204.228.124:1100/update/esp32/version.txt");
|
if (WiFi.status() == WL_CONNECTED) last_version = getURL("http://91.204.228.124:1100/update/esp32/version.txt");
|
||||||
#endif
|
#endif
|
||||||
jsonWriteStr(configSetupJson, "last_version", last_version);
|
jsonWriteStr(configSetupJson, "last_version", last_version);
|
||||||
Serial.print("[i] Last firmware version: ");
|
Serial.print("[I] Last firmware version: ");
|
||||||
Serial.println(last_version);
|
Serial.println(last_version);
|
||||||
}
|
}
|
||||||
|
|
||||||
void do_upgrade_url() {
|
void do_upgrade_url() {
|
||||||
if (upgrade_url) {
|
if (upgrade_url) {
|
||||||
upgrade_url = false;
|
upgrade_url = false;
|
||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
last_version = getURL("http://91.204.228.124:1100/update/esp32/version.txt");
|
last_version = getURL("http://91.204.228.124:1100/update/esp32/version.txt");
|
||||||
#endif
|
#endif
|
||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
last_version = getURL("http://91.204.228.124:1100/update/esp8266/version.txt");
|
last_version = getURL("http://91.204.228.124:1100/update/esp8266/version.txt");
|
||||||
#endif
|
#endif
|
||||||
jsonWriteStr(configSetupJson, "last_version", last_version);
|
jsonWriteStr(configSetupJson, "last_version", last_version);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void upgrade_firmware() {
|
void upgrade_firmware() {
|
||||||
|
String scenario_for_update;
|
||||||
|
String config_for_update;
|
||||||
|
String configSetup_for_update;
|
||||||
|
scenario_for_update = readFile("firmware.s.txt", 4000);
|
||||||
|
config_for_update = readFile("firmware.c.txt", 4000);
|
||||||
|
configSetup_for_update = configSetupJson;
|
||||||
|
|
||||||
String scenario_for_update;
|
Serial.println("Start upgrade SPIFFS, please wait...");
|
||||||
String config_for_update;
|
|
||||||
String configSetup_for_update;
|
|
||||||
scenario_for_update = readFile("firmware.s.txt", 4000);
|
|
||||||
config_for_update = readFile("firmware.c.txt", 4000);
|
|
||||||
configSetup_for_update = configSetupJson;
|
|
||||||
|
|
||||||
Serial.println("Start upgrade SPIFFS, please wait...");
|
WiFiClient client_for_upgrade;
|
||||||
|
|
||||||
WiFiClient client_for_upgrade;
|
|
||||||
|
|
||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
httpUpdate.rebootOnUpdate(false);
|
httpUpdate.rebootOnUpdate(false);
|
||||||
t_httpUpdate_return ret = httpUpdate.updateSpiffs(client_for_upgrade, "http://91.204.228.124:1100/update/esp32/esp32-esp8266_iot-manager_modules_firmware.spiffs.bin");
|
t_httpUpdate_return ret = httpUpdate.updateSpiffs(client_for_upgrade, "http://91.204.228.124:1100/update/esp32/esp32-esp8266_iot-manager_modules_firmware.spiffs.bin");
|
||||||
#endif
|
#endif
|
||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
ESPhttpUpdate.rebootOnUpdate(false);
|
ESPhttpUpdate.rebootOnUpdate(false);
|
||||||
t_httpUpdate_return ret = ESPhttpUpdate.updateSpiffs(client_for_upgrade, "http://91.204.228.124:1100/update/esp8266/esp32-esp8266_iot-manager_modules_firmware.spiffs.bin");
|
t_httpUpdate_return ret = ESPhttpUpdate.updateSpiffs(client_for_upgrade, "http://91.204.228.124:1100/update/esp8266/esp32-esp8266_iot-manager_modules_firmware.spiffs.bin");
|
||||||
#endif
|
|
||||||
|
|
||||||
if (ret == HTTP_UPDATE_OK) {
|
|
||||||
|
|
||||||
writeFile("firmware.s.txt", scenario_for_update);
|
|
||||||
writeFile("firmware.c.txt", config_for_update);
|
|
||||||
writeFile("config.json", configSetup_for_update);
|
|
||||||
saveConfig();
|
|
||||||
|
|
||||||
Serial.println("SPIFFS upgrade done!");
|
|
||||||
Serial.println("Start upgrade BUILD, please wait...");
|
|
||||||
|
|
||||||
#ifdef ESP32
|
|
||||||
//httpUpdate.rebootOnUpdate(true);
|
|
||||||
t_httpUpdate_return ret = httpUpdate.update(client_for_upgrade, "http://91.204.228.124:1100/update/esp32/esp32-esp8266_iot-manager_modules_firmware.ino.bin");
|
|
||||||
#endif
|
|
||||||
#ifdef ESP8266
|
|
||||||
//ESPhttpUpdate.rebootOnUpdate(true);
|
|
||||||
t_httpUpdate_return ret = ESPhttpUpdate.update(client_for_upgrade, "http://91.204.228.124:1100/update/esp8266/esp32-esp8266_iot-manager_modules_firmware.ino.bin");
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (ret == HTTP_UPDATE_OK) {
|
if (ret == HTTP_UPDATE_OK) {
|
||||||
|
writeFile("firmware.s.txt", scenario_for_update);
|
||||||
|
writeFile("firmware.c.txt", config_for_update);
|
||||||
|
writeFile("config.json", configSetup_for_update);
|
||||||
|
saveConfig();
|
||||||
|
|
||||||
Serial.println("BUILD upgrade done!");
|
Serial.println("Upgrade done!");
|
||||||
Serial.println("Restart ESP....");
|
Serial.println("Start upgrade BUILD, please wait...");
|
||||||
ESP.restart();
|
|
||||||
|
#ifdef ESP32
|
||||||
|
//httpUpdate.rebootOnUpdate(true);
|
||||||
|
t_httpUpdate_return ret = httpUpdate.update(client_for_upgrade, "http://91.204.228.124:1100/update/esp32/esp32-esp8266_iot-manager_modules_firmware.ino.bin");
|
||||||
|
#endif
|
||||||
|
#ifdef ESP8266
|
||||||
|
//ESPhttpUpdate.rebootOnUpdate(true);
|
||||||
|
t_httpUpdate_return ret = ESPhttpUpdate.update(client_for_upgrade, "http://91.204.228.124:1100/update/esp8266/esp32-esp8266_iot-manager_modules_firmware.ino.bin");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (ret == HTTP_UPDATE_OK) {
|
||||||
|
Serial.println("Upgrade done!");
|
||||||
|
Serial.println("Restart...");
|
||||||
|
ESP.restart();
|
||||||
|
} else {
|
||||||
|
Serial.println("[e] on build");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Serial.println("!!!!BUILD upgrade ERROR");
|
Serial.println("[e] on upgrade");
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
Serial.println("!!!!SPIFFS upgrade ERROR");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void do_upgrade() {
|
void do_upgrade() {
|
||||||
if (upgrade) {
|
if (upgrade) {
|
||||||
upgrade = false;
|
upgrade = false;
|
||||||
upgrade_firmware();
|
upgrade_firmware();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -1,42 +1,47 @@
|
|||||||
#include "Utils/FileUtils.h"
|
#include "Utils/FileUtils.h"
|
||||||
|
|
||||||
String readFileString(const String& filename, const String& str_to_found) {
|
#include <LittleFS.h>
|
||||||
String res = "failed";
|
|
||||||
auto file = SPIFFS.open("/" + filename, "r");
|
String readFileString(const String filename, const String to_find) {
|
||||||
if (file && file.find(str_to_found.c_str())) {
|
String res = "Failed";
|
||||||
|
auto file = LittleFS.open("/" + filename, "r");
|
||||||
|
if (!file) {
|
||||||
|
return "Failed";
|
||||||
|
}
|
||||||
|
if (file.find(to_find.c_str())) {
|
||||||
res = file.readStringUntil('\n');
|
res = file.readStringUntil('\n');
|
||||||
}
|
}
|
||||||
file.close();
|
file.close();
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
String addFile(const String& fileName, const String& str) {
|
String addFile(const String filename, const String str) {
|
||||||
auto file = SPIFFS.open("/" + fileName, "a");
|
auto file = LittleFS.open("/" + filename, "a");
|
||||||
if (!file) {
|
if (!file) {
|
||||||
return "Failed to open file";
|
return "Failed";
|
||||||
}
|
}
|
||||||
file.println(str);
|
file.println(str);
|
||||||
file.close();
|
file.close();
|
||||||
return "Write sucсess";
|
return "Write sucсess";
|
||||||
}
|
}
|
||||||
|
|
||||||
String writeFile(const String& fileName, const String& str) {
|
String writeFile(const String filename, const String str) {
|
||||||
auto file = SPIFFS.open("/" + fileName, "w");
|
auto file = LittleFS.open("/" + filename, "w");
|
||||||
if (!file) {
|
if (!file) {
|
||||||
return "Failed to open file";
|
return "Failed";
|
||||||
}
|
}
|
||||||
file.print(str);
|
file.print(str);
|
||||||
file.close();
|
file.close();
|
||||||
return "Write sucсess";
|
return "Write sucсess";
|
||||||
}
|
}
|
||||||
|
|
||||||
String readFile(const String& fileName, size_t len) {
|
String readFile(const String filename, size_t max_size) {
|
||||||
File file = SPIFFS.open("/" + fileName, "r");
|
auto file = LittleFS.open("/" + filename, "r");
|
||||||
if (!file) {
|
if (!file) {
|
||||||
return "Failed";
|
return "Failed";
|
||||||
}
|
}
|
||||||
size_t size = file.size();
|
size_t size = file.size();
|
||||||
if (size > len) {
|
if (size > max_size) {
|
||||||
file.close();
|
file.close();
|
||||||
return "Large";
|
return "Large";
|
||||||
}
|
}
|
||||||
@@ -45,8 +50,8 @@ String readFile(const String& fileName, size_t len) {
|
|||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
String sizeFile(const String& fileName) {
|
String getFileSize(const String filename) {
|
||||||
auto file = SPIFFS.open("/" + fileName, "r");
|
auto file = LittleFS.open("/" + filename, "r");
|
||||||
if (!file) {
|
if (!file) {
|
||||||
return "Failed";
|
return "Failed";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,9 +3,6 @@
|
|||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
#include "Utils\StringUtils.h"
|
#include "Utils\StringUtils.h"
|
||||||
|
|
||||||
static const char* TIME_FORMAT PROGMEM = "%2d:%2d:%2d";
|
|
||||||
static const char* TIME_FORMAT_WITH_DAYS PROGMEM = "%dd %2d:%2d";
|
|
||||||
|
|
||||||
void Time_Init() {
|
void Time_Init() {
|
||||||
ts.add(
|
ts.add(
|
||||||
TIME_SYNC, 30000, [&](void*) {
|
TIME_SYNC, 30000, [&](void*) {
|
||||||
@@ -14,33 +11,9 @@ void Time_Init() {
|
|||||||
nullptr, true);
|
nullptr, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
const String prettyMillis(unsigned long time_ms) {
|
|
||||||
unsigned long tmp = time_ms;
|
|
||||||
unsigned long seconds;
|
|
||||||
unsigned long minutes;
|
|
||||||
unsigned long hours;
|
|
||||||
unsigned long days;
|
|
||||||
seconds = tmp % 60;
|
|
||||||
tmp = tmp / 60;
|
|
||||||
|
|
||||||
minutes = tmp % 60;
|
|
||||||
tmp = tmp / 60;
|
|
||||||
hours = tmp % 24;
|
|
||||||
days = tmp / 24;
|
|
||||||
|
|
||||||
char buf[16];
|
|
||||||
|
|
||||||
if (days) {
|
|
||||||
sprintf_P(buf, TIME_FORMAT, hours, minutes, seconds);
|
|
||||||
} else {
|
|
||||||
sprintf_P(buf, TIME_FORMAT_WITH_DAYS, days, hours, minutes);
|
|
||||||
}
|
|
||||||
return String(buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
void time_check() {
|
void time_check() {
|
||||||
if (getTimeUnix() == "failed") {
|
if (getTimeUnix() == "failed") {
|
||||||
Serial.println("[i] Time is not synchronized, start synchronization");
|
Serial.println("[I] Trying to obtain time");
|
||||||
reconfigTime();
|
reconfigTime();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -50,7 +23,7 @@ void reconfigTime() {
|
|||||||
String ntp = jsonReadStr(configSetupJson, "ntp");
|
String ntp = jsonReadStr(configSetupJson, "ntp");
|
||||||
configTime(0, 0, ntp.c_str());
|
configTime(0, 0, ntp.c_str());
|
||||||
int i = 0;
|
int i = 0;
|
||||||
Serial.println("[i] Awaiting for time ");
|
Serial.println("[I] Start time sync");
|
||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
struct tm timeinfo;
|
struct tm timeinfo;
|
||||||
while (!getLocalTime(&timeinfo) && i <= 4) {
|
while (!getLocalTime(&timeinfo) && i <= 4) {
|
||||||
@@ -67,15 +40,15 @@ void reconfigTime() {
|
|||||||
//}
|
//}
|
||||||
#endif
|
#endif
|
||||||
if (getTimeUnix() != "failed") {
|
if (getTimeUnix() != "failed") {
|
||||||
Serial.print("[V] Time synchronized = ");
|
Serial.print("[V] Got time = ");
|
||||||
Serial.print(GetDataDigital());
|
Serial.print(getDateDigitalFormated());
|
||||||
Serial.print(" ");
|
Serial.print(' ');
|
||||||
Serial.println(getTime());
|
Serial.println(getTime());
|
||||||
} else {
|
} else {
|
||||||
Serial.println("[E] Time server or internet connection error, will try again in 30 sec");
|
Serial.println("[E] Failed to obtain time, retry in 30 sec");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Serial.println("[E] Get time impossible, no wifi connection");
|
Serial.println("[E] Unable to obtain time");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,7 +78,7 @@ String getTime() {
|
|||||||
return Time; // Возврашаем полученное время
|
return Time; // Возврашаем полученное время
|
||||||
}
|
}
|
||||||
|
|
||||||
String GetTimeWOsec() {
|
String getTimeWOsec() {
|
||||||
time_t now = time(nullptr); // получаем время с помощью библиотеки time.h
|
time_t now = time(nullptr); // получаем время с помощью библиотеки time.h
|
||||||
int zone = 3600 * jsonReadStr(configSetupJson, "timezone").toInt();
|
int zone = 3600 * jsonReadStr(configSetupJson, "timezone").toInt();
|
||||||
now = now + zone;
|
now = now + zone;
|
||||||
@@ -116,8 +89,7 @@ String GetTimeWOsec() {
|
|||||||
return Time; // Возврашаем полученное время
|
return Time; // Возврашаем полученное время
|
||||||
}
|
}
|
||||||
|
|
||||||
// Получение даты
|
String getDate() {
|
||||||
String GetDate() {
|
|
||||||
time_t now = time(nullptr); // получаем время с помощью библиотеки time.h
|
time_t now = time(nullptr); // получаем время с помощью библиотеки time.h
|
||||||
int zone = 3600 * jsonReadStr(configSetupJson, "timezone").toInt();
|
int zone = 3600 * jsonReadStr(configSetupJson, "timezone").toInt();
|
||||||
now = now + zone;
|
now = now + zone;
|
||||||
@@ -130,8 +102,8 @@ String GetDate() {
|
|||||||
return Data; // Возврашаем полученную дату
|
return Data; // Возврашаем полученную дату
|
||||||
}
|
}
|
||||||
|
|
||||||
String GetDataDigital() {
|
String getDateDigitalFormated() {
|
||||||
String date = GetDate();
|
String date = getDate();
|
||||||
|
|
||||||
date = deleteBeforeDelimiter(date, " ");
|
date = deleteBeforeDelimiter(date, " ");
|
||||||
|
|
||||||
@@ -168,3 +140,30 @@ int timeToMin(String Time) {
|
|||||||
min += selectToMarker(Time, ":").toInt(); // Добавим секунды из полных минут
|
min += selectToMarker(Time, ":").toInt(); // Добавим секунды из полных минут
|
||||||
return min;
|
return min;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const char* TIME_FORMAT PROGMEM = "%2d:%2d:%2d";
|
||||||
|
static const char* TIME_FORMAT_WITH_DAYS PROGMEM = "%dd %2d:%2d";
|
||||||
|
|
||||||
|
const String prettyMillis(unsigned long time_ms) {
|
||||||
|
unsigned long tmp = time_ms;
|
||||||
|
unsigned long seconds;
|
||||||
|
unsigned long minutes;
|
||||||
|
unsigned long hours;
|
||||||
|
unsigned long days;
|
||||||
|
seconds = tmp % 60;
|
||||||
|
tmp = tmp / 60;
|
||||||
|
|
||||||
|
minutes = tmp % 60;
|
||||||
|
tmp = tmp / 60;
|
||||||
|
hours = tmp % 24;
|
||||||
|
days = tmp / 24;
|
||||||
|
|
||||||
|
char buf[16];
|
||||||
|
|
||||||
|
if (days) {
|
||||||
|
sprintf_P(buf, TIME_FORMAT, hours, minutes, seconds);
|
||||||
|
} else {
|
||||||
|
sprintf_P(buf, TIME_FORMAT_WITH_DAYS, days, hours, minutes);
|
||||||
|
}
|
||||||
|
return String(buf);
|
||||||
|
}
|
||||||
|
|||||||
681
src/Web.cpp
681
src/Web.cpp
@@ -3,354 +3,351 @@
|
|||||||
String stateMQTT();
|
String stateMQTT();
|
||||||
|
|
||||||
void web_init() {
|
void web_init() {
|
||||||
server.on("/set", HTTP_GET, [](AsyncWebServerRequest * request) {
|
server.on("/set", HTTP_GET, [](AsyncWebServerRequest* request) {
|
||||||
String value;
|
String value;
|
||||||
//============================device settings=====================================
|
//============================device settings=====================================
|
||||||
if (request->hasArg("preset")) {
|
if (request->hasArg("preset")) {
|
||||||
//--------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------
|
||||||
String value;
|
String value;
|
||||||
value = request->getParam("preset")->value();
|
value = request->getParam("preset")->value();
|
||||||
if (value == "1") {
|
if (value == "1") {
|
||||||
writeFile("firmware.c.txt", readFile("configs/1-relay.c.txt", 2048));
|
writeFile("firmware.c.txt", readFile("configs/1-relay.c.txt", 2048));
|
||||||
writeFile("firmware.s.txt", readFile("configs/1-relay.s.txt", 2048));
|
writeFile("firmware.s.txt", readFile("configs/1-relay.s.txt", 2048));
|
||||||
}
|
}
|
||||||
if (value == "2") {
|
if (value == "2") {
|
||||||
writeFile("firmware.c.txt", readFile("configs/2-relay.c.txt", 2048));
|
writeFile("firmware.c.txt", readFile("configs/2-relay.c.txt", 2048));
|
||||||
writeFile("firmware.s.txt", readFile("configs/2-relay.s.txt", 2048));
|
writeFile("firmware.s.txt", readFile("configs/2-relay.s.txt", 2048));
|
||||||
}
|
}
|
||||||
if (value == "3") {
|
if (value == "3") {
|
||||||
writeFile("firmware.c.txt", readFile("configs/3-relay.c.txt", 2048));
|
writeFile("firmware.c.txt", readFile("configs/3-relay.c.txt", 2048));
|
||||||
writeFile("firmware.s.txt", readFile("configs/3-relay.s.txt", 2048));
|
writeFile("firmware.s.txt", readFile("configs/3-relay.s.txt", 2048));
|
||||||
}
|
}
|
||||||
if (value == "4") {
|
if (value == "4") {
|
||||||
writeFile("firmware.c.txt", readFile("configs/4-relay.c.txt", 2048));
|
writeFile("firmware.c.txt", readFile("configs/4-relay.c.txt", 2048));
|
||||||
writeFile("firmware.s.txt", readFile("configs/4-relay.s.txt", 2048));
|
writeFile("firmware.s.txt", readFile("configs/4-relay.s.txt", 2048));
|
||||||
}
|
}
|
||||||
if (value == "5") {
|
if (value == "5") {
|
||||||
writeFile("firmware.c.txt", readFile("configs/5-relay.c.txt", 2048));
|
writeFile("firmware.c.txt", readFile("configs/5-relay.c.txt", 2048));
|
||||||
writeFile("firmware.s.txt", readFile("configs/5-relay.s.txt", 2048));
|
writeFile("firmware.s.txt", readFile("configs/5-relay.s.txt", 2048));
|
||||||
}
|
}
|
||||||
if (value == "6") {
|
if (value == "6") {
|
||||||
writeFile("firmware.c.txt", readFile("configs/6-relay.c.txt", 2048));
|
writeFile("firmware.c.txt", readFile("configs/6-relay.c.txt", 2048));
|
||||||
writeFile("firmware.s.txt", readFile("configs/6-relay.s.txt", 2048));
|
writeFile("firmware.s.txt", readFile("configs/6-relay.s.txt", 2048));
|
||||||
}
|
}
|
||||||
if (value == "7") {
|
if (value == "7") {
|
||||||
writeFile("firmware.c.txt", readFile("configs/7-relay.c.txt", 2048));
|
writeFile("firmware.c.txt", readFile("configs/7-relay.c.txt", 2048));
|
||||||
writeFile("firmware.s.txt", readFile("configs/7-relay.s.txt", 2048));
|
writeFile("firmware.s.txt", readFile("configs/7-relay.s.txt", 2048));
|
||||||
}
|
}
|
||||||
if (value == "8") {
|
if (value == "8") {
|
||||||
writeFile("firmware.c.txt", readFile("configs/8-pwm.c.txt", 2048));
|
writeFile("firmware.c.txt", readFile("configs/8-pwm.c.txt", 2048));
|
||||||
writeFile("firmware.s.txt", readFile("configs/8-pwm.s.txt", 2048));
|
writeFile("firmware.s.txt", readFile("configs/8-pwm.s.txt", 2048));
|
||||||
}
|
}
|
||||||
if (value == "9") {
|
if (value == "9") {
|
||||||
writeFile("firmware.c.txt", readFile("configs/9-dht11.c.txt", 2048));
|
writeFile("firmware.c.txt", readFile("configs/9-dht11.c.txt", 2048));
|
||||||
writeFile("firmware.s.txt", readFile("configs/9-dht11.s.txt", 2048));
|
writeFile("firmware.s.txt", readFile("configs/9-dht11.s.txt", 2048));
|
||||||
}
|
}
|
||||||
if (value == "10") {
|
if (value == "10") {
|
||||||
writeFile("firmware.c.txt", readFile("configs/10-dht22.c.txt", 2048));
|
writeFile("firmware.c.txt", readFile("configs/10-dht22.c.txt", 2048));
|
||||||
writeFile("firmware.s.txt", readFile("configs/10-dht22.s.txt", 2048));
|
writeFile("firmware.s.txt", readFile("configs/10-dht22.s.txt", 2048));
|
||||||
}
|
}
|
||||||
if (value == "11") {
|
if (value == "11") {
|
||||||
writeFile("firmware.c.txt", readFile("configs/11-analog.c.txt", 2048));
|
writeFile("firmware.c.txt", readFile("configs/11-analog.c.txt", 2048));
|
||||||
writeFile("firmware.s.txt", readFile("configs/11-analog.s.txt", 2048));
|
writeFile("firmware.s.txt", readFile("configs/11-analog.s.txt", 2048));
|
||||||
}
|
}
|
||||||
if (value == "12") {
|
if (value == "12") {
|
||||||
writeFile("firmware.c.txt", readFile("configs/12-bmp280.c.txt", 2048));
|
writeFile("firmware.c.txt", readFile("configs/12-bmp280.c.txt", 2048));
|
||||||
writeFile("firmware.s.txt", readFile("configs/12-bmp280.s.txt", 2048));
|
writeFile("firmware.s.txt", readFile("configs/12-bmp280.s.txt", 2048));
|
||||||
}
|
}
|
||||||
if (value == "13") {
|
if (value == "13") {
|
||||||
writeFile("firmware.c.txt", readFile("configs/13-bme280.c.txt", 2048));
|
writeFile("firmware.c.txt", readFile("configs/13-bme280.c.txt", 2048));
|
||||||
writeFile("firmware.s.txt", readFile("configs/13-bme280.s.txt", 2048));
|
writeFile("firmware.s.txt", readFile("configs/13-bme280.s.txt", 2048));
|
||||||
}
|
}
|
||||||
if (value == "14") {
|
if (value == "14") {
|
||||||
writeFile("firmware.c.txt", readFile("configs/14-dallas.c.txt", 2048));
|
writeFile("firmware.c.txt", readFile("configs/14-dallas.c.txt", 2048));
|
||||||
writeFile("firmware.s.txt", readFile("configs/14-dallas.s.txt", 2048));
|
writeFile("firmware.s.txt", readFile("configs/14-dallas.s.txt", 2048));
|
||||||
}
|
}
|
||||||
if (value == "15") {
|
if (value == "15") {
|
||||||
writeFile("firmware.c.txt", readFile("configs/15-termostat.c.txt", 2048));
|
writeFile("firmware.c.txt", readFile("configs/15-termostat.c.txt", 2048));
|
||||||
writeFile("firmware.s.txt", readFile("configs/15-termostat.s.txt", 2048));
|
writeFile("firmware.s.txt", readFile("configs/15-termostat.s.txt", 2048));
|
||||||
}
|
}
|
||||||
if (value == "16") {
|
if (value == "16") {
|
||||||
writeFile("firmware.c.txt", readFile("configs/16-ultrasonic.c.txt", 2048));
|
writeFile("firmware.c.txt", readFile("configs/16-ultrasonic.c.txt", 2048));
|
||||||
writeFile("firmware.s.txt", readFile("configs/16-ultrasonic.s.txt", 2048));
|
writeFile("firmware.s.txt", readFile("configs/16-ultrasonic.s.txt", 2048));
|
||||||
}
|
}
|
||||||
if (value == "17") {
|
if (value == "17") {
|
||||||
writeFile("firmware.c.txt", readFile("configs/17-moution.c.txt", 2048));
|
writeFile("firmware.c.txt", readFile("configs/17-moution.c.txt", 2048));
|
||||||
writeFile("firmware.s.txt", readFile("configs/17-moution.s.txt", 2048));
|
writeFile("firmware.s.txt", readFile("configs/17-moution.s.txt", 2048));
|
||||||
}
|
}
|
||||||
if (value == "18") {
|
if (value == "18") {
|
||||||
writeFile("firmware.c.txt", readFile("configs/18-moution.c.txt", 2048));
|
writeFile("firmware.c.txt", readFile("configs/18-moution.c.txt", 2048));
|
||||||
writeFile("firmware.s.txt", readFile("configs/18-moution.s.txt", 2048));
|
writeFile("firmware.s.txt", readFile("configs/18-moution.s.txt", 2048));
|
||||||
}
|
}
|
||||||
if (value == "19") {
|
if (value == "19") {
|
||||||
writeFile("firmware.c.txt", readFile("configs/19-stepper.c.txt", 2048));
|
writeFile("firmware.c.txt", readFile("configs/19-stepper.c.txt", 2048));
|
||||||
writeFile("firmware.s.txt", readFile("configs/19-stepper.s.txt", 2048));
|
writeFile("firmware.s.txt", readFile("configs/19-stepper.s.txt", 2048));
|
||||||
}
|
}
|
||||||
if (value == "20") {
|
if (value == "20") {
|
||||||
writeFile("firmware.c.txt", readFile("configs/20-servo.c.txt", 2048));
|
writeFile("firmware.c.txt", readFile("configs/20-servo.c.txt", 2048));
|
||||||
writeFile("firmware.s.txt", readFile("configs/20-servo.s.txt", 2048));
|
writeFile("firmware.s.txt", readFile("configs/20-servo.s.txt", 2048));
|
||||||
}
|
}
|
||||||
if (value == "21") {
|
if (value == "21") {
|
||||||
writeFile("firmware.c.txt", readFile("configs/firmware.c.txt", 2048));
|
writeFile("firmware.c.txt", readFile("configs/firmware.c.txt", 2048));
|
||||||
writeFile("firmware.s.txt", readFile("configs/firmware.s.txt", 2048));
|
writeFile("firmware.s.txt", readFile("configs/firmware.s.txt", 2048));
|
||||||
}
|
}
|
||||||
Device_init();
|
Device_init();
|
||||||
Scenario_init();
|
Scenario_init();
|
||||||
request->redirect("/?set.device");
|
request->redirect("/?set.device");
|
||||||
}
|
}
|
||||||
//--------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------
|
||||||
if (request->hasArg("devinit")) {
|
if (request->hasArg("devinit")) {
|
||||||
Device_init();
|
Device_init();
|
||||||
request->send(200, "text/text", "OK");
|
request->send(200, "text/text", "OK");
|
||||||
}
|
}
|
||||||
//--------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------
|
||||||
if (request->hasArg("scen")) {
|
if (request->hasArg("scen")) {
|
||||||
value = request->getParam("scen")->value();
|
value = request->getParam("scen")->value();
|
||||||
if (value == "0") {
|
if (value == "0") {
|
||||||
jsonWriteStr(configSetupJson, "scen", value);
|
jsonWriteStr(configSetupJson, "scen", value);
|
||||||
saveConfig();
|
saveConfig();
|
||||||
Scenario_init();
|
Scenario_init();
|
||||||
}
|
}
|
||||||
if (value == "1") {
|
if (value == "1") {
|
||||||
jsonWriteStr(configSetupJson, "scen", value);
|
jsonWriteStr(configSetupJson, "scen", value);
|
||||||
saveConfig();
|
saveConfig();
|
||||||
Scenario_init();
|
Scenario_init();
|
||||||
}
|
}
|
||||||
request->send(200, "text/text", "OK");
|
request->send(200, "text/text", "OK");
|
||||||
}
|
}
|
||||||
//--------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------
|
||||||
if (request->hasArg("sceninit")) {
|
if (request->hasArg("sceninit")) {
|
||||||
Scenario_init();
|
Scenario_init();
|
||||||
request->send(200, "text/text", "OK");
|
request->send(200, "text/text", "OK");
|
||||||
}
|
}
|
||||||
//--------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------
|
||||||
#ifdef logging_enable
|
#ifdef logging_enable
|
||||||
if (request->hasArg("cleanlog")) {
|
if (request->hasArg("cleanlog")) {
|
||||||
clean_log_date();
|
clean_log_date();
|
||||||
request->send(200, "text/text", "OK");
|
request->send(200, "text/text", "OK");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
//==============================udp settings=============================================
|
//==============================udp settings=============================================
|
||||||
if (request->hasArg("udponoff")) {
|
if (request->hasArg("udponoff")) {
|
||||||
value = request->getParam("udponoff")->value();
|
value = request->getParam("udponoff")->value();
|
||||||
if (value == "0") {
|
if (value == "0") {
|
||||||
jsonWriteStr(configSetupJson, "udponoff", value);
|
jsonWriteStr(configSetupJson, "udponoff", value);
|
||||||
saveConfig();
|
saveConfig();
|
||||||
Scenario_init();
|
Scenario_init();
|
||||||
}
|
}
|
||||||
if (value == "1") {
|
if (value == "1") {
|
||||||
jsonWriteStr(configSetupJson, "udponoff", value);
|
jsonWriteStr(configSetupJson, "udponoff", value);
|
||||||
saveConfig();
|
saveConfig();
|
||||||
Scenario_init();
|
Scenario_init();
|
||||||
}
|
}
|
||||||
request->send(200, "text/text", "OK");
|
request->send(200, "text/text", "OK");
|
||||||
}
|
}
|
||||||
//--------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------
|
||||||
if (request->hasArg("updatelist")) {
|
if (request->hasArg("updatelist")) {
|
||||||
SPIFFS.remove("/dev.csv");
|
LittleFS.remove("/dev.csv");
|
||||||
addFile("dev.csv", "device id;device name;ip address");
|
addFile("dev.csv", "device id;device name;ip address");
|
||||||
request->redirect("/?set.udp");
|
request->redirect("/?set.udp");
|
||||||
}
|
}
|
||||||
//--------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------
|
||||||
if (request->hasArg("updatepage")) {
|
if (request->hasArg("updatepage")) {
|
||||||
request->redirect("/?set.udp");
|
request->redirect("/?set.udp");
|
||||||
}
|
}
|
||||||
//--------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------
|
||||||
if (request->hasArg("devname")) {
|
if (request->hasArg("devname")) {
|
||||||
jsonWriteStr(configSetupJson, "name", request->getParam("devname")->value());
|
jsonWriteStr(configSetupJson, "name", request->getParam("devname")->value());
|
||||||
saveConfig();
|
saveConfig();
|
||||||
request->send(200, "text/text", "OK");
|
request->send(200, "text/text", "OK");
|
||||||
}
|
}
|
||||||
//==============================wifi settings=============================================
|
//==============================wifi settings=============================================
|
||||||
if (request->hasArg("routerssid")) {
|
if (request->hasArg("routerssid")) {
|
||||||
jsonWriteStr(configSetupJson, "routerssid", request->getParam("routerssid")->value());
|
jsonWriteStr(configSetupJson, "routerssid", request->getParam("routerssid")->value());
|
||||||
saveConfig();
|
saveConfig();
|
||||||
request->send(200, "text/text", "OK");
|
request->send(200, "text/text", "OK");
|
||||||
}
|
}
|
||||||
if (request->hasArg("routerpass")) {
|
if (request->hasArg("routerpass")) {
|
||||||
jsonWriteStr(configSetupJson, "routerpass", request->getParam("routerpass")->value());
|
jsonWriteStr(configSetupJson, "routerpass", request->getParam("routerpass")->value());
|
||||||
saveConfig();
|
saveConfig();
|
||||||
request->send(200, "text/text", "OK");
|
request->send(200, "text/text", "OK");
|
||||||
}
|
}
|
||||||
//--------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------
|
||||||
if (request->hasArg("apssid")) {
|
if (request->hasArg("apssid")) {
|
||||||
jsonWriteStr(configSetupJson, "apssid", request->getParam("apssid")->value());
|
jsonWriteStr(configSetupJson, "apssid", request->getParam("apssid")->value());
|
||||||
saveConfig();
|
saveConfig();
|
||||||
request->send(200, "text/text", "OK");
|
request->send(200, "text/text", "OK");
|
||||||
}
|
}
|
||||||
if (request->hasArg("appass")) {
|
if (request->hasArg("appass")) {
|
||||||
jsonWriteStr(configSetupJson, "appass", request->getParam("appass")->value());
|
jsonWriteStr(configSetupJson, "appass", request->getParam("appass")->value());
|
||||||
saveConfig();
|
saveConfig();
|
||||||
request->send(200, "text/text", "OK");
|
request->send(200, "text/text", "OK");
|
||||||
}
|
}
|
||||||
//--------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------
|
||||||
if (request->hasArg("weblogin")) {
|
if (request->hasArg("weblogin")) {
|
||||||
jsonWriteStr(configSetupJson, "weblogin", request->getParam("weblogin")->value());
|
jsonWriteStr(configSetupJson, "weblogin", request->getParam("weblogin")->value());
|
||||||
saveConfig();
|
saveConfig();
|
||||||
request->send(200, "text/text", "OK");
|
request->send(200, "text/text", "OK");
|
||||||
}
|
}
|
||||||
if (request->hasArg("webpass")) {
|
if (request->hasArg("webpass")) {
|
||||||
jsonWriteStr(configSetupJson, "webpass", request->getParam("webpass")->value());
|
jsonWriteStr(configSetupJson, "webpass", request->getParam("webpass")->value());
|
||||||
saveConfig();
|
saveConfig();
|
||||||
request->send(200, "text/text", "OK");
|
request->send(200, "text/text", "OK");
|
||||||
}
|
}
|
||||||
//--------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------
|
||||||
if (request->hasArg("timezone")) {
|
if (request->hasArg("timezone")) {
|
||||||
jsonWriteStr(configSetupJson, "timezone", request->getParam("timezone")->value());
|
jsonWriteStr(configSetupJson, "timezone", request->getParam("timezone")->value());
|
||||||
saveConfig();
|
saveConfig();
|
||||||
reconfigTime();
|
reconfigTime();
|
||||||
request->send(200, "text/text", "OK");
|
request->send(200, "text/text", "OK");
|
||||||
}
|
}
|
||||||
if (request->hasArg("ntp")) {
|
if (request->hasArg("ntp")) {
|
||||||
jsonWriteStr(configSetupJson, "ntp", request->getParam("ntp")->value());
|
jsonWriteStr(configSetupJson, "ntp", request->getParam("ntp")->value());
|
||||||
saveConfig();
|
saveConfig();
|
||||||
reconfigTime();
|
reconfigTime();
|
||||||
request->send(200, "text/text", "OK");
|
request->send(200, "text/text", "OK");
|
||||||
}
|
}
|
||||||
//--------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------
|
||||||
if (request->hasArg("device")) {
|
if (request->hasArg("device")) {
|
||||||
if (request->getParam("device")->value() == "ok") ESP.restart();
|
if (request->getParam("device")->value() == "ok") ESP.restart();
|
||||||
request->send(200, "text/text", "OK");
|
request->send(200, "text/text", "OK");
|
||||||
}
|
}
|
||||||
//--------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------
|
||||||
if (request->hasArg("blink")) {
|
if (request->hasArg("blink")) {
|
||||||
value = request->getParam("blink")->value();
|
value = request->getParam("blink")->value();
|
||||||
if (value == "0") {
|
if (value == "0") {
|
||||||
jsonWriteStr(configSetupJson, "blink", value);
|
jsonWriteStr(configSetupJson, "blink", value);
|
||||||
saveConfig();
|
saveConfig();
|
||||||
}
|
}
|
||||||
if (value == "1") {
|
if (value == "1") {
|
||||||
jsonWriteStr(configSetupJson, "blink", value);
|
jsonWriteStr(configSetupJson, "blink", value);
|
||||||
saveConfig();
|
saveConfig();
|
||||||
}
|
}
|
||||||
request->send(200, "text/text", "OK");
|
request->send(200, "text/text", "OK");
|
||||||
}
|
}
|
||||||
//==============================mqtt settings=============================================
|
//==============================mqtt settings=============================================
|
||||||
if (request->hasArg("mqttServer")) {
|
if (request->hasArg("mqttServer")) {
|
||||||
jsonWriteStr(configSetupJson, "mqttServer", request->getParam("mqttServer")->value());
|
jsonWriteStr(configSetupJson, "mqttServer", request->getParam("mqttServer")->value());
|
||||||
saveConfig();
|
saveConfig();
|
||||||
mqtt_connection = true;
|
mqtt_connection = true;
|
||||||
request->send(200, "text/text", "ok");
|
request->send(200, "text/text", "ok");
|
||||||
}
|
}
|
||||||
if (request->hasArg("mqttPort")) {
|
if (request->hasArg("mqttPort")) {
|
||||||
int port = (request->getParam("mqttPort")->value()).toInt();
|
int port = (request->getParam("mqttPort")->value()).toInt();
|
||||||
jsonWriteInt(configSetupJson, "mqttPort", port);
|
jsonWriteInt(configSetupJson, "mqttPort", port);
|
||||||
saveConfig();
|
saveConfig();
|
||||||
mqtt_connection = true;
|
mqtt_connection = true;
|
||||||
request->send(200, "text/text", "ok");
|
request->send(200, "text/text", "ok");
|
||||||
}
|
}
|
||||||
if (request->hasArg("mqttPrefix")) {
|
if (request->hasArg("mqttPrefix")) {
|
||||||
jsonWriteStr(configSetupJson, "mqttPrefix", request->getParam("mqttPrefix")->value());
|
jsonWriteStr(configSetupJson, "mqttPrefix", request->getParam("mqttPrefix")->value());
|
||||||
saveConfig();
|
saveConfig();
|
||||||
mqtt_connection = true;
|
mqtt_connection = true;
|
||||||
request->send(200, "text/text", "ok");
|
request->send(200, "text/text", "ok");
|
||||||
}
|
}
|
||||||
if (request->hasArg("mqttUser")) {
|
if (request->hasArg("mqttUser")) {
|
||||||
jsonWriteStr(configSetupJson, "mqttUser", request->getParam("mqttUser")->value());
|
jsonWriteStr(configSetupJson, "mqttUser", request->getParam("mqttUser")->value());
|
||||||
saveConfig();
|
saveConfig();
|
||||||
mqtt_connection = true;
|
mqtt_connection = true;
|
||||||
request->send(200, "text/text", "ok");
|
request->send(200, "text/text", "ok");
|
||||||
}
|
}
|
||||||
if (request->hasArg("mqttPass")) {
|
if (request->hasArg("mqttPass")) {
|
||||||
jsonWriteStr(configSetupJson, "mqttPass", request->getParam("mqttPass")->value());
|
jsonWriteStr(configSetupJson, "mqttPass", request->getParam("mqttPass")->value());
|
||||||
saveConfig();
|
saveConfig();
|
||||||
mqtt_connection = true;
|
mqtt_connection = true;
|
||||||
request->send(200, "text/text", "ok");
|
request->send(200, "text/text", "ok");
|
||||||
}
|
}
|
||||||
//--------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------
|
||||||
if (request->hasArg("mqttsend")) {
|
if (request->hasArg("mqttsend")) {
|
||||||
mqtt_send_settings_to_udp = true;
|
mqtt_send_settings_to_udp = true;
|
||||||
request->send(200, "text/text", "ok");
|
request->send(200, "text/text", "ok");
|
||||||
}
|
}
|
||||||
//--------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------
|
||||||
if (request->hasArg("mqttcheck")) {
|
if (request->hasArg("mqttcheck")) {
|
||||||
String tmp = "{}";
|
String tmp = "{}";
|
||||||
jsonWriteStr(tmp, "title", "<button class=\"close\" onclick=\"toggle('my-block')\">×</button>" + stateMQTT());
|
jsonWriteStr(tmp, "title", "<button class=\"close\" onclick=\"toggle('my-block')\">×</button>" + stateMQTT());
|
||||||
jsonWriteStr(tmp, "class", "pop-up");
|
jsonWriteStr(tmp, "class", "pop-up");
|
||||||
request->send(200, "text/text", tmp);
|
request->send(200, "text/text", tmp);
|
||||||
}
|
}
|
||||||
//==============================push settings=============================================
|
//==============================push settings=============================================
|
||||||
#ifdef push_enable
|
#ifdef push_enable
|
||||||
if (request->hasArg("pushingboxid")) {
|
if (request->hasArg("pushingboxid")) {
|
||||||
jsonWriteStr(configSetupJson, "pushingboxid", request->getParam("pushingboxid")->value());
|
jsonWriteStr(configSetupJson, "pushingboxid", request->getParam("pushingboxid")->value());
|
||||||
saveConfig();
|
saveConfig();
|
||||||
request->send(200, "text/text", "ok");
|
request->send(200, "text/text", "ok");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
//==============================utilities settings=============================================
|
//==============================utilities settings=============================================
|
||||||
if (request->hasArg("itoc")) {
|
if (request->hasArg("itoc")) {
|
||||||
i2c_scanning = true;
|
i2c_scanning = true;
|
||||||
request->redirect("/?set.utilities");
|
request->redirect("/?set.utilities");
|
||||||
}
|
|
||||||
});
|
|
||||||
//==============================upgrade settings=============================================
|
|
||||||
server.on("/check", HTTP_GET, [](AsyncWebServerRequest * request) {
|
|
||||||
upgrade_url = true;
|
|
||||||
Serial.print("[i] Last firmware version: ");
|
|
||||||
Serial.println(last_version);
|
|
||||||
String tmp = "{}";
|
|
||||||
int case_of_update;
|
|
||||||
|
|
||||||
if (WiFi.status() != WL_CONNECTED) last_version = "nowifi";
|
|
||||||
if (!mb_4_of_memory) last_version = "less";
|
|
||||||
|
|
||||||
if (last_version == firmware_version) case_of_update = 1;
|
|
||||||
if (last_version != firmware_version) case_of_update = 2;
|
|
||||||
if (last_version == "error") case_of_update = 3;
|
|
||||||
if (last_version == "") case_of_update = 4;
|
|
||||||
if (last_version == "less") case_of_update = 5;
|
|
||||||
if (last_version == "nowifi") case_of_update = 6;
|
|
||||||
if (last_version == "notsupported") case_of_update = 7;
|
|
||||||
|
|
||||||
switch (case_of_update) {
|
|
||||||
case 1: {
|
|
||||||
jsonWriteStr(tmp, "title", "<button class=\"close\" onclick=\"toggle('my-block')\">×</button>Последняя версия прошивки уже установлена.");
|
|
||||||
jsonWriteStr(tmp, "class", "pop-up");
|
|
||||||
}
|
}
|
||||||
break;
|
});
|
||||||
|
//==============================upgrade settings=============================================
|
||||||
|
server.on("/check", HTTP_GET, [](AsyncWebServerRequest* request) {
|
||||||
|
upgrade_url = true;
|
||||||
|
Serial.print("[I] Last firmware version: ");
|
||||||
|
Serial.println(last_version);
|
||||||
|
String tmp = "{}";
|
||||||
|
int case_of_update;
|
||||||
|
|
||||||
case 2: {
|
if (WiFi.status() != WL_CONNECTED) last_version = "nowifi";
|
||||||
jsonWriteStr(tmp, "title", "<button class=\"close\" onclick=\"toggle('my-block')\">×</button>Имеется новая версия прошивки<a href=\"#\" class=\"btn btn-block btn-danger\" onclick=\"send_request(this, '/upgrade');setTimeout(function(){ location.href='/'; }, 120000);html('my-block','<span class=loader></span>Идет обновление прошивки, после обновления страница перезагрузится автоматически...')\">Установить</a>");
|
if (!mb_4_of_memory) last_version = "less";
|
||||||
jsonWriteStr(tmp, "class", "pop-up");
|
|
||||||
|
if (last_version == firmware_version) case_of_update = 1;
|
||||||
|
if (last_version != firmware_version) case_of_update = 2;
|
||||||
|
if (last_version == "error") case_of_update = 3;
|
||||||
|
if (last_version == "") case_of_update = 4;
|
||||||
|
if (last_version == "less") case_of_update = 5;
|
||||||
|
if (last_version == "nowifi") case_of_update = 6;
|
||||||
|
if (last_version == "notsupported") case_of_update = 7;
|
||||||
|
|
||||||
|
switch (case_of_update) {
|
||||||
|
case 1: {
|
||||||
|
jsonWriteStr(tmp, "title", "<button class=\"close\" onclick=\"toggle('my-block')\">×</button>Последняя версия прошивки уже установлена.");
|
||||||
|
jsonWriteStr(tmp, "class", "pop-up");
|
||||||
|
} break;
|
||||||
|
|
||||||
|
case 2: {
|
||||||
|
jsonWriteStr(tmp, "title", "<button class=\"close\" onclick=\"toggle('my-block')\">×</button>Имеется новая версия прошивки<a href=\"#\" class=\"btn btn-block btn-danger\" onclick=\"send_request(this, '/upgrade');setTimeout(function(){ location.href='/'; }, 120000);html('my-block','<span class=loader></span>Идет обновление прошивки, после обновления страница перезагрузится автоматически...')\">Установить</a>");
|
||||||
|
jsonWriteStr(tmp, "class", "pop-up");
|
||||||
|
} break;
|
||||||
|
|
||||||
|
case 3: {
|
||||||
|
jsonWriteStr(tmp, "title", "<button class=\"close\" onclick=\"toggle('my-block')\">×</button>Ошибка... Cервер не найден. Попробуйте позже...");
|
||||||
|
jsonWriteStr(tmp, "class", "pop-up");
|
||||||
|
} break;
|
||||||
|
|
||||||
|
case 4: {
|
||||||
|
jsonWriteStr(tmp, "title", "<button class=\"close\" onclick=\"toggle('my-block')\">×</button>Нажмите на кнопку \"обновить прошивку\" повторно...");
|
||||||
|
jsonWriteStr(tmp, "class", "pop-up");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 5: {
|
||||||
|
jsonWriteStr(tmp, "title", "<button class=\"close\" onclick=\"toggle('my-block')\">×</button>Обновление по воздуху не поддерживается, модуль имеет меньше 4 мб памяти...");
|
||||||
|
jsonWriteStr(tmp, "class", "pop-up");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 6: {
|
||||||
|
jsonWriteStr(tmp, "title", "<button class=\"close\" onclick=\"toggle('my-block')\">×</button>Устройство не подключено к роутеру...");
|
||||||
|
jsonWriteStr(tmp, "class", "pop-up");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 7: {
|
||||||
|
jsonWriteStr(tmp, "title", "<button class=\"close\" onclick=\"toggle('my-block')\">×</button>Обновление на новую версию возможно только через usb...");
|
||||||
|
jsonWriteStr(tmp, "class", "pop-up");
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
request->send(200, "text/text", tmp);
|
||||||
|
});
|
||||||
|
|
||||||
case 3: {
|
server.on("/upgrade", HTTP_GET, [](AsyncWebServerRequest* request) {
|
||||||
jsonWriteStr(tmp, "title", "<button class=\"close\" onclick=\"toggle('my-block')\">×</button>Ошибка... Cервер не найден. Попробуйте позже...");
|
upgrade = true;
|
||||||
jsonWriteStr(tmp, "class", "pop-up");
|
String tmp = "{}";
|
||||||
}
|
request->send(200, "text/text", "ok");
|
||||||
break;
|
});
|
||||||
|
|
||||||
case 4: {
|
|
||||||
jsonWriteStr(tmp, "title", "<button class=\"close\" onclick=\"toggle('my-block')\">×</button>Нажмите на кнопку \"обновить прошивку\" повторно...");
|
|
||||||
jsonWriteStr(tmp, "class", "pop-up");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 5: {
|
|
||||||
jsonWriteStr(tmp, "title", "<button class=\"close\" onclick=\"toggle('my-block')\">×</button>Обновление по воздуху не поддерживается, модуль имеет меньше 4 мб памяти...");
|
|
||||||
jsonWriteStr(tmp, "class", "pop-up");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 6: {
|
|
||||||
jsonWriteStr(tmp, "title", "<button class=\"close\" onclick=\"toggle('my-block')\">×</button>Устройство не подключено к роутеру...");
|
|
||||||
jsonWriteStr(tmp, "class", "pop-up");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 7: {
|
|
||||||
jsonWriteStr(tmp, "title", "<button class=\"close\" onclick=\"toggle('my-block')\">×</button>Обновление на новую версию возможно только через usb...");
|
|
||||||
jsonWriteStr(tmp, "class", "pop-up");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
request->send(200, "text/text", tmp);
|
|
||||||
});
|
|
||||||
|
|
||||||
server.on("/upgrade", HTTP_GET, [](AsyncWebServerRequest * request) {
|
|
||||||
upgrade = true;
|
|
||||||
String tmp = "{}";
|
|
||||||
request->send(200, "text/text", "ok");
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
@@ -1,234 +1,236 @@
|
|||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
|
|
||||||
void Web_server_init() {
|
void Web_server_init() {
|
||||||
/*********************************************************************************
|
/*********************************************************************************
|
||||||
***************************************OTA****************************************
|
***************************************OTA****************************************
|
||||||
*********************************************************************************/
|
*********************************************************************************/
|
||||||
#ifdef OTA_enable
|
#ifdef OTA_enable
|
||||||
ArduinoOTA.onStart([]() {
|
ArduinoOTA.onStart([]() {
|
||||||
events.send("Update Start", "ota");
|
events.send("Update Start", "ota");
|
||||||
});
|
});
|
||||||
ArduinoOTA.onEnd([]() {
|
ArduinoOTA.onEnd([]() {
|
||||||
events.send("Update End", "ota");
|
events.send("Update End", "ota");
|
||||||
});
|
});
|
||||||
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
|
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
|
||||||
char p[32];
|
char p[32];
|
||||||
sprintf(p, "Progress: %u%%\n", (progress / (total / 100)));
|
sprintf(p, "Progress: %u%%\n", (progress / (total / 100)));
|
||||||
events.send(p, "ota");
|
events.send(p, "ota");
|
||||||
});
|
});
|
||||||
ArduinoOTA.onError([](ota_error_t error) {
|
ArduinoOTA.onError([](ota_error_t error) {
|
||||||
if (error == OTA_AUTH_ERROR) events.send("Auth Failed", "ota");
|
if (error == OTA_AUTH_ERROR)
|
||||||
else if (error == OTA_BEGIN_ERROR) events.send("Begin Failed", "ota");
|
events.send("Auth Failed", "ota");
|
||||||
else if (error == OTA_CONNECT_ERROR) events.send("Connect Failed", "ota");
|
else if (error == OTA_BEGIN_ERROR)
|
||||||
else if (error == OTA_RECEIVE_ERROR) events.send("Recieve Failed", "ota");
|
events.send("Begin Failed", "ota");
|
||||||
else if (error == OTA_END_ERROR) events.send("End Failed", "ota");
|
else if (error == OTA_CONNECT_ERROR)
|
||||||
});
|
events.send("Connect Failed", "ota");
|
||||||
ArduinoOTA.setHostname(hostName);
|
else if (error == OTA_RECEIVE_ERROR)
|
||||||
ArduinoOTA.begin();
|
events.send("Recieve Failed", "ota");
|
||||||
|
else if (error == OTA_END_ERROR)
|
||||||
|
events.send("End Failed", "ota");
|
||||||
|
});
|
||||||
|
ArduinoOTA.setHostname(hostName);
|
||||||
|
ArduinoOTA.begin();
|
||||||
#endif
|
#endif
|
||||||
/*********************************************************************************
|
/*********************************************************************************
|
||||||
**************************************MDNS****************************************
|
**************************************MDNS****************************************
|
||||||
*********************************************************************************/
|
*********************************************************************************/
|
||||||
#ifdef MDNS_enable
|
#ifdef MDNS_enable
|
||||||
MDNS.addService("http", "tcp", 80);
|
MDNS.addService("http", "tcp", 80);
|
||||||
#endif
|
#endif
|
||||||
//SPIFFS.begin();
|
//LittleFS.begin();
|
||||||
/*********************************************************************************
|
/*********************************************************************************
|
||||||
**************************************WS******************************************
|
**************************************WS******************************************
|
||||||
*********************************************************************************/
|
*********************************************************************************/
|
||||||
#ifdef WS_enable
|
#ifdef WS_enable
|
||||||
ws.onEvent(onWsEvent);
|
ws.onEvent(onWsEvent);
|
||||||
server.addHandler(&ws);
|
server.addHandler(&ws);
|
||||||
|
|
||||||
events.onConnect([](AsyncEventSourceClient * client) {
|
events.onConnect([](AsyncEventSourceClient *client) {
|
||||||
//!!!client->send("hello!", NULL, millis(), 1000);
|
//!!!client->send("hello!", NULL, millis(), 1000);
|
||||||
});
|
});
|
||||||
|
|
||||||
server.addHandler(&events);
|
server.addHandler(&events);
|
||||||
#endif
|
#endif
|
||||||
/*********************************************************************************
|
/*********************************************************************************
|
||||||
**************************************WEB****************************************
|
**************************************WEB****************************************
|
||||||
*********************************************************************************/
|
*********************************************************************************/
|
||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
server.addHandler(new SPIFFSEditor(SPIFFS, jsonReadStr(configSetupJson, "weblogin").c_str(), jsonReadStr(configSetupJson, "webpass").c_str()));
|
server.addHandler(new SPIFFSEditor(LittleFS, jsonReadStr(configSetupJson, "weblogin").c_str(), jsonReadStr(configSetupJson, "webpass").c_str()));
|
||||||
#elif defined(ESP8266)
|
#elif defined(ESP8266)
|
||||||
server.addHandler(new SPIFFSEditor(jsonReadStr(configSetupJson, "weblogin").c_str(), jsonReadStr(configSetupJson, "webpass").c_str()));
|
server.addHandler(new SPIFFSEditor(jsonReadStr(configSetupJson, "weblogin").c_str(), jsonReadStr(configSetupJson, "webpass").c_str()));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* server.on("/heap", HTTP_GET, [](AsyncWebServerRequest * request) {
|
/* server.on("/heap", HTTP_GET, [](AsyncWebServerRequest * request) {
|
||||||
request->send(200, "text/plain", String(ESP.getFreeHeap()));
|
request->send(200, "text/plain", String(ESP.getFreeHeap()));
|
||||||
});*/
|
});*/
|
||||||
|
|
||||||
server.serveStatic("/css/", SPIFFS, "/css/").setCacheControl("max-age=31536000");
|
server.serveStatic("/css/", LittleFS, "/css/").setCacheControl("max-age=31536000");
|
||||||
server.serveStatic("/js/", SPIFFS, "/js/").setCacheControl("max-age=31536000");
|
server.serveStatic("/js/", LittleFS, "/js/").setCacheControl("max-age=31536000");
|
||||||
server.serveStatic("/favicon.ico", SPIFFS, "/favicon.ico").setCacheControl("max-age=31536000");
|
server.serveStatic("/favicon.ico", LittleFS, "/favicon.ico").setCacheControl("max-age=31536000");
|
||||||
server.serveStatic("/icon.jpeg", SPIFFS, "/icon.jpeg").setCacheControl("max-age=31536000");
|
server.serveStatic("/icon.jpeg", LittleFS, "/icon.jpeg").setCacheControl("max-age=31536000");
|
||||||
|
|
||||||
server.serveStatic("/", SPIFFS, "/").setDefaultFile("index.htm")
|
server.serveStatic("/", LittleFS, "/").setDefaultFile("index.htm").setAuthentication(jsonReadStr(configSetupJson, "weblogin").c_str(), jsonReadStr(configSetupJson, "webpass").c_str());
|
||||||
.setAuthentication(jsonReadStr(configSetupJson, "weblogin").c_str(), jsonReadStr(configSetupJson, "webpass").c_str());
|
|
||||||
|
|
||||||
server.onNotFound([](AsyncWebServerRequest * request) {
|
server.onNotFound([](AsyncWebServerRequest *request) {
|
||||||
Serial.printf("NOT_FOUND: ");
|
Serial.printf("NOT_FOUND: ");
|
||||||
if (request->method() == HTTP_GET)
|
if (request->method() == HTTP_GET)
|
||||||
Serial.printf("GET");
|
Serial.printf("GET");
|
||||||
else if (request->method() == HTTP_POST)
|
else if (request->method() == HTTP_POST)
|
||||||
Serial.printf("POST");
|
Serial.printf("POST");
|
||||||
else if (request->method() == HTTP_DELETE)
|
else if (request->method() == HTTP_DELETE)
|
||||||
Serial.printf("DELETE");
|
Serial.printf("DELETE");
|
||||||
else if (request->method() == HTTP_PUT)
|
else if (request->method() == HTTP_PUT)
|
||||||
Serial.printf("PUT");
|
Serial.printf("PUT");
|
||||||
else if (request->method() == HTTP_PATCH)
|
else if (request->method() == HTTP_PATCH)
|
||||||
Serial.printf("PATCH");
|
Serial.printf("PATCH");
|
||||||
else if (request->method() == HTTP_HEAD)
|
else if (request->method() == HTTP_HEAD)
|
||||||
Serial.printf("HEAD");
|
Serial.printf("HEAD");
|
||||||
else if (request->method() == HTTP_OPTIONS)
|
else if (request->method() == HTTP_OPTIONS)
|
||||||
Serial.printf("OPTIONS");
|
Serial.printf("OPTIONS");
|
||||||
else
|
else
|
||||||
Serial.printf("UNKNOWN");
|
Serial.printf("UNKNOWN");
|
||||||
Serial.printf(" http://%s%s\n", request->host().c_str(), request->url().c_str());
|
Serial.printf(" http://%s%s\n", request->host().c_str(), request->url().c_str());
|
||||||
|
|
||||||
if (request->contentLength()) {
|
if (request->contentLength()) {
|
||||||
Serial.printf("_CONTENT_TYPE: %s\n", request->contentType().c_str());
|
Serial.printf("_CONTENT_TYPE: %s\n", request->contentType().c_str());
|
||||||
Serial.printf("_CONTENT_LENGTH: %u\n", request->contentLength());
|
Serial.printf("_CONTENT_LENGTH: %u\n", request->contentLength());
|
||||||
}
|
}
|
||||||
|
|
||||||
int headers = request->headers();
|
int headers = request->headers();
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < headers; i++) {
|
for (i = 0; i < headers; i++) {
|
||||||
AsyncWebHeader* h = request->getHeader(i);
|
AsyncWebHeader *h = request->getHeader(i);
|
||||||
Serial.printf("_HEADER[%s]: %s\n", h->name().c_str(), h->value().c_str());
|
Serial.printf("_HEADER[%s]: %s\n", h->name().c_str(), h->value().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
int params = request->params();
|
int params = request->params();
|
||||||
for (i = 0; i < params; i++) {
|
for (i = 0; i < params; i++) {
|
||||||
AsyncWebParameter* p = request->getParam(i);
|
AsyncWebParameter *p = request->getParam(i);
|
||||||
if (p->isFile()) {
|
if (p->isFile()) {
|
||||||
Serial.printf("_FILE[%s]: %s, size: %u\n", p->name().c_str(), p->value().c_str(), p->size());
|
Serial.printf("_FILE[%s]: %s, size: %u\n", p->name().c_str(), p->value().c_str(), p->size());
|
||||||
} else if (p->isPost()) {
|
} else if (p->isPost()) {
|
||||||
Serial.printf("_POST[%s]: %s\n", p->name().c_str(), p->value().c_str());
|
Serial.printf("_POST[%s]: %s\n", p->name().c_str(), p->value().c_str());
|
||||||
} else {
|
} else {
|
||||||
Serial.printf("_GET[%s]: %s\n", p->name().c_str(), p->value().c_str());
|
Serial.printf("_GET[%s]: %s\n", p->name().c_str(), p->value().c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
request->send(404);
|
request->send(404);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
server.onFileUpload([](AsyncWebServerRequest *request, const String &filename, size_t index, uint8_t *data, size_t len, bool final) {
|
||||||
|
if (!index)
|
||||||
|
Serial.printf("UploadStart: %s\n", filename.c_str());
|
||||||
|
Serial.printf("%s", (const char *)data);
|
||||||
|
if (final)
|
||||||
|
Serial.printf("UploadEnd: %s (%u)\n", filename.c_str(), index + len);
|
||||||
|
});
|
||||||
|
|
||||||
server.onFileUpload([](AsyncWebServerRequest * request, const String & filename, size_t index, uint8_t *data, size_t len, bool final) {
|
server.onRequestBody([](AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total) {
|
||||||
if (!index)
|
if (!index)
|
||||||
Serial.printf("UploadStart: %s\n", filename.c_str());
|
Serial.printf("BodyStart: %u\n", total);
|
||||||
Serial.printf("%s", (const char*)data);
|
Serial.printf("%s", (const char *)data);
|
||||||
if (final)
|
if (index + len == total)
|
||||||
Serial.printf("UploadEnd: %s (%u)\n", filename.c_str(), index + len);
|
Serial.printf("BodyEnd: %u\n", total);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
server.begin();
|
||||||
|
|
||||||
server.onRequestBody([](AsyncWebServerRequest * request, uint8_t *data, size_t len, size_t index, size_t total) {
|
// --------------------Выдаем данные configJson //config.live.json - динамические данные
|
||||||
if (!index)
|
server.on("/config.live.json", HTTP_GET, [](AsyncWebServerRequest *request) {
|
||||||
Serial.printf("BodyStart: %u\n", total);
|
request->send(200, "application/json", configLiveJson);
|
||||||
Serial.printf("%s", (const char*)data);
|
});
|
||||||
if (index + len == total)
|
// --------------------Выдаем данные optionJson //config.option.json - данные не являющиеся событиями
|
||||||
Serial.printf("BodyEnd: %u\n", total);
|
server.on("/config.option.json", HTTP_GET, [](AsyncWebServerRequest *request) {
|
||||||
});
|
request->send(200, "application/json", configOptionJson);
|
||||||
|
});
|
||||||
|
// -------------------Выдаем данные configSetup //config.setup.json - для хранения постоянных данных
|
||||||
|
server.on("/config.setup.json", HTTP_GET, [](AsyncWebServerRequest *request) {
|
||||||
|
request->send(200, "application/json", configSetupJson);
|
||||||
|
});
|
||||||
|
|
||||||
server.begin();
|
// ------------------Выполнение команды из запроса
|
||||||
|
//http://192.168.88.45/cmd?command=rel%201%201
|
||||||
// --------------------Выдаем данные configJson //config.live.json - динамические данные
|
server.on("/cmd", HTTP_GET, [](AsyncWebServerRequest *request) {
|
||||||
server.on("/config.live.json", HTTP_GET, [](AsyncWebServerRequest * request) {
|
String com = request->getParam("command")->value();
|
||||||
request->send(200, "application/json", configLiveJson);
|
Serial.println(com);
|
||||||
});
|
order_loop += com + ",";
|
||||||
// --------------------Выдаем данные optionJson //config.option.json - данные не являющиеся событиями
|
request->send(200, "text/text", "OK"); // отправляем ответ о выполнении
|
||||||
server.on("/config.option.json", HTTP_GET, [](AsyncWebServerRequest * request) {
|
});
|
||||||
request->send(200, "application/json", configOptionJson);
|
|
||||||
});
|
|
||||||
// -------------------Выдаем данные configSetup //config.setup.json - для хранения постоянных данных
|
|
||||||
server.on("/config.setup.json", HTTP_GET, [](AsyncWebServerRequest * request) {
|
|
||||||
request->send(200, "application/json", configSetupJson);
|
|
||||||
});
|
|
||||||
|
|
||||||
// ------------------Выполнение команды из запроса
|
|
||||||
//http://192.168.88.45/cmd?command=rel%201%201
|
|
||||||
server.on("/cmd", HTTP_GET, [](AsyncWebServerRequest * request) {
|
|
||||||
String com = request->getParam("command")->value();
|
|
||||||
Serial.println(com);
|
|
||||||
order_loop += com + ",";
|
|
||||||
request->send(200, "text/text", "OK"); // отправляем ответ о выполнении
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
/*********************************************************************************************************************************
|
/*********************************************************************************************************************************
|
||||||
*********************************************************WS**********************************************************************
|
*********************************************************WS**********************************************************************
|
||||||
********************************************************************************************************************************/
|
********************************************************************************************************************************/
|
||||||
#ifdef WS_enable
|
#ifdef WS_enable
|
||||||
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) {
|
||||||
if (type == WS_EVT_CONNECT) {
|
if (type == WS_EVT_CONNECT) {
|
||||||
Serial.printf("ws[%s][%u] connect\n", server->url(), client->id());
|
Serial.printf("ws[%s][%u] connect\n", server->url(), client->id());
|
||||||
client->printf(json.c_str(), client->id());
|
client->printf(json.c_str(), client->id());
|
||||||
//client->ping();
|
//client->ping();
|
||||||
} else if (type == WS_EVT_DISCONNECT) {
|
} else if (type == WS_EVT_DISCONNECT) {
|
||||||
Serial.printf("ws[%s][%u] disconnect\n", server->url(), client->id());
|
Serial.printf("ws[%s][%u] disconnect\n", server->url(), client->id());
|
||||||
} else if (type == WS_EVT_ERROR) {
|
} else if (type == WS_EVT_ERROR) {
|
||||||
Serial.printf("ws[%s][%u] error(%u): %s\n", server->url(), client->id(), *((uint16_t*)arg), (char*)data);
|
Serial.printf("ws[%s][%u] error(%u): %s\n", server->url(), client->id(), *((uint16_t *)arg), (char *)data);
|
||||||
} else if (type == WS_EVT_PONG) {
|
} else if (type == WS_EVT_PONG) {
|
||||||
Serial.printf("ws[%s][%u] pong[%u]: %s\n", server->url(), client->id(), len, (len) ? (char*)data : "");
|
Serial.printf("ws[%s][%u] pong[%u]: %s\n", server->url(), client->id(), len, (len) ? (char *)data : "");
|
||||||
} else if (type == WS_EVT_DATA) {
|
} else if (type == WS_EVT_DATA) {
|
||||||
AwsFrameInfo * info = (AwsFrameInfo*)arg;
|
AwsFrameInfo *info = (AwsFrameInfo *)arg;
|
||||||
String msg = "";
|
String msg = "";
|
||||||
if (info->final && info->index == 0 && info->len == len) {
|
if (info->final && info->index == 0 && info->len == len) {
|
||||||
//the whole message is in a single frame and we got all of it's data
|
//the whole message is in a single frame and we got all of it's data
|
||||||
Serial.printf("ws[%s][%u] %s-message[%llu]: ", server->url(), client->id(), (info->opcode == WS_TEXT) ? "text" : "binary", info->len);
|
Serial.printf("ws[%s][%u] %s-message[%llu]: ", server->url(), client->id(), (info->opcode == WS_TEXT) ? "text" : "binary", info->len);
|
||||||
|
|
||||||
if (info->opcode == WS_TEXT) {
|
if (info->opcode == WS_TEXT) {
|
||||||
for (size_t i = 0; i < info->len; i++) {
|
for (size_t i = 0; i < info->len; i++) {
|
||||||
msg += (char) data[i];
|
msg += (char)data[i];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
char buff[3];
|
char buff[3];
|
||||||
for (size_t i = 0; i < info->len; i++) {
|
for (size_t i = 0; i < info->len; i++) {
|
||||||
sprintf(buff, "%02x ", (uint8_t) data[i]);
|
sprintf(buff, "%02x ", (uint8_t)data[i]);
|
||||||
msg += buff ;
|
msg += buff;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Serial.printf("%s\n", msg.c_str());
|
Serial.printf("%s\n", msg.c_str());
|
||||||
|
|
||||||
if (info->opcode == WS_TEXT)
|
if (info->opcode == WS_TEXT)
|
||||||
client->text("{}");
|
client->text("{}");
|
||||||
else
|
else
|
||||||
client->binary("{}");
|
client->binary("{}");
|
||||||
} else {
|
} else {
|
||||||
//message is comprised of multiple frames or the frame is split into multiple packets
|
//message is comprised of multiple frames or the frame is split into multiple packets
|
||||||
if (info->index == 0) {
|
if (info->index == 0) {
|
||||||
if (info->num == 0)
|
if (info->num == 0)
|
||||||
Serial.printf("ws[%s][%u] %s-message start\n", server->url(), client->id(), (info->message_opcode == WS_TEXT) ? "text" : "binary");
|
Serial.printf("ws[%s][%u] %s-message start\n", server->url(), client->id(), (info->message_opcode == WS_TEXT) ? "text" : "binary");
|
||||||
Serial.printf("ws[%s][%u] frame[%u] start[%llu]\n", server->url(), client->id(), info->num, info->len);
|
Serial.printf("ws[%s][%u] frame[%u] start[%llu]\n", server->url(), client->id(), info->num, info->len);
|
||||||
}
|
}
|
||||||
|
|
||||||
Serial.printf("ws[%s][%u] frame[%u] %s[%llu - %llu]: ", server->url(), client->id(), info->num, (info->message_opcode == WS_TEXT) ? "text" : "binary", info->index, info->index + len);
|
Serial.printf("ws[%s][%u] frame[%u] %s[%llu - %llu]: ", server->url(), client->id(), info->num, (info->message_opcode == WS_TEXT) ? "text" : "binary", info->index, info->index + len);
|
||||||
|
|
||||||
if (info->opcode == WS_TEXT) {
|
if (info->opcode == WS_TEXT) {
|
||||||
for (size_t i = 0; i < len; i++) {
|
for (size_t i = 0; i < len; i++) {
|
||||||
msg += (char) data[i];
|
msg += (char)data[i];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
char buff[3];
|
char buff[3];
|
||||||
for (size_t i = 0; i < len; i++) {
|
for (size_t i = 0; i < len; i++) {
|
||||||
sprintf(buff, "%02x ", (uint8_t) data[i]);
|
sprintf(buff, "%02x ", (uint8_t)data[i]);
|
||||||
msg += buff ;
|
msg += buff;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Serial.printf("%s\n", msg.c_str());
|
Serial.printf("%s\n", msg.c_str());
|
||||||
|
|
||||||
if ((info->index + len) == info->len) {
|
if ((info->index + len) == info->len) {
|
||||||
Serial.printf("ws[%s][%u] frame[%u] end[%llu]\n", server->url(), client->id(), info->num, info->len);
|
Serial.printf("ws[%s][%u] frame[%u] end[%llu]\n", server->url(), client->id(), info->num, info->len);
|
||||||
if (info->final) {
|
if (info->final) {
|
||||||
Serial.printf("ws[%s][%u] %s-message end\n", server->url(), client->id(), (info->message_opcode == WS_TEXT) ? "text" : "binary");
|
Serial.printf("ws[%s][%u] %s-message end\n", server->url(), client->id(), (info->message_opcode == WS_TEXT) ? "text" : "binary");
|
||||||
if (info->message_opcode == WS_TEXT)
|
if (info->message_opcode == WS_TEXT)
|
||||||
client->text("I got your text message");
|
client->text("I got your text message");
|
||||||
else
|
else
|
||||||
client->binary("I got your binary message");
|
client->binary("I got your binary message");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -3,131 +3,109 @@
|
|||||||
boolean RouterFind(String ssid);
|
boolean RouterFind(String ssid);
|
||||||
|
|
||||||
void ROUTER_Connecting() {
|
void ROUTER_Connecting() {
|
||||||
|
led_blink("slow");
|
||||||
|
|
||||||
led_blink("slow");
|
WiFi.mode(WIFI_STA);
|
||||||
|
|
||||||
WiFi.mode(WIFI_STA);
|
byte tries = 20;
|
||||||
|
String _ssid = jsonReadStr(configSetupJson, "routerssid");
|
||||||
|
String _password = jsonReadStr(configSetupJson, "routerpass");
|
||||||
|
//WiFi.persistent(false);
|
||||||
|
|
||||||
byte tries = 20;
|
if (_ssid == "" && _password == "") {
|
||||||
String _ssid = jsonReadStr(configSetupJson, "routerssid");
|
WiFi.begin();
|
||||||
String _password = jsonReadStr(configSetupJson, "routerpass");
|
} else {
|
||||||
//WiFi.persistent(false);
|
WiFi.begin(_ssid.c_str(), _password.c_str());
|
||||||
|
Serial.print("ssid: ");
|
||||||
if (_ssid == "" && _password == "") {
|
Serial.println(_ssid);
|
||||||
WiFi.begin();
|
}
|
||||||
}
|
// Делаем проверку подключения до тех пор пока счетчик tries
|
||||||
else {
|
// не станет равен нулю или не получим подключение
|
||||||
WiFi.begin(_ssid.c_str(), _password.c_str());
|
while (--tries && WiFi.status() != WL_CONNECTED) {
|
||||||
Serial.print("ssid: ");
|
if (WiFi.status() == WL_CONNECT_FAILED) {
|
||||||
Serial.println(_ssid);
|
Serial.println("[E] password is not correct");
|
||||||
}
|
tries = 1;
|
||||||
// Делаем проверку подключения до тех пор пока счетчик tries
|
jsonWriteInt(configOptionJson, "pass_status", 1);
|
||||||
// не станет равен нулю или не получим подключение
|
}
|
||||||
while (--tries && WiFi.status() != WL_CONNECTED) {
|
Serial.print(".");
|
||||||
if (WiFi.status() == WL_CONNECT_FAILED) {
|
delay(1000);
|
||||||
Serial.println("[E] password is not correct");
|
|
||||||
tries = 1;
|
|
||||||
jsonWriteInt(configOptionJson, "pass_status", 1);
|
|
||||||
}
|
}
|
||||||
Serial.print(".");
|
|
||||||
delay(1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (WiFi.status() != WL_CONNECTED)
|
if (WiFi.status() != WL_CONNECTED) {
|
||||||
{
|
// Если не удалось подключиться запускаем в режиме AP
|
||||||
// Если не удалось подключиться запускаем в режиме AP
|
Serial.println("");
|
||||||
Serial.println("");
|
// WiFi.disconnect(true);
|
||||||
// WiFi.disconnect(true);
|
StartAPMode();
|
||||||
StartAPMode();
|
|
||||||
|
|
||||||
}
|
} else {
|
||||||
else {
|
// Иначе удалось подключиться отправляем сообщение
|
||||||
// Иначе удалось подключиться отправляем сообщение
|
// о подключении и выводим адрес IP
|
||||||
// о подключении и выводим адрес IP
|
Serial.println("");
|
||||||
Serial.println("");
|
Serial.println("[V] WiFi connected");
|
||||||
Serial.println("[V] WiFi connected");
|
Serial.print("[V] IP address: http://");
|
||||||
Serial.print("[V] IP address: http://");
|
Serial.print(WiFi.localIP());
|
||||||
Serial.print(WiFi.localIP());
|
Serial.println("");
|
||||||
Serial.println("");
|
jsonWriteStr(configSetupJson, "ip", WiFi.localIP().toString());
|
||||||
jsonWriteStr(configSetupJson, "ip", WiFi.localIP().toString());
|
led_blink("off");
|
||||||
led_blink("off");
|
//add_dev_in_list("dev.txt", chipID, WiFi.localIP().toString());
|
||||||
//add_dev_in_list("dev.txt", chipID, WiFi.localIP().toString());
|
MQTT_init();
|
||||||
MQTT_init();
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StartAPMode() {
|
bool StartAPMode() {
|
||||||
Serial.println("WiFi up AP");
|
Serial.println("[I] WiFi AP");
|
||||||
WiFi.disconnect();
|
WiFi.disconnect();
|
||||||
|
|
||||||
WiFi.mode(WIFI_AP);
|
WiFi.mode(WIFI_AP);
|
||||||
|
|
||||||
String _ssidAP = jsonReadStr(configSetupJson, "apssid");
|
String _ssidAP = jsonReadStr(configSetupJson, "apssid");
|
||||||
String _passwordAP = jsonReadStr(configSetupJson, "appass");
|
String _passwordAP = jsonReadStr(configSetupJson, "appass");
|
||||||
WiFi.softAP(_ssidAP.c_str(), _passwordAP.c_str());
|
WiFi.softAP(_ssidAP.c_str(), _passwordAP.c_str());
|
||||||
IPAddress myIP = WiFi.softAPIP();
|
IPAddress myIP = WiFi.softAPIP();
|
||||||
led_blink("on");
|
led_blink("on");
|
||||||
Serial.print("AP IP address: ");
|
Serial.print("[I] AP IP: ");
|
||||||
Serial.println(myIP);
|
Serial.println(myIP);
|
||||||
jsonWriteStr(configSetupJson, "ip", myIP.toString());
|
jsonWriteStr(configSetupJson, "ip", myIP.toString());
|
||||||
|
|
||||||
//if (jsonReadInt(configOptionJson, "pass_status") != 1) {
|
//if (jsonReadInt(configOptionJson, "pass_status") != 1) {
|
||||||
ts.add(ROUTER_SEARCHING, 10 * 1000, [&](void*) {
|
ts.add(
|
||||||
Serial.println("->try find router");
|
ROUTER_SEARCHING, 10 * 1000, [&](void*) {
|
||||||
if (RouterFind(jsonReadStr(configSetupJson, "routerssid"))) {
|
Serial.println("[I] searching ssid");
|
||||||
ts.remove(ROUTER_SEARCHING);
|
if (RouterFind(jsonReadStr(configSetupJson, "routerssid"))) {
|
||||||
WiFi.scanDelete();
|
ts.remove(ROUTER_SEARCHING);
|
||||||
ROUTER_Connecting();
|
WiFi.scanDelete();
|
||||||
}
|
ROUTER_Connecting();
|
||||||
}, nullptr, true);
|
}
|
||||||
//}
|
},
|
||||||
return true;
|
nullptr, true);
|
||||||
|
//}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean RouterFind(String ssid) {
|
||||||
boolean RouterFind(String ssid)
|
|
||||||
{
|
|
||||||
bool res = false;
|
bool res = false;
|
||||||
|
|
||||||
int n = WiFi.scanComplete();
|
int8_t n = WiFi.scanComplete();
|
||||||
Serial.println("n = " + String(n));
|
Serial.printf("[I][WIFI] scan result = %d\n", n);
|
||||||
if (n == -2)
|
if (n == -2) {
|
||||||
{ //Сканирование не было запущено, запускаем
|
// не было запущено, запускаем
|
||||||
Serial.println("[WIFI][i] scanning has not been triggered, starting scanning");
|
Serial.println("[I][WIFI] scanning has not been triggered, start scanning");
|
||||||
WiFi.scanNetworks(true, false); //async, show_hidde
|
// async, show_hidden
|
||||||
}
|
|
||||||
else if (n == -1)
|
|
||||||
{ //Сканирование все еще выполняется
|
|
||||||
Serial.println("[WIFI][i] scanning still in progress");
|
|
||||||
}
|
|
||||||
else if (n == 0)
|
|
||||||
{ //ни одна сеть не найдена
|
|
||||||
Serial.println("[WIFI][i] no any wifi sations, starting scanning");
|
|
||||||
WiFi.scanNetworks(true, false);
|
WiFi.scanNetworks(true, false);
|
||||||
}
|
} else if (n == -1) {
|
||||||
else if (n > 0)
|
// все еще выполняется
|
||||||
{
|
Serial.println("[I][WIFI] scanning in progress");
|
||||||
for (int i = 0; i <= n; i++)
|
} else if (n == 0) {
|
||||||
{
|
// не найдена ни одна сеть
|
||||||
if (WiFi.SSID(i) == ssid)
|
Serial.println("[I][WIFI] no wifi stations, start scanning");
|
||||||
{
|
WiFi.scanNetworks(true, false);
|
||||||
|
} else if (n > 0) {
|
||||||
|
for (int8_t i = 0; i < n; i++) {
|
||||||
|
if (WiFi.SSID(i) == ssid) {
|
||||||
WiFi.scanDelete();
|
WiFi.scanDelete();
|
||||||
res = true;
|
res = true;
|
||||||
}
|
} else {
|
||||||
else
|
Serial.printf("%d) %s;\n", i, WiFi.SSID(i).c_str());
|
||||||
{
|
|
||||||
Serial.print(i);
|
|
||||||
Serial.print(")");
|
|
||||||
if (i == n)
|
|
||||||
{
|
|
||||||
Serial.print(WiFi.SSID(i));
|
|
||||||
Serial.println("; ");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Serial.print(WiFi.SSID(i));
|
|
||||||
Serial.println("; ");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
WiFi.scanDelete();
|
WiFi.scanDelete();
|
||||||
|
|||||||
@@ -3,47 +3,51 @@
|
|||||||
void not_async_actions();
|
void not_async_actions();
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
//--------------------------------------------------------------
|
Serial.begin(115200);
|
||||||
|
Serial.println();
|
||||||
|
Serial.println("--------------started----------------");
|
||||||
|
//Serial.setDebugOutput(true);
|
||||||
|
|
||||||
|
setChipId();
|
||||||
|
|
||||||
File_system_init();
|
File_system_init();
|
||||||
Serial.println("SPIFFS_init");
|
Serial.println("[V] LittleFS");
|
||||||
//--------------------------------------------------------------
|
|
||||||
CMD_init();
|
CMD_init();
|
||||||
Serial.println("[V] CMD_init");
|
Serial.println("[V] Commands");
|
||||||
//--------------------------------------------------------------
|
|
||||||
sensors_init();
|
sensors_init();
|
||||||
Serial.println("[V] sensors_init");
|
Serial.println("[V] Sensors");
|
||||||
//--------------------------------------------------------------
|
|
||||||
All_init();
|
All_init();
|
||||||
Serial.println("[V] All_init");
|
Serial.println("[V] All");
|
||||||
//--------------------------------------------------------------
|
|
||||||
ROUTER_Connecting();
|
ROUTER_Connecting();
|
||||||
Serial.println("[V] ROUTER_Connecting");
|
Serial.println("[V] ROUTER_Connecting");
|
||||||
//--------------------------------------------------------------
|
|
||||||
uptime_init();
|
uptime_init();
|
||||||
Serial.println("[V] statistics_init");
|
Serial.println("[V] statistics_init");
|
||||||
//--------------------------------------------------------------
|
|
||||||
initUpgrade();
|
initUpgrade();
|
||||||
Serial.println("[V] initUpgrade");
|
Serial.println("[V] initUpgrade");
|
||||||
//--------------------------------------------------------------
|
|
||||||
Web_server_init();
|
Web_server_init();
|
||||||
Serial.println("[V] Web_server_init");
|
Serial.println("[V] Web_server_init");
|
||||||
//--------------------------------------------------------------
|
|
||||||
web_init();
|
web_init();
|
||||||
Serial.println("[V] web_init");
|
Serial.println("[V] web_init");
|
||||||
//--------------------------------------------------------------
|
|
||||||
Time_Init();
|
Time_Init();
|
||||||
Serial.println("[V] Time_Init");
|
Serial.println("[V] Time_Init");
|
||||||
//--------------------------------------------------------------
|
|
||||||
#ifdef UDP_enable
|
#ifdef UDP_enable
|
||||||
UDP_init();
|
UDP_init();
|
||||||
Serial.println("[V] UDP_init");
|
Serial.println("[V] UDP_init");
|
||||||
#endif
|
#endif
|
||||||
//--------------------------------------------------------------
|
|
||||||
|
|
||||||
ts.add(
|
ts.add(
|
||||||
TEST, 10000, [&](void*) {
|
TEST, 10000, [&](void*) {
|
||||||
getMemoryLoad("[i] periodic check of");
|
getMemoryLoad("[I] sysinfo ");
|
||||||
//ws.textAll(json);
|
|
||||||
},
|
},
|
||||||
nullptr, true);
|
nullptr, true);
|
||||||
|
|
||||||
|
|||||||
28
src/main.cpp
28
src/main.cpp
@@ -33,7 +33,7 @@ void safeDataToFile(String data, String Folder) {
|
|||||||
|
|
||||||
void sendCONFIG(String topik, String widgetConfig, String key, String date) {
|
void sendCONFIG(String topik, String widgetConfig, String key, String date) {
|
||||||
yield();
|
yield();
|
||||||
topik = jsonReadStr(configSetupJson, "mqttPrefix") + "/" + chipID + "/" + topik + "/status";
|
topik = jsonReadStr(configSetupJson, "mqttPrefix") + "/" + chipId + "/" + topik + "/status";
|
||||||
String outer = "{\"widgetConfig\":";
|
String outer = "{\"widgetConfig\":";
|
||||||
String inner = "{\"";
|
String inner = "{\"";
|
||||||
inner = inner + key;
|
inner = inner + key;
|
||||||
@@ -65,16 +65,32 @@ void led_blink(String satus) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const String getChipId() {
|
||||||
|
String res;
|
||||||
|
#ifdef ESP32
|
||||||
|
res = String(ESP.getEfuseMac());
|
||||||
|
#endif
|
||||||
|
#ifdef ESP8266
|
||||||
|
res = String(ESP.getChipId()) + "-" + String(ESP.getFlashChipId());
|
||||||
|
#endif
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setChipId() {
|
||||||
|
chipId = getChipId();
|
||||||
|
Serial.println(chipId);
|
||||||
|
}
|
||||||
|
|
||||||
void getMemoryLoad(String text) {
|
void getMemoryLoad(String text) {
|
||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
int all_memory = 52864;
|
uint32_t all_memory = 52864;
|
||||||
#endif
|
#endif
|
||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
int all_memory = 362868;
|
uint32_t all_memory = 362868;
|
||||||
#endif
|
#endif
|
||||||
int memory_remain = ESP.getFreeHeap();
|
uint32_t memory_remain = ESP.getFreeHeap();
|
||||||
int memory_used = all_memory - memory_remain;
|
uint32_t memory_used = all_memory - memory_remain;
|
||||||
int memory_load = (memory_used * 100) / all_memory;
|
uint32_t memory_load = (memory_used * 100) / all_memory;
|
||||||
if (memory_load > 65) {
|
if (memory_load > 65) {
|
||||||
Serial.println("Memory low!");
|
Serial.println("Memory low!");
|
||||||
}
|
}
|
||||||
|
|||||||
10
src/udp.cpp
10
src/udp.cpp
@@ -20,7 +20,7 @@ void add_dev_in_list(String fileName, String id, String dev_name, String ip);
|
|||||||
|
|
||||||
#ifdef UDP_enable
|
#ifdef UDP_enable
|
||||||
void UDP_init() {
|
void UDP_init() {
|
||||||
SPIFFS.remove("/dev.csv");
|
LittleFS.remove("/dev.csv");
|
||||||
addFile("dev.csv", "device id;device name;ip address");
|
addFile("dev.csv", "device id;device name;ip address");
|
||||||
|
|
||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
@@ -37,7 +37,7 @@ void UDP_init() {
|
|||||||
if (jsonReadStr(configSetupJson, "udponoff") == "1") {
|
if (jsonReadStr(configSetupJson, "udponoff") == "1") {
|
||||||
if (WiFi.status() == WL_CONNECTED) {
|
if (WiFi.status() == WL_CONNECTED) {
|
||||||
if (!udp_busy) {
|
if (!udp_busy) {
|
||||||
String line_to_send = "iotm;" + chipID + ";" + jsonReadStr(configSetupJson, "name");
|
String line_to_send = "iotm;" + chipId + ";" + jsonReadStr(configSetupJson, "name");
|
||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
Udp.beginPacketMulticast(udp_multicastIP, udp_port, WiFi.localIP());
|
Udp.beginPacketMulticast(udp_multicastIP, udp_port, WiFi.localIP());
|
||||||
Udp.write(line_to_send.c_str());
|
Udp.write(line_to_send.c_str());
|
||||||
@@ -122,10 +122,10 @@ void do_udp_data_parse() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void add_dev_in_list(String fileName, String id, String dev_name, String ip) {
|
void add_dev_in_list(String filename, String id, String dev_name, String ip) {
|
||||||
File configFile = SPIFFS.open("/" + fileName, "r");
|
File configFile = LittleFS.open("/" + filename, "r");
|
||||||
if (!configFile.find(id.c_str())) {
|
if (!configFile.find(id.c_str())) {
|
||||||
addFile(fileName, id + ";" + dev_name + "; <a href=\"http://" + ip + "\" target=\"_blank\"\">" + ip + "</a>");
|
addFile(filename, id + ";" + dev_name + "; <a href=\"http://" + ip + "\" target=\"_blank\"\">" + ip + "</a>");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user