mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 22:22:16 +03:00
fix many bugs
This commit is contained in:
40
SSDP.ino
Normal file
40
SSDP.ino
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
void SSDP_init() {
|
||||
|
||||
// --------------------Получаем ssdp со страницы
|
||||
server.on("/ssdp", HTTP_GET, [](AsyncWebServerRequest * request) {
|
||||
if (request->hasArg("ssdp")) {
|
||||
jsonWrite(configSetup, "SSDP", request->getParam("ssdp")->value());
|
||||
jsonWrite(configJson, "SSDP", request->getParam("ssdp")->value());
|
||||
SSDP.setName(jsonRead(configSetup, "SSDP"));
|
||||
}
|
||||
saveConfig();
|
||||
request->send(200, "text/text", "OK");
|
||||
});
|
||||
|
||||
// SSDP дескриптор
|
||||
server.on("/description.xml", [](AsyncWebServerRequest * request) {
|
||||
//SSDP.schema(http.client());
|
||||
request->send(200, "text/text", "OK");
|
||||
});
|
||||
|
||||
|
||||
if (WiFi.status() == WL_CONNECTED) {
|
||||
//Если версия 2.0.0 закаментируйте следующую строчку
|
||||
SSDP.setDeviceType("upnp:rootdevice");
|
||||
SSDP.setSchemaURL("description.xml");
|
||||
SSDP.setHTTPPort(80);
|
||||
SSDP.setName(jsonRead(configSetup, "SSDP"));
|
||||
SSDP.setSerialNumber(chipID);
|
||||
SSDP.setURL("/");
|
||||
SSDP.setModelName("tech");
|
||||
SSDP.setModelNumber(chipID + "/" + jsonRead(configSetup, "SSDP"));
|
||||
|
||||
|
||||
SSDP.setModelURL("https://github.com/DmitryBorisenko33/esp32-esp8266_iot-manager_modules_firmware");
|
||||
SSDP.setManufacturer("Borisenko Dmitry");
|
||||
SSDP.setManufacturerURL("https://www.instagram.com/rriissee3");
|
||||
SSDP.begin();
|
||||
}
|
||||
}
|
||||
*/
|
||||
47
Upgrade.ino
47
Upgrade.ino
@@ -1,36 +1,51 @@
|
||||
void initUpgrade() {
|
||||
server.on("/upgrade", HTTP_GET, [](AsyncWebServerRequest * request) {
|
||||
|
||||
#ifdef ESP32
|
||||
new_version = getURL("http://91.204.228.124:1100/update/esp32/version.txt");
|
||||
#endif
|
||||
#ifdef ESP8266
|
||||
//new_version = getURL("http://91.204.228.124:1100/update/esp8266/version.txt");
|
||||
#endif
|
||||
start_check_version = true;
|
||||
|
||||
Serial.print("[i] Last firmware version: ");
|
||||
Serial.println(new_version);
|
||||
Serial.println(last_version);
|
||||
|
||||
String tmp = "{}";
|
||||
|
||||
if (new_version != "error") {
|
||||
if (new_version == firmware_version) {
|
||||
jsonWrite(tmp, "title", "<button class=\"close\" onclick=\"toggle('my-block')\">×</button>Последняя версия прошивки уже установлена.");
|
||||
jsonWrite(tmp, "class", "pop-up");
|
||||
if (!flash_1mb) {
|
||||
if (last_version != "") {
|
||||
if (last_version != "error") {
|
||||
if (last_version == firmware_version) {
|
||||
jsonWrite(tmp, "title", "<button class=\"close\" onclick=\"toggle('my-block')\">×</button>Последняя версия прошивки уже установлена.");
|
||||
jsonWrite(tmp, "class", "pop-up");
|
||||
} else {
|
||||
upgrade_flag = true;
|
||||
jsonWrite(tmp, "title", "<button class=\"close\" onclick=\"toggle('my-block')\">×</button>Идет обновление прошивки... После завершения устройство перезагрузится. Подождите одну минуту!!!");
|
||||
jsonWrite(tmp, "class", "pop-up");
|
||||
}
|
||||
} else {
|
||||
jsonWrite(tmp, "title", "<button class=\"close\" onclick=\"toggle('my-block')\">×</button>Ошибка... Cервер не найден. Попробуйте позже...");
|
||||
jsonWrite(tmp, "class", "pop-up");
|
||||
}
|
||||
} else {
|
||||
upgrade_flag = true;
|
||||
jsonWrite(tmp, "title", "<button class=\"close\" onclick=\"toggle('my-block')\">×</button>Идет обновление прошивки... После завершения устройство перезагрузится. Подождите минуту...");
|
||||
jsonWrite(tmp, "title", "<button class=\"close\" onclick=\"toggle('my-block')\">×</button>Нажмите на кнопку \"обновить прошивку\" повторно...");
|
||||
jsonWrite(tmp, "class", "pop-up");
|
||||
}
|
||||
} else {
|
||||
jsonWrite(tmp, "title", "<button class=\"close\" onclick=\"toggle('my-block')\">×</button>Ошибка... Cервер не найден. Попробуйте позже...");
|
||||
jsonWrite(tmp, "title", "<button class=\"close\" onclick=\"toggle('my-block')\">×</button>Обновление по воздуху не поддерживается, модуль имеет меньше 4 мб памяти...");
|
||||
jsonWrite(tmp, "class", "pop-up");
|
||||
}
|
||||
|
||||
request->send(200, "text/text", tmp);
|
||||
});
|
||||
}
|
||||
|
||||
void handle_get_url() {
|
||||
if (start_check_version) {
|
||||
start_check_version = false;
|
||||
#ifdef ESP32
|
||||
last_version = getURL("http://91.204.228.124:1100/update/esp32/version.txt");
|
||||
#endif
|
||||
#ifdef ESP8266
|
||||
last_version = getURL("http://91.204.228.124:1100/update/esp8266/version.txt");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void upgrade_firmware() {
|
||||
|
||||
String scenario_for_update;
|
||||
|
||||
@@ -146,7 +146,7 @@ void Web_server_init() {
|
||||
});
|
||||
|
||||
// ------------------Выполнение команды из запроса
|
||||
server.on("/cmd", HTTP_GET, [](AsyncWebServerRequest * request) { //http://192.168.88.45/cmd?command=rel 1 1
|
||||
server.on("/cmd", HTTP_GET, [](AsyncWebServerRequest * request) { //http://192.168.88.45/cmd?command=rel%201%201
|
||||
String com = request->getParam("command")->value();
|
||||
Serial.println(com);
|
||||
order_loop += com + ",";
|
||||
|
||||
9
WiFi.ino
9
WiFi.ino
@@ -1,12 +1,5 @@
|
||||
void WIFI_init() {
|
||||
|
||||
// --------------------Получаем ssid password со страницы
|
||||
server.on("/wifi.scan.json", HTTP_GET, [](AsyncWebServerRequest * request) {
|
||||
String tmp;
|
||||
//tmp = scanWIFI();
|
||||
//Serial.println(tmp);
|
||||
request->send(200, "application/json", tmp); // отправляем ответ о выполнении
|
||||
});
|
||||
|
||||
// --------------------Получаем ssid password со страницы
|
||||
server.on("/ssid", HTTP_GET, [](AsyncWebServerRequest * request) {
|
||||
if (request->hasArg("ssid")) {
|
||||
|
||||
Binary file not shown.
@@ -1,92 +0,0 @@
|
||||
{
|
||||
"configs": [
|
||||
"/config.setup.json"
|
||||
],
|
||||
"class":"col-sm-offset-1 col-sm-10 col-md-offset-2 col-md-8 col-lg-offset-3 col-lg-6",
|
||||
"content": [
|
||||
{
|
||||
"type": "h5",
|
||||
"title": "{{SSDP}}",
|
||||
"class":"alert-warning"
|
||||
},
|
||||
{
|
||||
"type": "h4",
|
||||
"title": "Host name:"
|
||||
},
|
||||
{
|
||||
"type": "input",
|
||||
"title": "",
|
||||
"name":"1",
|
||||
"state": "{{pushHost}}"
|
||||
},
|
||||
{
|
||||
"type": "h4",
|
||||
"title": "Port:"
|
||||
},
|
||||
{
|
||||
"type": "input",
|
||||
"title": "",
|
||||
"name":"2",
|
||||
"state": "{{pushPort}}"
|
||||
},
|
||||
{
|
||||
"type": "h4",
|
||||
"title": "Fingerprint:"
|
||||
},
|
||||
{
|
||||
"type": "input",
|
||||
"title": "",
|
||||
"name":"3",
|
||||
"state": "{{pushFingerprint}}"
|
||||
},
|
||||
{
|
||||
"type": "h4",
|
||||
"title": "Access Token:"
|
||||
},
|
||||
{
|
||||
"type": "input",
|
||||
"title": "",
|
||||
"name":"4",
|
||||
"state": "{{pushAccessToken}}"
|
||||
},
|
||||
{
|
||||
"type":"h3",
|
||||
"name":"my-block",
|
||||
"style":"position:fixed;top:30%;left:50%;width:400px;margin-left:-200px;text-align:center;",
|
||||
"class":"hidden"
|
||||
},
|
||||
{
|
||||
"type": "button",
|
||||
"title":"Сохранить и проверить соединение",
|
||||
"action": "pushDate?pushHost=[[1]]&pushPort=[[2]]&pushFingerprint=[[3]]&pushAccessToken=[[4]]",
|
||||
"response":"[[my-block]]",
|
||||
"class": "btn btn-block btn-success",
|
||||
"style": "width:100%;display:inline"
|
||||
},
|
||||
{
|
||||
"type": "hr"
|
||||
},
|
||||
{
|
||||
"type": "checkbox",
|
||||
"name":"start-push",
|
||||
"title": "Отправлять push при включении устройства",
|
||||
"action": "startPush?status=[[start-push]]",
|
||||
"state": "{{startPush}}"
|
||||
},
|
||||
{
|
||||
"type": "hr"
|
||||
},
|
||||
{
|
||||
"type": "link",
|
||||
"title": "Перезагрузить устройство",
|
||||
"action": "javascript:if(confirm(renameBlock(jsonResponse,'Перезагрузить?'))){send_request(this,'/restart?device=ok');}",
|
||||
"class": "btn btn-block btn-warning"
|
||||
},
|
||||
{
|
||||
"type": "link",
|
||||
"title": "Главная",
|
||||
"action": "/page.htm?index",
|
||||
"class": "btn btn-block btn-danger btn-sm"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -8,6 +8,7 @@
|
||||
"timezone": 3,
|
||||
"mqttServer": "",
|
||||
"mqttPort": 0,
|
||||
"mqttPrefix": "/IoTmanager",
|
||||
"mqttUser": "",
|
||||
"mqttPass": "",
|
||||
"scenario": "1",
|
||||
@@ -59,20 +59,26 @@ void setup() {
|
||||
Push_init();
|
||||
Serial.println("[V] Push_init");
|
||||
//--------------------------------------------------------------
|
||||
//SSDP_init();
|
||||
//Serial.println("[V] SSDP_init");
|
||||
//--------------------------------------------------------------
|
||||
|
||||
Serial.print("[i] Date compiling: ");
|
||||
Serial.println(DATE_COMPILING);
|
||||
|
||||
getMemoryLoad("[i] After loading");
|
||||
|
||||
#ifdef ESP8266
|
||||
new_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
|
||||
#ifdef ESP32
|
||||
new_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
|
||||
|
||||
jsonWrite(configSetup, "last_version", last_version);
|
||||
|
||||
Serial.print("[i] Last firmware version: ");
|
||||
Serial.println(new_version);
|
||||
Serial.println(last_version);
|
||||
|
||||
just_load = false;
|
||||
}
|
||||
@@ -90,7 +96,9 @@ void loop() {
|
||||
#endif
|
||||
|
||||
handleMQTT();
|
||||
|
||||
handle_connection();
|
||||
handle_get_url();
|
||||
|
||||
handleCMD_loop();
|
||||
handleButton();
|
||||
|
||||
7
mqtt.ino
7
mqtt.ino
@@ -38,7 +38,8 @@ void MQTT_init() {
|
||||
jsonWrite(configSetup, "mqttPass", request->getParam("mqttPass")->value());
|
||||
}
|
||||
saveConfig();
|
||||
start_connection = true;
|
||||
start_connecting_to_mqtt = true;
|
||||
|
||||
request->send(200, "text/text", "ok");
|
||||
});
|
||||
|
||||
@@ -51,8 +52,8 @@ void MQTT_init() {
|
||||
}
|
||||
|
||||
void handle_connection() {
|
||||
if (start_connection) {
|
||||
start_connection = false;
|
||||
if (start_connecting_to_mqtt) {
|
||||
start_connecting_to_mqtt = false;
|
||||
client.disconnect();
|
||||
MQTT_Connecting();
|
||||
}
|
||||
|
||||
18
set.h
18
set.h
@@ -1,7 +1,7 @@
|
||||
String firmware_version = "2.3.1";
|
||||
String new_version;
|
||||
|
||||
//23560
|
||||
boolean flash_1mb = true;
|
||||
String last_version;
|
||||
boolean start_check_version = false;
|
||||
|
||||
//#define OTA_enable
|
||||
//#define MDNS_enable
|
||||
@@ -33,9 +33,11 @@ String new_version;
|
||||
#ifdef ESP8266
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <ESP8266HTTPClient.h>
|
||||
#include <ESPAsyncTCP.h>
|
||||
//#include <ESPAsyncTCP.h>
|
||||
#ifdef MDNS_enable
|
||||
#include <ESP8266mDNS.h>
|
||||
|
||||
#endif
|
||||
//#include <ESP8266SSDP.h>
|
||||
#include <ESP8266httpUpdate.h>
|
||||
#include <ESP8266HTTPUpdateServer.h>
|
||||
ESP8266HTTPUpdateServer httpUpdater;
|
||||
@@ -50,11 +52,11 @@ ESP8266HTTPUpdateServer httpUpdater;
|
||||
#endif
|
||||
#include <AsyncTCP.h>
|
||||
#include <analogWrite.h>
|
||||
|
||||
//#include <ESP32SSDP.h>
|
||||
#include <HTTPUpdate.h>
|
||||
#include <HTTPClient.h>
|
||||
//HTTPClient http;
|
||||
#include <rom/rtc.h>
|
||||
//#include <rom/rtc.h>
|
||||
#endif
|
||||
|
||||
//==общие библиотеки и объекты==//
|
||||
@@ -149,4 +151,4 @@ String var;
|
||||
boolean upgrade_flag = false;
|
||||
boolean get_url_flag = false;
|
||||
|
||||
boolean start_connection = false;
|
||||
boolean start_connecting_to_mqtt = false;
|
||||
|
||||
Reference in New Issue
Block a user