mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-29 07:32:18 +03:00
Merge branch 'beta' into beta
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include "BufferExecute.h"
|
||||
#include "Global.h"
|
||||
#include "SoftUART.h"
|
||||
//
|
||||
#include "items/vSensorDallas.h"
|
||||
#include "items/vSensorUltrasonic.h"
|
||||
@@ -11,9 +12,18 @@
|
||||
#include "items/vCountDown.h"
|
||||
|
||||
void loopCmdAdd(const String& cmdStr) {
|
||||
orderBuf += cmdStr;
|
||||
if (!cmdStr.endsWith(",")) {
|
||||
orderBuf += ",";
|
||||
if (cmdStr.endsWith(",")) {
|
||||
orderBuf += cmdStr;
|
||||
#ifdef uartEnable
|
||||
if (jsonReadBool(configSetupJson, "uart")) {
|
||||
if (jsonReadBool(configSetupJson, "uartEvents")) {
|
||||
if (myUART) {
|
||||
myUART->print(cmdStr);
|
||||
SerialPrint("I", "<=UART", cmdStr);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ WiFiClient espClient;
|
||||
PubSubClient mqtt(espClient);
|
||||
StringCommand sCmd;
|
||||
AsyncWebServer server(80);
|
||||
OneWire *oneWire;
|
||||
OneWire* oneWire;
|
||||
DallasTemperature sensors;
|
||||
|
||||
/*
|
||||
@@ -25,6 +25,7 @@ String configSetupJson = "{}";
|
||||
String configLiveJson = "{}";
|
||||
String configStoreJson = "{}";
|
||||
String configOptionJson = "{}";
|
||||
String telegramMsgJson = "{}";
|
||||
|
||||
// Mqtt
|
||||
String chipId = "";
|
||||
@@ -70,7 +71,7 @@ String presetName;
|
||||
String serverIP;
|
||||
|
||||
// Scenario
|
||||
int scenario_line_status[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
|
||||
int scenario_line_status[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
|
||||
int lastVersion;
|
||||
|
||||
boolean busScanFlag = false;
|
||||
|
||||
@@ -18,63 +18,96 @@ void itemsListInit() {
|
||||
delChoosingItems();
|
||||
},
|
||||
nullptr);
|
||||
|
||||
|
||||
|
||||
SerialPrint("I", F("Items"), F("Items Init"));
|
||||
}
|
||||
|
||||
void addItem(String name) {
|
||||
void addItem2(String param) {
|
||||
int num = selectToMarker(param, "-").toInt();
|
||||
File configFile = LittleFS.open("/items/items.txt", "r");
|
||||
if (!configFile) {
|
||||
return;
|
||||
}
|
||||
configFile.seek(0, SeekSet);
|
||||
String seachingLine;
|
||||
|
||||
String item = readFile("items/" + name + ".txt", 1024);
|
||||
|
||||
name = selectToMarker(name, "-");
|
||||
while (configFile.position() != configFile.size()) {
|
||||
String item = configFile.readStringUntil('\n');
|
||||
int tmpNum = selectToMarker(item, ";").toInt();
|
||||
if (tmpNum == num) {
|
||||
seachingLine = item;
|
||||
break;
|
||||
}
|
||||
}
|
||||
configFile.close();
|
||||
|
||||
String name = deleteBeforeDelimiter(param, "-");
|
||||
randomSeed(micros());
|
||||
unsigned int num = random(0, 1000);
|
||||
unsigned int rnd = random(0, 1000);
|
||||
seachingLine.replace("id", name + String(rnd));
|
||||
seachingLine.replace("order", String(getNewElementNumber("order.txt")));
|
||||
|
||||
item.replace("id", name + String(num));
|
||||
item.replace("order", String(getNewElementNumber("order.txt")));
|
||||
|
||||
if (item.indexOf("pin") != -1) { //all cases (random pins from available)
|
||||
item.replace("pin", "pin[" + String(getFreePinAll()) + "]");
|
||||
}
|
||||
else if (item.indexOf("gol") != -1) { //analog
|
||||
item.replace("gol", "pin[" + String(getFreePinAnalog()) + "]");
|
||||
}
|
||||
else if (item.indexOf("cin") != -1) { //ultrasonic
|
||||
item.replace("cin", "pin[" + String(getFreePinAll()) + "," + String(getFreePinAll()) + "]");
|
||||
}
|
||||
else if (item.indexOf("sal") != -1) { //dallas
|
||||
item.replace("sal", "pin[2]");
|
||||
}
|
||||
else if (item.indexOf("thd") != -1) { //dht11/22
|
||||
item.replace("thd", "pin[2]");
|
||||
if (seachingLine.indexOf("pin") != -1) {
|
||||
seachingLine.replace("pin", "pin[" + String(getFreePinAll()) + "]");
|
||||
}
|
||||
|
||||
item.replace("\r\n", "");
|
||||
item.replace("\r", "");
|
||||
item.replace("\n", "");
|
||||
|
||||
addFile(DEVICE_CONFIG_FILE, "\n" + item);
|
||||
Serial.println(item);
|
||||
seachingLine = deleteBeforeDelimiter(seachingLine, ";");
|
||||
seachingLine.replace("\r\n", "");
|
||||
seachingLine.replace("\r", "");
|
||||
seachingLine.replace("\n", "");
|
||||
addFile(DEVICE_CONFIG_FILE, "\n" + seachingLine);
|
||||
Serial.println(seachingLine);
|
||||
}
|
||||
|
||||
void addPreset(String name) {
|
||||
String preset = readFile("presets/" + name + ".txt", 4048);
|
||||
addFile(DEVICE_CONFIG_FILE, "\n" + preset);
|
||||
Serial.println(preset);
|
||||
|
||||
name.replace(".c", ".s");
|
||||
void addPreset2(int num) {
|
||||
File configFile = LittleFS.open("/presets/presets.c.txt", "r");
|
||||
if (!configFile) {
|
||||
return;
|
||||
}
|
||||
configFile.seek(0, SeekSet);
|
||||
String config;
|
||||
int i1 = 0;
|
||||
while (configFile.position() != configFile.size()) {
|
||||
i1++;
|
||||
String item = configFile.readStringUntil('*');
|
||||
if (i1 == num) {
|
||||
if (i1 == 1) {
|
||||
config = "\n" + item;
|
||||
}
|
||||
else {
|
||||
config = item;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
configFile.close();
|
||||
addFile(DEVICE_CONFIG_FILE, config);
|
||||
|
||||
String scenario = readFile("presets/" + name + ".txt", 4048);
|
||||
|
||||
removeFile(DEVICE_SCENARIO_FILE);
|
||||
|
||||
addFile(DEVICE_SCENARIO_FILE, scenario);
|
||||
loadScenario();
|
||||
Serial.println(scenario);
|
||||
File scenFile = LittleFS.open("/presets/presets.s.txt", "r");
|
||||
if (!scenFile) {
|
||||
return;
|
||||
}
|
||||
scenFile.seek(0, SeekSet);
|
||||
String scen;
|
||||
int i2 = 0;
|
||||
while (scenFile.position() != scenFile.size()) {
|
||||
i2++;
|
||||
String item = scenFile.readStringUntil('*');
|
||||
if (i2 == num) {
|
||||
scen = item;
|
||||
break;
|
||||
}
|
||||
}
|
||||
scenFile.close();
|
||||
if (readFile(String(DEVICE_SCENARIO_FILE), 2048) == "//") {
|
||||
removeFile(DEVICE_SCENARIO_FILE);
|
||||
}
|
||||
addFile(DEVICE_SCENARIO_FILE, scen);
|
||||
}
|
||||
|
||||
|
||||
void delAllItems() {
|
||||
removeFile(DEVICE_CONFIG_FILE);
|
||||
addFile(DEVICE_CONFIG_FILE, String(firstLine));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "MqttClient.h"
|
||||
|
||||
#include "BufferExecute.h"
|
||||
#include <LittleFS.h>
|
||||
#include "items/vLogging.h"
|
||||
#include "Class/NotAsync.h"
|
||||
@@ -169,10 +169,13 @@ void mqttCallback(char* topic, uint8_t* payload, size_t length) {
|
||||
|
||||
String key = selectFromMarkerToMarker(topicStr, "/", 3);
|
||||
|
||||
orderBuf += key;
|
||||
orderBuf += " ";
|
||||
orderBuf += payloadStr;
|
||||
orderBuf += ",";
|
||||
String order;
|
||||
order += key;
|
||||
order += " ";
|
||||
order += payloadStr;
|
||||
order += ",";
|
||||
|
||||
loopCmdAdd(order);
|
||||
|
||||
SerialPrint("I", "=>MQTT", "Msg from iotmanager app: " + key + " " + payloadStr);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#ifdef uartEnable
|
||||
#include "SoftUART.h"
|
||||
#include "Global.h"
|
||||
#include "BufferExecute.h"
|
||||
|
||||
#ifdef ESP8266
|
||||
SoftwareSerial* myUART = nullptr;
|
||||
@@ -10,7 +11,7 @@ HardwareSerial* myUART = nullptr;
|
||||
#endif
|
||||
|
||||
void uartInit() {
|
||||
if (!jsonReadBool(configSetupJson, "uartEnable")) {
|
||||
if (!jsonReadBool(configSetupJson, "uart")) {
|
||||
return;
|
||||
}
|
||||
if (!myUART) {
|
||||
@@ -27,7 +28,7 @@ void uartInit() {
|
||||
|
||||
void uartHandle() {
|
||||
if (myUART) {
|
||||
if (!jsonReadBool(configSetupJson, "uartEnable")) {
|
||||
if (!jsonReadBool(configSetupJson, "uart")) {
|
||||
return;
|
||||
}
|
||||
static String incStr;
|
||||
@@ -49,7 +50,7 @@ void parse(String& incStr) {
|
||||
incStr.replace("\n", "");
|
||||
if (incStr.indexOf("set") != -1) {
|
||||
incStr = deleteBeforeDelimiter(incStr, " ");
|
||||
orderBuf += incStr;
|
||||
loopCmdAdd(incStr);
|
||||
SerialPrint("I", "=>UART", incStr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "Consts.h"
|
||||
#ifdef telegramEnable
|
||||
#include "Telegram.h"
|
||||
#include "BufferExecute.h"
|
||||
CTBot* myBot{ nullptr };
|
||||
|
||||
void telegramInit() {
|
||||
@@ -49,7 +50,7 @@ void telegramMsgParse(String msg) {
|
||||
if (msg.indexOf("set") != -1) {
|
||||
msg = deleteBeforeDelimiter(msg, "_");
|
||||
msg.replace("_", " ");
|
||||
orderBuf += String(msg) + ",";
|
||||
loopCmdAdd(String(msg) + ",");
|
||||
myBot->sendMessage(jsonReadInt(configSetupJson, "chatId"), "order done");
|
||||
SerialPrint("<-", "Telegram", "chat ID: " + String(jsonReadInt(configSetupJson, "chatId")) + ", msg: " + String(msg));
|
||||
}
|
||||
@@ -69,23 +70,21 @@ void telegramMsgParse(String msg) {
|
||||
}
|
||||
|
||||
void sendTelegramMsg() {
|
||||
String id = sCmd.next();
|
||||
String msg = sCmd.next();
|
||||
String type = sCmd.next();
|
||||
msg.replace("#", " ");
|
||||
if (type == "1") {
|
||||
static String prevMsg;
|
||||
if (prevMsg != msg) {
|
||||
prevMsg = msg;
|
||||
if (msg != "na") {
|
||||
myBot->sendMessage(jsonReadInt(configSetupJson, "chatId"), msg);
|
||||
}
|
||||
SerialPrint("<-", "Telegram", "chat ID: " + String(jsonReadInt(configSetupJson, "chatId")) + ", msg: " + msg);
|
||||
}
|
||||
}
|
||||
else if (type == "2") {
|
||||
if (id == "often") {
|
||||
myBot->sendMessage(jsonReadInt(configSetupJson, "chatId"), msg);
|
||||
SerialPrint("<-", "Telegram", "chat ID: " + String(jsonReadInt(configSetupJson, "chatId")) + ", msg: " + msg);
|
||||
}
|
||||
else {
|
||||
String prevMsg = jsonReadStr(telegramMsgJson, id);
|
||||
if (prevMsg != msg) {
|
||||
jsonWriteStr(telegramMsgJson, id, msg);
|
||||
myBot->sendMessage(jsonReadInt(configSetupJson, "chatId"), msg);
|
||||
SerialPrint("<-", "Telegram", "chat ID: " + String(jsonReadInt(configSetupJson, "chatId")) + ", msg: " + msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool isTelegramEnabled() {
|
||||
|
||||
152
src/Web.cpp
152
src/Web.cpp
@@ -19,65 +19,54 @@ bool parseRequestForPreset(AsyncWebServerRequest* request, uint8_t& preset) {
|
||||
void web_init() {
|
||||
server.on("/set", HTTP_GET, [](AsyncWebServerRequest* request) {
|
||||
//==============================set.device.json====================================================================================================
|
||||
if (request->hasArg("addItem")) {
|
||||
addItem(request->getParam("addItem")->value());
|
||||
if (request->hasArg(F("addItem"))) {
|
||||
addItem2(request->getParam("addItem")->value());
|
||||
request->redirect("/?set.device");
|
||||
}
|
||||
|
||||
if (request->hasArg("addPreset")) {
|
||||
addPreset(request->getParam("addPreset")->value());
|
||||
jsonWriteStr(configSetupJson, "warning1", F("<div style='margin-top:10px;margin-bottom:10px;'><font color='black'><p style='border: 1px solid #DCDCDC; border-radius: 3px; background-color: #ffc7c7; padding: 10px;'>Требуется перезагрузка</p></font></div>"));
|
||||
request->redirect("/?set.device");
|
||||
if (request->hasArg(F("addPreset"))) {
|
||||
addPreset2(request->getParam(F("addPreset"))->value().toInt());
|
||||
#ifdef FLASH_SIZE_1MB
|
||||
jsonWriteStr(configSetupJson, F("warning1"), F("<div style='margin-top:10px;margin-bottom:10px;'><font color='black'><p style='border: 1px solid #DCDCDC; border-radius: 3px; background-color: #ffc7c7; padding: 10px;'>Присеты не доступны, модуль на 1mb</p></font></div>"));
|
||||
#else
|
||||
jsonWriteStr(configSetupJson, F("warning1"), F("<div style='margin-top:10px;margin-bottom:10px;'><font color='black'><p style='border: 1px solid #DCDCDC; border-radius: 3px; background-color: #ffc7c7; padding: 10px;'>Требуется перезагрузка</p></font></div>"));
|
||||
#endif
|
||||
request->redirect(F("/?set.device"));
|
||||
}
|
||||
|
||||
if (request->hasArg("delChoosingItems")) {
|
||||
jsonWriteStr(configSetupJson, "warning1", F("<div style='margin-top:10px;margin-bottom:10px;'><font color='black'><p style='border: 1px solid #DCDCDC; border-radius: 3px; background-color: #ffc7c7; padding: 10px;'>Требуется перезагрузка</p></font></div>"));
|
||||
if (request->hasArg(F("delChoosingItems"))) {
|
||||
jsonWriteStr(configSetupJson, F("warning1"), F("<div style='margin-top:10px;margin-bottom:10px;'><font color='black'><p style='border: 1px solid #DCDCDC; border-radius: 3px; background-color: #ffc7c7; padding: 10px;'>Требуется перезагрузка</p></font></div>"));
|
||||
myNotAsyncActions->make(do_delChoosingItems);
|
||||
request->send(200);
|
||||
}
|
||||
|
||||
if (request->hasArg("delAllItems")) {
|
||||
if (request->hasArg(F("delAllItems"))) {
|
||||
delAllItems();
|
||||
cleanLogAndData();
|
||||
jsonWriteStr(configSetupJson, "warning1", F("<div style='margin-top:10px;margin-bottom:10px;'><font color='black'><p style='border: 1px solid #DCDCDC; border-radius: 3px; background-color: #ffc7c7; padding: 10px;'>Требуется перезагрузка</p></font></div>"));
|
||||
request->redirect("/?set.device");
|
||||
jsonWriteStr(configSetupJson, F("warning1"), F("<div style='margin-top:10px;margin-bottom:10px;'><font color='black'><p style='border: 1px solid #DCDCDC; border-radius: 3px; background-color: #ffc7c7; padding: 10px;'>Требуется перезагрузка</p></font></div>"));
|
||||
request->redirect(F("/?set.device"));
|
||||
}
|
||||
|
||||
if (request->hasArg("saveItems")) {
|
||||
if (request->hasArg(F("saveItems"))) {
|
||||
myNotAsyncActions->make(do_deviceInit);
|
||||
request->send(200);
|
||||
}
|
||||
|
||||
if (request->hasArg("scen")) {
|
||||
bool value = request->getParam("scen")->value().toInt();
|
||||
jsonWriteBool(configSetupJson, "scen", value);
|
||||
if (request->hasArg(F("scen"))) {
|
||||
bool value = request->getParam(F("scen"))->value().toInt();
|
||||
jsonWriteBool(configSetupJson, F("scen"), value);
|
||||
saveConfig();
|
||||
loadScenario();
|
||||
request->send(200);
|
||||
}
|
||||
|
||||
if (request->hasArg("sceninit")) {
|
||||
if (request->hasArg(F("sceninit"))) {
|
||||
loadScenario();
|
||||
request->send(200);
|
||||
}
|
||||
|
||||
//if (request->hasArg("snaUdp")) {
|
||||
// bool value = request->getParam("snaUdp")->value().toInt();
|
||||
// jsonWriteBool(configSetupJson, "snaUdp", value);
|
||||
// saveConfig();
|
||||
// #ifdef UDP_ENABLED
|
||||
// asyncUdpInit();
|
||||
// #endif
|
||||
// request->send(200);
|
||||
//}
|
||||
|
||||
//if (request->hasArg("scenUdp")) {
|
||||
// myNotAsyncActions->make(do_sendScenUDP);
|
||||
// request->send(200);
|
||||
//}
|
||||
|
||||
if (request->hasArg("MqttIn")) {
|
||||
bool value = request->getParam("MqttIn")->value().toInt();
|
||||
if (request->hasArg(F("MqttIn"))) {
|
||||
bool value = request->getParam(F("MqttIn"))->value().toInt();
|
||||
jsonWriteBool(configSetupJson, "MqttIn", value);
|
||||
saveConfig();
|
||||
mqtt.subscribe((mqttPrefix + "/+/+/event").c_str());
|
||||
@@ -85,111 +74,103 @@ void web_init() {
|
||||
request->send(200);
|
||||
}
|
||||
|
||||
if (request->hasArg("MqttOut")) {
|
||||
bool value = request->getParam("MqttOut")->value().toInt();
|
||||
jsonWriteBool(configSetupJson, "MqttOut", value);
|
||||
if (request->hasArg(F("MqttOut"))) {
|
||||
bool value = request->getParam(F("MqttOut"))->value().toInt();
|
||||
jsonWriteBool(configSetupJson, F("MqttOut"), value);
|
||||
saveConfig();
|
||||
request->send(200);
|
||||
}
|
||||
|
||||
if (request->hasArg("scenMqtt")) {
|
||||
if (request->hasArg(F("scenMqtt"))) {
|
||||
myNotAsyncActions->make(do_sendScenMQTT);
|
||||
request->send(200);
|
||||
}
|
||||
|
||||
|
||||
if (request->hasArg("cleanlog")) {
|
||||
if (request->hasArg(F("cleanlog"))) {
|
||||
cleanLogAndData();
|
||||
request->send(200);
|
||||
}
|
||||
|
||||
//==============================wifi settings=============================================
|
||||
if (request->hasArg("devname")) {
|
||||
jsonWriteStr(configSetupJson, "name", request->getParam("devname")->value());
|
||||
if (request->hasArg(F("devname"))) {
|
||||
jsonWriteStr(configSetupJson, F("name"), request->getParam(F("devname"))->value());
|
||||
saveConfig();
|
||||
request->send(200);
|
||||
}
|
||||
|
||||
if (request->hasArg("routerssid")) {
|
||||
jsonWriteStr(configSetupJson, "routerssid", request->getParam("routerssid")->value());
|
||||
if (request->hasArg(F("routerssid"))) {
|
||||
jsonWriteStr(configSetupJson, F("routerssid"), request->getParam(F("routerssid"))->value());
|
||||
saveConfig();
|
||||
request->send(200);
|
||||
}
|
||||
|
||||
if (request->hasArg("routerpass")) {
|
||||
jsonWriteStr(configSetupJson, "routerpass", request->getParam("routerpass")->value());
|
||||
if (request->hasArg(F("routerpass"))) {
|
||||
jsonWriteStr(configSetupJson, F("routerpass"), request->getParam(F("routerpass"))->value());
|
||||
saveConfig();
|
||||
request->send(200);
|
||||
}
|
||||
|
||||
if (request->hasArg("apssid")) {
|
||||
jsonWriteStr(configSetupJson, "apssid", request->getParam("apssid")->value());
|
||||
if (request->hasArg(F("apssid"))) {
|
||||
jsonWriteStr(configSetupJson, F("apssid"), request->getParam(F("apssid"))->value());
|
||||
saveConfig();
|
||||
request->send(200, "text/text", "OK");
|
||||
}
|
||||
|
||||
if (request->hasArg("appass")) {
|
||||
jsonWriteStr(configSetupJson, "appass", request->getParam("appass")->value());
|
||||
if (request->hasArg(F("appass"))) {
|
||||
jsonWriteStr(configSetupJson, F("appass"), request->getParam(F("appass"))->value());
|
||||
saveConfig();
|
||||
request->send(200);
|
||||
}
|
||||
|
||||
if (request->hasArg("weblogin")) {
|
||||
jsonWriteStr(configSetupJson, "weblogin", request->getParam("weblogin")->value());
|
||||
if (request->hasArg(F("weblogin"))) {
|
||||
jsonWriteStr(configSetupJson, F("weblogin"), request->getParam(F("weblogin"))->value());
|
||||
saveConfig();
|
||||
request->send(200);
|
||||
}
|
||||
|
||||
if (request->hasArg("webpass")) {
|
||||
jsonWriteStr(configSetupJson, "webpass", request->getParam("webpass")->value());
|
||||
if (request->hasArg(F("webpass"))) {
|
||||
jsonWriteStr(configSetupJson, F("webpass"), request->getParam(F("webpass"))->value());
|
||||
saveConfig();
|
||||
request->send(200);
|
||||
}
|
||||
|
||||
if (request->hasArg("timezone")) {
|
||||
String timezoneStr = request->getParam("timezone")->value();
|
||||
jsonWriteStr(configSetupJson, "timezone", timezoneStr);
|
||||
if (request->hasArg(F("timezone"))) {
|
||||
String timezoneStr = request->getParam(F("timezone"))->value();
|
||||
jsonWriteStr(configSetupJson, F("timezone"), timezoneStr);
|
||||
saveConfig();
|
||||
timeNow->setTimezone(timezoneStr.toInt());
|
||||
request->send(200);
|
||||
}
|
||||
|
||||
if (request->hasArg("ntp")) {
|
||||
String ntpStr = request->getParam("ntp")->value();
|
||||
jsonWriteStr(configSetupJson, "ntp", ntpStr);
|
||||
if (request->hasArg(F("ntp"))) {
|
||||
String ntpStr = request->getParam(F("ntp"))->value();
|
||||
jsonWriteStr(configSetupJson, F("ntp"), ntpStr);
|
||||
saveConfig();
|
||||
timeNow->setNtpPool(ntpStr);
|
||||
request->send(200);
|
||||
}
|
||||
|
||||
if (request->hasArg("blink")) {
|
||||
bool value = request->getParam("blink")->value().toInt();
|
||||
jsonWriteBool(configSetupJson, "blink", value);
|
||||
if (request->hasArg(F("blink"))) {
|
||||
bool value = request->getParam(F("blink"))->value().toInt();
|
||||
jsonWriteBool(configSetupJson, F("blink"), value);
|
||||
saveConfig();
|
||||
request->send(200);
|
||||
}
|
||||
|
||||
if (request->hasArg("reqReset")) {
|
||||
if (request->hasArg(F("reqReset"))) {
|
||||
String tmp = "{}";
|
||||
jsonWriteStr(tmp, "title", F("<button class=\"close\" onclick=\"toggle('reset-block')\">×</button>Вы действительно хотите перезагрузить устройство?<a href=\"#\" class=\"btn btn-block btn-danger\" onclick=\"send_request(this, '/set?reset');setTimeout(function(){ location.href='/?set.device'; }, 15000);html('reset-block','<span class=loader></span>Идет перезагрузка устройства')\">Перезагрузить</a>"));
|
||||
jsonWriteStr(tmp, "class", "pop-up");
|
||||
request->send(200, "text/html", tmp);
|
||||
}
|
||||
|
||||
if (request->hasArg("reset")) {
|
||||
if (request->hasArg(F("reset"))) {
|
||||
ESP.restart();
|
||||
request->send(200);
|
||||
}
|
||||
|
||||
if (request->hasArg("test")) {
|
||||
if (request->getParam("test")->value() == "ok") {
|
||||
Serial.println("test pass");
|
||||
}
|
||||
request->send(200);
|
||||
}
|
||||
|
||||
//==============================mqtt settings=============================================
|
||||
|
||||
if (request->hasArg("mqttServer")) {
|
||||
jsonWriteStr(configSetupJson, "mqttServer", request->getParam("mqttServer")->value());
|
||||
saveConfig();
|
||||
@@ -237,7 +218,7 @@ void web_init() {
|
||||
request->send(200, "text/html", payload);
|
||||
}
|
||||
|
||||
//==============================push settings=============================================
|
||||
//==============================telegram settings=============================================
|
||||
if (request->hasArg("telegramApi")) {
|
||||
jsonWriteStr(configSetupJson, "telegramApi", request->getParam("telegramApi")->value());
|
||||
saveConfig();
|
||||
@@ -266,15 +247,21 @@ void web_init() {
|
||||
myNotAsyncActions->make(do_BUSSCAN);
|
||||
request->redirect("/?set.utilities");
|
||||
}
|
||||
if (request->hasArg("uartEnable")) {
|
||||
bool value = request->getParam("uartEnable")->value().toInt();
|
||||
jsonWriteBool(configSetupJson, "uartEnable", value);
|
||||
if (request->hasArg("uart")) {
|
||||
bool value = request->getParam("uart")->value().toInt();
|
||||
jsonWriteBool(configSetupJson, "uart", value);
|
||||
saveConfig();
|
||||
#ifdef uartEnable
|
||||
uartInit();
|
||||
#endif
|
||||
request->send(200);
|
||||
}
|
||||
if (request->hasArg("uartEvents")) {
|
||||
bool value = request->getParam("uartEvents")->value().toInt();
|
||||
jsonWriteBool(configSetupJson, "uartEvents", value);
|
||||
saveConfig();
|
||||
request->send(200);
|
||||
}
|
||||
if (request->hasArg("uartS")) {
|
||||
jsonWriteStr(configSetupJson, "uartS", request->getParam("uartS")->value());
|
||||
saveConfig();
|
||||
@@ -309,22 +296,7 @@ void web_init() {
|
||||
}
|
||||
});
|
||||
|
||||
//==============================list of items=====================================================
|
||||
//server.on("/del", HTTP_GET, [](AsyncWebServerRequest* request) {
|
||||
// if (request->hasArg("file")) {
|
||||
// itemsFile = request->getParam("file")->value();
|
||||
// }
|
||||
// if (request->hasArg("line")) {
|
||||
// itemsLine = request->getParam("line")->value();
|
||||
// }
|
||||
// delElementFlag = true;
|
||||
// deviceInit();
|
||||
// request->redirect("/?setn.device");
|
||||
//});
|
||||
|
||||
/*
|
||||
* Check
|
||||
*/
|
||||
server.on("/check", HTTP_GET, [](AsyncWebServerRequest* request) {
|
||||
myNotAsyncActions->make(do_GETLASTVERSION);
|
||||
SerialPrint("I", "Update", "firmware version: " + String(lastVersion));
|
||||
|
||||
@@ -20,17 +20,6 @@ ButtonOut::ButtonOut(String pin, boolean inv, String key, String type) {
|
||||
ButtonOut::~ButtonOut() {}
|
||||
|
||||
void ButtonOut::execute(String state) {
|
||||
if (_type == "UART") {
|
||||
if (jsonReadBool(configSetupJson, "uartEnable")) {
|
||||
#ifdef uartEnable
|
||||
if (myUART) {
|
||||
String msg = _key + " " + state;
|
||||
myUART->print(msg);
|
||||
SerialPrint("I", "<=UART", msg);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
if (state != "" && _pin != "") {
|
||||
if (state == "change") {
|
||||
state = String(!digitalRead(_pin.toInt()));
|
||||
|
||||
Reference in New Issue
Block a user