mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-30 11:59:12 +03:00
get mqtt remote
This commit is contained in:
@@ -1,12 +1,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
#include "Cmd.h"
|
#include "Cmd.h"
|
||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
|
|
||||||
class Scenario {
|
class Scenario {
|
||||||
|
public:
|
||||||
public:
|
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
if (!jsonReadBool(configSetupJson, "scen")) {
|
if (!jsonReadBool(configSetupJson, "scen")) {
|
||||||
return;
|
return;
|
||||||
@@ -27,7 +26,6 @@ public:
|
|||||||
String setEventKey = selectFromMarkerToMarker(condition, " ", 0);
|
String setEventKey = selectFromMarkerToMarker(condition, " ", 0);
|
||||||
|
|
||||||
if (incommingEventKey == setEventKey) {
|
if (incommingEventKey == setEventKey) {
|
||||||
|
|
||||||
String setEventSign = selectFromMarkerToMarker(condition, " ", 1);
|
String setEventSign = selectFromMarkerToMarker(condition, " ", 1);
|
||||||
String setEventValue = selectFromMarkerToMarker(condition, " ", 2);
|
String setEventValue = selectFromMarkerToMarker(condition, " ", 2);
|
||||||
|
|
||||||
@@ -42,13 +40,10 @@ public:
|
|||||||
|
|
||||||
if (setEventSign == ">") {
|
if (setEventSign == ">") {
|
||||||
setEventValue = upValue;
|
setEventValue = upValue;
|
||||||
}
|
} else if (setEventSign == "<") {
|
||||||
else if (setEventSign == "<") {
|
|
||||||
setEventValue = lowValue;
|
setEventValue = lowValue;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
setEventValue = getValue(setEventValue);
|
setEventValue = getValue(setEventValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -57,20 +52,15 @@ public:
|
|||||||
|
|
||||||
if (setEventSign == "=") {
|
if (setEventSign == "=") {
|
||||||
flag = incommingEventValue == setEventValue;
|
flag = incommingEventValue == setEventValue;
|
||||||
}
|
} else if (setEventSign == "!=") {
|
||||||
else if (setEventSign == "!=") {
|
|
||||||
flag = incommingEventValue != setEventValue;
|
flag = incommingEventValue != setEventValue;
|
||||||
}
|
} else if (setEventSign == "<") {
|
||||||
else if (setEventSign == "<") {
|
|
||||||
flag = incommingEventValue.toFloat() < setEventValue.toFloat();
|
flag = incommingEventValue.toFloat() < setEventValue.toFloat();
|
||||||
}
|
} else if (setEventSign == ">") {
|
||||||
else if (setEventSign == ">") {
|
|
||||||
flag = incommingEventValue.toFloat() > setEventValue.toFloat();
|
flag = incommingEventValue.toFloat() > setEventValue.toFloat();
|
||||||
}
|
} else if (setEventSign == ">=") {
|
||||||
else if (setEventSign == ">=") {
|
|
||||||
flag = incommingEventValue.toFloat() >= setEventValue.toFloat();
|
flag = incommingEventValue.toFloat() >= setEventValue.toFloat();
|
||||||
}
|
} else if (setEventSign == "<=") {
|
||||||
else if (setEventSign == "<=") {
|
|
||||||
flag = incommingEventValue.toFloat() <= setEventValue.toFloat();
|
flag = incommingEventValue.toFloat() <= setEventValue.toFloat();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include "Class/ScenarioClass3.h"
|
#include "Class/ScenarioClass3.h"
|
||||||
|
|
||||||
#include "MqttClient.h"
|
#include "MqttClient.h"
|
||||||
#include "RemoteOrdersUdp.h"
|
#include "RemoteOrdersUdp.h"
|
||||||
Scenario* myScenario;
|
Scenario* myScenario;
|
||||||
@@ -11,7 +12,9 @@ void eventGen2(String eventName, String eventValue) {
|
|||||||
eventBuf += event;
|
eventBuf += event;
|
||||||
|
|
||||||
if (jsonReadBool(configSetupJson, "MqttOut")) {
|
if (jsonReadBool(configSetupJson, "MqttOut")) {
|
||||||
publishEvent(eventName, eventValue);
|
if (eventName != "timenow") {
|
||||||
|
publishEvent(eventName, eventValue);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,6 @@ void espInit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void deviceInit() {
|
void deviceInit() {
|
||||||
|
|
||||||
//======clear dallas params======
|
//======clear dallas params======
|
||||||
if (mySensorDallas2 != nullptr) {
|
if (mySensorDallas2 != nullptr) {
|
||||||
mySensorDallas2->clear();
|
mySensorDallas2->clear();
|
||||||
@@ -111,7 +110,6 @@ void deviceInit() {
|
|||||||
} else {
|
} else {
|
||||||
jsonWriteStr(configSetupJson, F("warning3"), "");
|
jsonWriteStr(configSetupJson, F("warning3"), "");
|
||||||
}
|
}
|
||||||
|
|
||||||
//outcoming_date();
|
//outcoming_date();
|
||||||
}
|
}
|
||||||
//-------------------------------сценарии-----------------------------------------------------
|
//-------------------------------сценарии-----------------------------------------------------
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
#include "MqttClient.h"
|
#include "MqttClient.h"
|
||||||
|
|
||||||
#include "BufferExecute.h"
|
#include "BufferExecute.h"
|
||||||
#include "items/vLogging.h"
|
|
||||||
#include "Class/NotAsync.h"
|
#include "Class/NotAsync.h"
|
||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
#include "Init.h"
|
#include "Init.h"
|
||||||
|
#include "items/vLogging.h"
|
||||||
|
|
||||||
enum MqttBroker { MQTT_PRIMARY,
|
enum MqttBroker { MQTT_PRIMARY,
|
||||||
MQTT_RESERVE };
|
MQTT_RESERVE };
|
||||||
@@ -110,6 +111,7 @@ void mqttSubscribe() {
|
|||||||
|
|
||||||
if (jsonReadBool(configSetupJson, "MqttIn")) {
|
if (jsonReadBool(configSetupJson, "MqttIn")) {
|
||||||
mqtt.subscribe((mqttPrefix + "/+/+/event").c_str());
|
mqtt.subscribe((mqttPrefix + "/+/+/event").c_str());
|
||||||
|
mqtt.subscribe((mqttPrefix + "/+/+/order").c_str());
|
||||||
mqtt.subscribe((mqttPrefix + "/+/+/info").c_str());
|
mqtt.subscribe((mqttPrefix + "/+/+/info").c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -201,6 +203,17 @@ void mqttCallback(char* topic, uint8_t* payload, size_t length) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else if (topicStr.indexOf("order") != -1) {
|
||||||
|
if (!jsonReadBool(configSetupJson, "MqttIn")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String devId = selectFromMarkerToMarker(topicStr, "/", 2);
|
||||||
|
String key = selectFromMarkerToMarker(topicStr, "/", 3);
|
||||||
|
SerialPrint("I", "=>MQTT", "Received direct order " + key + " " + payloadStr);
|
||||||
|
String order = key + " " + payloadStr + ",";
|
||||||
|
orderBuf += order;
|
||||||
|
}
|
||||||
|
|
||||||
else if (topicStr.indexOf("info") != -1) {
|
else if (topicStr.indexOf("info") != -1) {
|
||||||
if (topicStr.indexOf("scen") != -1) {
|
if (topicStr.indexOf("scen") != -1) {
|
||||||
writeFile(String(DEVICE_SCENARIO_FILE), payloadStr);
|
writeFile(String(DEVICE_SCENARIO_FILE), payloadStr);
|
||||||
@@ -208,12 +221,6 @@ void mqttCallback(char* topic, uint8_t* payload, size_t length) {
|
|||||||
SerialPrint("I", "=>MQTT", "Scenario received");
|
SerialPrint("I", "=>MQTT", "Scenario received");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//else if (topicStr.indexOf("update")) {
|
|
||||||
// if (payloadStr == "1") {
|
|
||||||
// myNotAsyncActions->make(do_UPGRADE);
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean publish(const String& topic, const String& data) {
|
boolean publish(const String& topic, const String& data) {
|
||||||
|
|||||||
37
src/Web.cpp
37
src/Web.cpp
@@ -1,12 +1,13 @@
|
|||||||
#include "Web.h"
|
#include "Web.h"
|
||||||
|
|
||||||
#include "Class/NotAsync.h"
|
#include "Class/NotAsync.h"
|
||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
#include "Init.h"
|
#include "Init.h"
|
||||||
#include "ItemsList.h"
|
#include "ItemsList.h"
|
||||||
#include "items/vLogging.h"
|
|
||||||
#include "Telegram.h"
|
|
||||||
#include "RemoteOrdersUdp.h"
|
#include "RemoteOrdersUdp.h"
|
||||||
#include "SoftUART.h"
|
#include "SoftUART.h"
|
||||||
|
#include "Telegram.h"
|
||||||
|
#include "items/vLogging.h"
|
||||||
|
|
||||||
bool parseRequestForPreset(AsyncWebServerRequest* request, uint8_t& preset) {
|
bool parseRequestForPreset(AsyncWebServerRequest* request, uint8_t& preset) {
|
||||||
if (request->hasArg("preset")) {
|
if (request->hasArg("preset")) {
|
||||||
@@ -84,7 +85,6 @@ void web_init() {
|
|||||||
request->send(200);
|
request->send(200);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (request->hasArg(F("cleanlog"))) {
|
if (request->hasArg(F("cleanlog"))) {
|
||||||
cleanLogAndData();
|
cleanLogAndData();
|
||||||
request->send(200);
|
request->send(200);
|
||||||
@@ -325,8 +325,18 @@ void web_init() {
|
|||||||
serverIP = jsonReadStr(configSetupJson, "serverip");
|
serverIP = jsonReadStr(configSetupJson, "serverip");
|
||||||
request->send(200);
|
request->send(200);
|
||||||
}
|
}
|
||||||
});
|
//set?order=button_1
|
||||||
|
if (request->hasArg("order")) {
|
||||||
|
String order = request->getParam("order")->value();
|
||||||
|
order.replace("_"," ");
|
||||||
|
orderBuf += order + ",";
|
||||||
|
request->send(200);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
server.on("/order", HTTP_GET, [](AsyncWebServerRequest* request) {
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
server.on("/check", HTTP_GET, [](AsyncWebServerRequest* request) {
|
server.on("/check", HTTP_GET, [](AsyncWebServerRequest* request) {
|
||||||
myNotAsyncActions->make(do_GETLASTVERSION);
|
myNotAsyncActions->make(do_GETLASTVERSION);
|
||||||
@@ -336,21 +346,16 @@ void web_init() {
|
|||||||
|
|
||||||
if (ESP8266_FLASH_SIZE_1MB) {
|
if (ESP8266_FLASH_SIZE_1MB) {
|
||||||
msg = F("Обновление невозможно, память устройства 1 мб");
|
msg = F("Обновление невозможно, память устройства 1 мб");
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
if (lastVersion == FIRMWARE_VERSION) {
|
if (lastVersion == FIRMWARE_VERSION) {
|
||||||
msg = F("Актуальная версия прошивки уже установлена.");
|
msg = F("Актуальная версия прошивки уже установлена.");
|
||||||
}
|
} else if (lastVersion > FIRMWARE_VERSION) {
|
||||||
else if (lastVersion > FIRMWARE_VERSION) {
|
|
||||||
msg = F("Новая версия прошивки<a href=\"#\" class=\"btn btn-block btn-danger\" onclick=\"send_request(this, '/upgrade');setTimeout(function(){ location.href='/?set.device'; }, 90000);html('my-block','<span class=loader></span>Идет обновление прошивки, после обновления страница перезагрузится автоматически...')\">Установить</a>");
|
msg = F("Новая версия прошивки<a href=\"#\" class=\"btn btn-block btn-danger\" onclick=\"send_request(this, '/upgrade');setTimeout(function(){ location.href='/?set.device'; }, 90000);html('my-block','<span class=loader></span>Идет обновление прошивки, после обновления страница перезагрузится автоматически...')\">Установить</a>");
|
||||||
}
|
} else if (lastVersion == -1) {
|
||||||
else if (lastVersion == -1) {
|
|
||||||
msg = F("Cервер не найден. Попробуйте повторить позже...");
|
msg = F("Cервер не найден. Попробуйте повторить позже...");
|
||||||
}
|
} else if (lastVersion == -2) {
|
||||||
else if (lastVersion == -2) {
|
|
||||||
msg = F("Устройство не подключено к роутеру!");
|
msg = F("Устройство не подключено к роутеру!");
|
||||||
}
|
} else if (lastVersion < FIRMWARE_VERSION) {
|
||||||
else if (lastVersion < FIRMWARE_VERSION) {
|
|
||||||
msg = F("Ошибка версии. Попробуйте повторить позже...");
|
msg = F("Ошибка версии. Попробуйте повторить позже...");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -359,7 +364,7 @@ void web_init() {
|
|||||||
jsonWriteStr(tmp, "title", "<button class=\"close\" onclick=\"toggle('my-block')\">×</button>" + msg);
|
jsonWriteStr(tmp, "title", "<button class=\"close\" onclick=\"toggle('my-block')\">×</button>" + msg);
|
||||||
jsonWriteStr(tmp, "class", "pop-up");
|
jsonWriteStr(tmp, "class", "pop-up");
|
||||||
request->send(200, "text/html", tmp);
|
request->send(200, "text/html", tmp);
|
||||||
});
|
});
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Upgrade
|
* Upgrade
|
||||||
@@ -367,7 +372,7 @@ void web_init() {
|
|||||||
server.on("/upgrade", HTTP_GET, [](AsyncWebServerRequest* request) {
|
server.on("/upgrade", HTTP_GET, [](AsyncWebServerRequest* request) {
|
||||||
myNotAsyncActions->make(do_UPGRADE);
|
myNotAsyncActions->make(do_UPGRADE);
|
||||||
request->send(200, "text/html");
|
request->send(200, "text/html");
|
||||||
});
|
});
|
||||||
|
|
||||||
SerialPrint("I", F("Web"), F("WebAdmin Init"));
|
SerialPrint("I", F("Web"), F("WebAdmin Init"));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,11 +2,10 @@
|
|||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
#include "FileSystem.h"
|
|
||||||
|
|
||||||
#include "Class/LineParsing.h"
|
|
||||||
#include "Global.h"
|
|
||||||
#include "BufferExecute.h"
|
#include "BufferExecute.h"
|
||||||
|
#include "Class/LineParsing.h"
|
||||||
|
#include "FileSystem.h"
|
||||||
|
#include "Global.h"
|
||||||
|
|
||||||
LoggingClass::LoggingClass(unsigned long period, unsigned int maxPoints, String loggingValueKey, String key) {
|
LoggingClass::LoggingClass(unsigned long period, unsigned int maxPoints, String loggingValueKey, String key) {
|
||||||
_period = period * 1000;
|
_period = period * 1000;
|
||||||
@@ -28,10 +27,25 @@ void LoggingClass::loop() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoggingClass::execute(String payload) {
|
void LoggingClass::execute(String keyOrValue) {
|
||||||
|
String loggingValue = "";
|
||||||
|
|
||||||
if (_period > 0) {
|
if (keyOrValue == "") { //прилетело из лупа
|
||||||
payload = getValue(_loggingValueKey);
|
if (getValue(_loggingValueKey) != "no value") {
|
||||||
|
loggingValue = getValue(_loggingValueKey);
|
||||||
|
} else {
|
||||||
|
SerialPrint("E", "Logging", "This value not found on this device");
|
||||||
|
}
|
||||||
|
} else { //прилетело из события
|
||||||
|
if (isDigitStr(keyOrValue)) { //если это число
|
||||||
|
loggingValue = keyOrValue;
|
||||||
|
} else { //если это ключ
|
||||||
|
if (getValue(_loggingValueKey) != "no value") {
|
||||||
|
loggingValue = getValue(keyOrValue);
|
||||||
|
} else {
|
||||||
|
SerialPrint("E", "Logging", "This value not found on this device");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String filename = "logs/" + _key + ".txt";
|
String filename = "logs/" + _key + ".txt";
|
||||||
@@ -46,20 +60,24 @@ void LoggingClass::execute(String payload) {
|
|||||||
lines_cnt = 0;
|
lines_cnt = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (payload != "") {
|
if (loggingValue != "") {
|
||||||
if (lines_cnt > _maxPoints) {
|
if (lines_cnt > _maxPoints) { //удаляем старую строку и добавляем новую
|
||||||
logData = deleteBeforeDelimiter(logData, "\r\n");
|
logData = deleteBeforeDelimiter(logData, "\r\n");
|
||||||
if (timeNow->hasTimeSynced()) {
|
if (timeNow->hasTimeSynced()) {
|
||||||
logData += timeNow->getTimeUnix() + " " + payload + "\r\n";
|
logData += timeNow->getTimeUnix() + " " + loggingValue + "\r\n";
|
||||||
writeFile(filename, logData);
|
writeFile(filename, logData);
|
||||||
}
|
}
|
||||||
}
|
} else { //просто добавляем новую строку
|
||||||
else {
|
|
||||||
if (timeNow->hasTimeSynced()) {
|
if (timeNow->hasTimeSynced()) {
|
||||||
addFileLn(filename, timeNow->getTimeUnix() + " " + payload);
|
addFileLn(filename, timeNow->getTimeUnix() + " " + loggingValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
String buf = "{}";
|
||||||
|
jsonWriteInt(buf, "x", timeNow->getTimeUnix().toInt());
|
||||||
|
jsonWriteFloat(buf, "y1", loggingValue.toFloat());
|
||||||
|
buf = "{\"status\":[" + buf + "]}";
|
||||||
|
publishChart(_key, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
MyLoggingVector* myLogging = nullptr;
|
MyLoggingVector* myLogging = nullptr;
|
||||||
@@ -88,13 +106,7 @@ void logging() {
|
|||||||
void loggingExecute() {
|
void loggingExecute() {
|
||||||
String key = sCmd.order();
|
String key = sCmd.order();
|
||||||
String value = sCmd.next();
|
String value = sCmd.next();
|
||||||
|
|
||||||
if (!isDigitStr(value)) { //если значение - текст
|
|
||||||
value = getValue(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
int number = getKeyNum(key, logging_KeyList);
|
int number = getKeyNum(key, logging_KeyList);
|
||||||
|
|
||||||
if (myLogging != nullptr) {
|
if (myLogging != nullptr) {
|
||||||
if (number != -1) {
|
if (number != -1) {
|
||||||
myLogging->at(number).execute(value);
|
myLogging->at(number).execute(value);
|
||||||
@@ -102,8 +114,6 @@ void loggingExecute() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void choose_log_date_and_send() {
|
void choose_log_date_and_send() {
|
||||||
String all_line = logging_KeyList;
|
String all_line = logging_KeyList;
|
||||||
while (all_line.length() != 0) {
|
while (all_line.length() != 0) {
|
||||||
@@ -131,8 +141,7 @@ void sendLogData(String file, String topic) {
|
|||||||
jsonWriteFloat(buf, "y1", value.toFloat());
|
jsonWriteFloat(buf, "y1", value.toFloat());
|
||||||
if (log_date.length() < 3) {
|
if (log_date.length() < 3) {
|
||||||
json_array += buf;
|
json_array += buf;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
json_array += buf + ",";
|
json_array += buf + ",";
|
||||||
}
|
}
|
||||||
buf = "{}";
|
buf = "{}";
|
||||||
@@ -148,7 +157,6 @@ void sendLogData(String file, String topic) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void cleanLogAndData() {
|
void cleanLogAndData() {
|
||||||
|
|
||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
auto dir = FileFS.openDir("logs");
|
auto dir = FileFS.openDir("logs");
|
||||||
while (dir.next()) {
|
while (dir.next()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user