mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 22:22:16 +03:00
websocket & function
This commit is contained in:
@@ -7,7 +7,15 @@
|
||||
|
||||
//для того что бы выключить оригинальный лог нужно перейти в файл библиотеки MyGatewayTransportSerial.cpp
|
||||
//и заккоментировать строку 36 MY_SERIALDEVICE.print(protocolMyMessage2Serial(message));
|
||||
|
||||
boolean publishAnyJsonKeyWS(const String& topic, const String& key, const String& data) {
|
||||
String path = mqttRootDevice + "/" + topic + "/status";
|
||||
String json = "{}";
|
||||
jsonWriteStr(json, key, data);
|
||||
//добавляем топик, выводим в ws
|
||||
String MyJson = json;
|
||||
jsonWriteStr(MyJson, "topic", path);
|
||||
ws.textAll(MyJson);
|
||||
}
|
||||
void loopMySensorsExecute() {
|
||||
if (mysensorBuf.length()) {
|
||||
String tmp = selectToMarker(mysensorBuf, ";");
|
||||
@@ -27,9 +35,15 @@ void loopMySensorsExecute() {
|
||||
if (command == "3") { //это особое внутреннее сообщение
|
||||
if (type == "11") { //название ноды
|
||||
SerialPrint("I", "MySensor", "Node name: " + value);
|
||||
}
|
||||
//*
|
||||
publishAnyJsonKey("MySensors", "Node name:", value);
|
||||
publishAnyJsonKeyWS("MySensors", "Node name:", value);
|
||||
}
|
||||
if (type == "12") { //версия ноды
|
||||
SerialPrint("I", "MySensor", "Node version: " + value);
|
||||
//*
|
||||
publishAnyJsonKey("MySensors", "Node version: ", value);
|
||||
publishAnyJsonKeyWS("MySensors", "Node version: ", value);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -44,13 +58,26 @@ void loopMySensorsExecute() {
|
||||
addItemAuto(num, key, widget, descr);
|
||||
descr.replace("#", " ");
|
||||
SerialPrint("I", "MySensor", "Add new item: " + key + ": " + descr);
|
||||
//*
|
||||
publishAnyJsonKey("MySensors", key, descr);
|
||||
publishAnyJsonKeyWS("MySensors", key, descr);
|
||||
|
||||
|
||||
} else {
|
||||
descr.replace("#", " ");
|
||||
SerialPrint("I", "MySensor", "Item already exist: " + key + ": " + descr);
|
||||
|
||||
//*
|
||||
publishAnyJsonKey("MySensors", key, descr);
|
||||
publishAnyJsonKeyWS("MySensors", key, descr);
|
||||
}
|
||||
} else {
|
||||
descr.replace("#", " ");
|
||||
SerialPrint("I", "MySensor", "Presentation: " + key + ": " + descr);
|
||||
|
||||
//*
|
||||
publishAnyJsonKey("MySensors", key, descr);
|
||||
publishAnyJsonKeyWS("MySensors", key, descr);
|
||||
}
|
||||
}
|
||||
if (command == "1") { //это данные
|
||||
@@ -63,6 +90,9 @@ void loopMySensorsExecute() {
|
||||
if (mySensorNode != nullptr) {
|
||||
for (unsigned int i = 0; i < mySensorNode->size(); i++) {
|
||||
mySensorNode->at(i).onChange(value, key); //вызываем поочередно все экземпляры, там где подойдет там и выполнится
|
||||
//*
|
||||
publishAnyJsonKey("MySensors", key, value);
|
||||
publishAnyJsonKeyWS("MySensors", key, value);
|
||||
}
|
||||
}
|
||||
SerialPrint("I", "MySensor", "node: " + nodeId + ", sensor: " + childSensorId + ", command: " + command + ", type: " + type + ", val: " + value);
|
||||
|
||||
@@ -8,11 +8,14 @@
|
||||
#endif
|
||||
|
||||
#include "Global.h"
|
||||
|
||||
String msg = "";
|
||||
void upgradeInit() {
|
||||
|
||||
|
||||
myNotAsyncActions->add(
|
||||
do_UPGRADE, [&](void*) {
|
||||
upgrade_firmware(3);
|
||||
|
||||
},
|
||||
nullptr);
|
||||
|
||||
@@ -27,7 +30,7 @@ void upgradeInit() {
|
||||
if (lastVersion > 0) {
|
||||
SerialPrint("I", F("Update"), "available version: " + String(lastVersion));
|
||||
if (lastVersion > FIRMWARE_VERSION) {
|
||||
jsonWriteStr(configSetupJson, "warning2", F("Вышла новая версия прошивки, нажмите обновить прошивку"));
|
||||
jsonWriteStr(configSetupJson, "warning2", 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;'>Вышла новая версия прошивки, нажмите <b>обновить прошивку</b></p></font></div>"));
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -61,6 +64,8 @@ void getLastVersion() {
|
||||
}
|
||||
|
||||
void upgrade_firmware(int type) {
|
||||
|
||||
|
||||
String scenario_ForUpdate;
|
||||
String devconfig_ForUpdate;
|
||||
String configSetup_ForUpdate;
|
||||
@@ -69,11 +74,11 @@ void upgrade_firmware(int type) {
|
||||
devconfig_ForUpdate = readFile(String(DEVICE_CONFIG_FILE), 4096);
|
||||
configSetup_ForUpdate = configSetupJson;
|
||||
|
||||
if (type == 1) { // only build
|
||||
if (type == 1) { //only build
|
||||
if (upgradeBuild()) restartEsp();
|
||||
}
|
||||
|
||||
else if (type == 2) { // only spiffs
|
||||
else if (type == 2) { //only spiffs
|
||||
if (upgradeFS()) {
|
||||
writeFile(String(DEVICE_SCENARIO_FILE), scenario_ForUpdate);
|
||||
writeFile(String(DEVICE_CONFIG_FILE), devconfig_ForUpdate);
|
||||
@@ -82,8 +87,10 @@ void upgrade_firmware(int type) {
|
||||
}
|
||||
}
|
||||
|
||||
else if (type == 3) { // spiffs and build
|
||||
else if (type == 3) { //spiffs and build
|
||||
if (upgradeFS()) {
|
||||
String temp = jsonWriteInt(msg, "upgrade", 3 );
|
||||
ws.textAll(temp);
|
||||
writeFile(String(DEVICE_SCENARIO_FILE), scenario_ForUpdate);
|
||||
writeFile(String(DEVICE_CONFIG_FILE), devconfig_ForUpdate);
|
||||
writeFile("config.json", configSetup_ForUpdate);
|
||||
@@ -95,11 +102,18 @@ void upgrade_firmware(int type) {
|
||||
}
|
||||
}
|
||||
|
||||
bool upgradeFS() {
|
||||
bool ret = false;
|
||||
bool upgradeFS() {
|
||||
|
||||
|
||||
|
||||
bool ret = false;
|
||||
#ifndef esp8266_1mb
|
||||
WiFiClient wifiClient;
|
||||
|
||||
|
||||
|
||||
Serial.printf("Start upgrade %s, please wait...", FS_NAME);
|
||||
|
||||
#ifdef esp8266_4mb
|
||||
ESPhttpUpdate.rebootOnUpdate(false);
|
||||
t_httpUpdate_return retFS = ESPhttpUpdate.updateFS(wifiClient, serverIP + F("/projects/iotmanager/esp8266/littlefs/littlefs.bin"));
|
||||
@@ -117,6 +131,8 @@ bool upgradeFS() {
|
||||
HTTPUpdateResult retFS = httpUpdate.updateSpiffs(wifiClient, serverIP + F("/projects/iotmanager/esp32ms/littlefs/spiffs.bin"));
|
||||
#endif
|
||||
if (retFS == HTTP_UPDATE_OK) { //если FS обновилась успешно
|
||||
String temp = jsonWriteInt(msg, "upgrade", 2);
|
||||
ws.textAll(temp);
|
||||
SerialPrint("I", F("Update"), F("FS upgrade done!"));
|
||||
ret = true;
|
||||
}
|
||||
@@ -125,6 +141,8 @@ bool upgradeFS() {
|
||||
}
|
||||
|
||||
bool upgradeBuild() {
|
||||
String temp = jsonWriteInt(msg, "upgrade", 4 );
|
||||
ws.textAll(temp);
|
||||
bool ret = false;
|
||||
#ifndef esp8266_1mb
|
||||
WiFiClient wifiClient;
|
||||
@@ -149,12 +167,16 @@ bool upgradeBuild() {
|
||||
if (retBuild == HTTP_UPDATE_OK) { //если BUILD обновился успешно
|
||||
SerialPrint("I", F("Update"), F("BUILD upgrade done!"));
|
||||
ret = true;
|
||||
String temp = jsonWriteInt(msg, "upgrade", 5 );
|
||||
ws.textAll(temp);
|
||||
}
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
void restartEsp() {
|
||||
String temp = jsonWriteInt(msg, "upgrade", 6 );
|
||||
ws.textAll(temp);
|
||||
Serial.println(F("Restart ESP...."));
|
||||
delay(1000);
|
||||
ESP.restart();
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
#include "Utils\SerialPrint.h"
|
||||
|
||||
#include "Global.h"
|
||||
|
||||
void SerialPrint(String errorLevel, String module, String msg) {
|
||||
//if (module == "MySensor") {
|
||||
Serial.println(prettyMillis(millis()) + " [" + errorLevel + "] [" + module + "] " + msg);
|
||||
String logtoWS = jsonReadStr(configSetupJson, "logtoWS");
|
||||
if (logtoWS == "true"){
|
||||
ws.textAll(" [" + errorLevel + "] [" + module + "] " + msg);
|
||||
}
|
||||
String logtoMQTT = jsonReadStr(configSetupJson, "logtoMQTT");
|
||||
if (logtoMQTT == "true"){
|
||||
publishAnyJsonKey("log", "log", errorLevel + " " + module + " " + msg);
|
||||
}
|
||||
//}
|
||||
}
|
||||
@@ -3,7 +3,13 @@
|
||||
#include "Utils/FileUtils.h"
|
||||
#include "Utils/WebUtils.h"
|
||||
#include "FSEditor.h"
|
||||
#include "Upgrade.h"
|
||||
#include "Class/NotAsync.h"
|
||||
#include "items/vLogging.h"
|
||||
|
||||
int flagq ;
|
||||
AsyncWebSocket ws ("/ws");
|
||||
AsyncEventSource events("/events");
|
||||
namespace HttpServer {
|
||||
|
||||
|
||||
@@ -84,12 +90,100 @@ void init() {
|
||||
|
||||
SerialPrint("I", F("HTTP"), F("HttpServer Init"));
|
||||
}
|
||||
///////////
|
||||
|
||||
#ifndef LAYOUT_IN_RAM
|
||||
void publishWidgetsWS() {
|
||||
String str="";
|
||||
auto file = seekFile("layout.txt");
|
||||
if (!file) {
|
||||
SerialPrint("E", F("WS"), F("no file layout.txt"));
|
||||
return;
|
||||
}
|
||||
while (file.available()) {
|
||||
|
||||
String payload = file.readStringUntil('\n');
|
||||
if (str==""){
|
||||
str += payload;
|
||||
}else {str += "," + payload;}
|
||||
|
||||
}
|
||||
file.close();
|
||||
SerialPrint("I", "WS", "widgets: " + str);
|
||||
ws.textAll(str);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void publishStateWS() {
|
||||
String mystr="";
|
||||
String str;
|
||||
if (configLiveJson != "{}") {
|
||||
str += configLiveJson;
|
||||
}
|
||||
if (configStoreJson != "{}") {
|
||||
str += "," + configStoreJson;
|
||||
}
|
||||
|
||||
|
||||
|
||||
str.replace("{", "");
|
||||
str.replace("}", "");
|
||||
str.replace("\"", "");
|
||||
str += ",";
|
||||
|
||||
while (str.length() != 0) {
|
||||
String tmp = selectToMarker(str, ",");
|
||||
String topic = selectToMarker(tmp, ":");
|
||||
String state = deleteBeforeDelimiter(tmp, ":");
|
||||
|
||||
|
||||
if (topic != "" && state != "") {
|
||||
|
||||
String json = "{}";
|
||||
jsonWriteStr(json, "status", state);
|
||||
jsonWriteStr(json, "topic", mqttRootDevice + "/" + topic + "/status");
|
||||
SerialPrint("I", "ws", json.c_str());
|
||||
if (mystr==""){
|
||||
mystr += json;
|
||||
}else {mystr += "," + json;}
|
||||
|
||||
|
||||
}
|
||||
str = deleteBeforeDelimiter(str, ",");
|
||||
}
|
||||
ws.textAll(mystr);
|
||||
|
||||
}
|
||||
/*
|
||||
boolean publishStatusWS(const String& topic, const String& data) {
|
||||
String path = mqttRootDevice + "/" + topic + "/status";
|
||||
String json = "{}";
|
||||
jsonWriteStr(json, "status", data);
|
||||
String MyJson = json;
|
||||
jsonWriteStr(MyJson, "topic", path);
|
||||
ws.textAll(MyJson);
|
||||
|
||||
}
|
||||
*/
|
||||
boolean publishAnyJsonKeyWS(const String& topic, const String& key, const String& data) {
|
||||
String path = mqttRootDevice + "/" + topic + "/status";
|
||||
String json = "{}";
|
||||
jsonWriteStr(json, key, data);
|
||||
//добавляем топик, выводим в ws
|
||||
String MyJson = json;
|
||||
jsonWriteStr(MyJson, "topic", path);
|
||||
ws.textAll(MyJson);
|
||||
}
|
||||
#endif
|
||||
|
||||
/////////
|
||||
void onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventType type, void *arg, uint8_t *data, size_t len) {
|
||||
#ifdef WS_enable
|
||||
#ifdef WEBSOCKET_ENABLED
|
||||
if (type == WS_EVT_CONNECT) {
|
||||
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();
|
||||
} else if (type == WS_EVT_DISCONNECT) {
|
||||
Serial.printf("ws[%s][%u] disconnect\n", server->url(), client->id());
|
||||
@@ -116,6 +210,121 @@ void onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventTyp
|
||||
}
|
||||
}
|
||||
Serial.printf("%s\n", msg.c_str());
|
||||
//->
|
||||
//если пришло HELLO публикуем виджеты и статусы
|
||||
if (msg.startsWith("HELLO")) {
|
||||
SerialPrint("I", F("WS"), F("Full update"));
|
||||
publishWidgetsWS();
|
||||
publishStateWS();
|
||||
flagq = 1;
|
||||
}
|
||||
//если пришло UPGRADE
|
||||
if (msg.startsWith("upgrade")) {
|
||||
// SerialPrint("I", F("WS"), F("do_UPGRADEstart"));
|
||||
myNotAsyncActions->make(do_UPGRADE);
|
||||
String temp = jsonWriteInt(msg, "upgrade", 1 );
|
||||
ws.textAll(temp);
|
||||
}
|
||||
|
||||
String upgrade = jsonReadStr(msg, "upgrade");
|
||||
|
||||
if (upgrade != ""){
|
||||
// SerialPrint("I", F("WS"), F("do_UPGRADE"));
|
||||
myNotAsyncActions->make(do_UPGRADE);
|
||||
String temp = jsonWriteInt(msg, "upgrade", 1 );
|
||||
ws.textAll(temp);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//отправляем конфигурацию на ESP
|
||||
if (msg.startsWith("getconfigsetupjson")) {
|
||||
ws.textAll(configSetupJson);
|
||||
// Serial.printf("%s\n", configSetupJson.c_str());
|
||||
}
|
||||
//отправляем NetworkMap в ESP
|
||||
if (msg.startsWith("getNetworkMap")) {
|
||||
String NetworkMap= readFile("NetworkMap.json", 409600);
|
||||
// NetworkMap = NetworkMap.replace("\r\n", "");
|
||||
ws.textAll(NetworkMap);
|
||||
|
||||
}
|
||||
|
||||
//отправляем файл в ESP
|
||||
String getFileName = jsonReadStr(msg, "getFileName");
|
||||
if (getFileName !=""){
|
||||
String getFile= readFile(getFileName, 409600);
|
||||
// getFile.replace("\n", " ");
|
||||
getFile="{getFileText:'"+getFile+"', getFileName: '"+getFileName+"'}";
|
||||
jsonWriteStr(getFile, "getFileName", getFileName);
|
||||
ws.textAll(getFile);
|
||||
Serial.printf("%s\n getFileName: ", getFileName.c_str());
|
||||
Serial.printf("%s\n getFile: ", getFile.c_str());
|
||||
}
|
||||
//получаем файл от ESP
|
||||
|
||||
String setFileName = jsonReadStr(msg, "setFileName");
|
||||
if (setFileName !=""){
|
||||
|
||||
|
||||
DynamicJsonBuffer jsonBuffer;
|
||||
JsonObject& root = jsonBuffer.parseObject(msg);
|
||||
|
||||
root.remove("setFileName");
|
||||
String newmsg;
|
||||
root.printTo(newmsg);
|
||||
|
||||
|
||||
writeFile(setFileName,newmsg);
|
||||
//Serial.printf("%s\n setFileName: ", setFileName.c_str());
|
||||
Serial.printf("%s\n text: ", newmsg.c_str());
|
||||
}
|
||||
|
||||
//получаем NetworkMap от ESP
|
||||
String NetworkMap = jsonReadStr(msg, "NetworkMap");
|
||||
if (NetworkMap !=""){
|
||||
writeFile("NetworkMap.json", NetworkMap.c_str());
|
||||
// ws.textAll(NetworkMap);
|
||||
}
|
||||
//перезагрузка
|
||||
String command = jsonReadStr(msg, "command");
|
||||
if (command !="" && jsonReadStr(msg, "command")=="reboot"){
|
||||
ESP.restart();
|
||||
}
|
||||
|
||||
|
||||
|
||||
//получаем конфигурацию от ESP
|
||||
|
||||
String changeConf = jsonReadStr(msg, "setconfigsetupjson");
|
||||
if (changeConf = "1"){
|
||||
|
||||
jsonWriteStr(configSetupJson, jsonReadStr(msg, "name"), jsonReadStr(msg, "val"));
|
||||
saveConfig();
|
||||
Serial.printf("%s\n", jsonReadStr(msg, "name").c_str(), jsonReadStr(msg, "val").c_str());
|
||||
}
|
||||
|
||||
|
||||
|
||||
// если пришло в control управляем
|
||||
String path = jsonReadStr(msg, "path");
|
||||
String status = jsonReadStr(msg, "status");
|
||||
|
||||
if (path.indexOf("control") != -1) {
|
||||
String key = selectFromMarkerToMarker(path, "/", 3);
|
||||
|
||||
String order;
|
||||
order += key;
|
||||
order += " ";
|
||||
order += status;
|
||||
order += ",";
|
||||
|
||||
loopCmdAdd(order);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if (info->opcode == WS_TEXT)
|
||||
client->text("{}");
|
||||
@@ -200,7 +409,7 @@ void initOta() {
|
||||
}
|
||||
|
||||
void initWS() {
|
||||
#ifdef WS_enable
|
||||
#ifdef WEBSOCKET_ENABLED
|
||||
ws.onEvent(onWsEvent);
|
||||
server.addHandler(&ws);
|
||||
events.onConnect([](AsyncEventSourceClient *client) {
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "Global.h"
|
||||
#include "SoftUART.h"
|
||||
#include "items/vButtonOut.h"
|
||||
//#include "WebServer.h"
|
||||
//this class save data to flash
|
||||
ButtonOut::ButtonOut(String pin, boolean inv, String key, String type) {
|
||||
_pin = pin;
|
||||
@@ -21,6 +22,12 @@ ButtonOut::ButtonOut(String pin, boolean inv, String key, String type) {
|
||||
this->execute(String(state)); //установили это состояние
|
||||
#endif
|
||||
#ifdef GATE_MODE
|
||||
if (_pin != "") {
|
||||
pinMode(_pin.toInt(), OUTPUT);
|
||||
}
|
||||
int state = jsonReadInt(configStoreJson, key); //прочитали из памяти
|
||||
this->execute(String(state)); //установили это состояние
|
||||
|
||||
//TO DO запросили ноду о состоянии реле
|
||||
//установили в это состояние кнопку в приложении
|
||||
//если нода не ответила - кнопку сделать красным цветом
|
||||
@@ -44,6 +51,20 @@ void ButtonOut::execute(String state) {
|
||||
}
|
||||
#endif
|
||||
#ifdef GATE_MODE
|
||||
// включаем кнопки на ESP гейта
|
||||
if (state != "" && _pin != "") {
|
||||
if (state == "change") {
|
||||
state = String(!digitalRead(_pin.toInt()));
|
||||
digitalWrite(_pin.toInt(), state.toInt());
|
||||
} else {
|
||||
if (_inv) {
|
||||
digitalWrite(_pin.toInt(), !state.toInt());
|
||||
} else {
|
||||
digitalWrite(_pin.toInt(), state.toInt());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//отправили ноде команду на вкл выкл
|
||||
//получили обратную связь - переставили кнопку в приложении
|
||||
//не получили обратную связь - сделали кнопку красной
|
||||
@@ -52,6 +73,12 @@ void ButtonOut::execute(String state) {
|
||||
jsonWriteInt(configStoreJson, _key, state.toInt());
|
||||
saveStore();
|
||||
publishStatus(_key, state);
|
||||
String path = mqttRootDevice + "/" + _key + "/status";
|
||||
String json = "{}";
|
||||
jsonWriteStr(json, "status", state);
|
||||
String MyJson = json;
|
||||
jsonWriteStr(MyJson, "topic", path);
|
||||
ws.textAll(MyJson);
|
||||
}
|
||||
|
||||
MyButtonOutVector* myButtonOut = nullptr;
|
||||
|
||||
@@ -32,6 +32,12 @@ void CountDownClass::loop() {
|
||||
String time = String(prettyMillis(sec * 1000));
|
||||
jsonWriteStr(configLiveJson, _key, time);
|
||||
publishStatus(_key, time);
|
||||
String path = mqttRootDevice + "/" + _key + "/status";
|
||||
String json = "{}";
|
||||
jsonWriteStr(json, "status", time);
|
||||
String MyJson = json;
|
||||
jsonWriteStr(MyJson, "topic", path);
|
||||
ws.textAll(MyJson);
|
||||
sec--;
|
||||
if (sec < 0) {
|
||||
_countDownPeriod = 0;
|
||||
@@ -48,10 +54,8 @@ void countDown() {
|
||||
|
||||
countDown_EnterCounter++;
|
||||
addKey(key, countDown_KeyList, countDown_EnterCounter);
|
||||
|
||||
//Serial.println(countDown_EnterCounter);
|
||||
//Serial.println(countDown_KeyList);
|
||||
|
||||
static bool firstTime = true;
|
||||
if (firstTime) myCountDown = new MyCountDownVector();
|
||||
firstTime = false;
|
||||
|
||||
@@ -31,6 +31,12 @@ void Input::execute(String value) {
|
||||
jsonWriteStr(configStoreJson, _key, value);
|
||||
saveStore();
|
||||
publishStatus(_key, value);
|
||||
String path = mqttRootDevice + "/" + _key + "/status";
|
||||
String json = "{}";
|
||||
jsonWriteStr(json, "status", value);
|
||||
String MyJson = json;
|
||||
jsonWriteStr(MyJson, "topic", path);
|
||||
ws.textAll(MyJson);
|
||||
}
|
||||
|
||||
MyInputVector* myInput = nullptr;
|
||||
|
||||
@@ -166,7 +166,78 @@ void loggingExecute() {
|
||||
}
|
||||
}
|
||||
|
||||
void choose_log_date_and_sendWS() {
|
||||
|
||||
String all_line = logging_KeyList;
|
||||
while (all_line.length() != 0) {
|
||||
String tmp = selectToMarker(all_line, ",");
|
||||
sendLogDataWS("/logs/" + tmp + ".txt", tmp);
|
||||
all_line = deleteBeforeDelimiter(all_line, ",");
|
||||
}
|
||||
}
|
||||
|
||||
void sendLogDataWS(String file, String topic) {
|
||||
File configFile = FileFS.open(file, "r");
|
||||
if (!configFile) {
|
||||
return;
|
||||
}
|
||||
configFile.seek(0, SeekSet);
|
||||
int i = 0;
|
||||
String buf = "{}";
|
||||
String json_array;
|
||||
String unix_time;
|
||||
String value;
|
||||
unsigned int psn;
|
||||
unsigned int sz = configFile.size();
|
||||
do {
|
||||
i++;
|
||||
psn = configFile.position();
|
||||
String line = configFile.readStringUntil('\n');
|
||||
unix_time = selectToMarker(line, " ");
|
||||
jsonWriteInt(buf, "x", unix_time.toInt());
|
||||
value = deleteBeforeDelimiter(line, " ");
|
||||
jsonWriteFloat(buf, "y1", value.toFloat());
|
||||
if (unix_time != "" || value != "") {
|
||||
json_array += buf + ",";
|
||||
}
|
||||
int grafmax = jsonReadInt(configSetupJson, "grafmax");
|
||||
if (grafmax != 0) {
|
||||
if (i >= grafmax) {
|
||||
json_array = "{\"status\":[" + json_array + "]}";
|
||||
json_array.replace("},]}", "}]}");
|
||||
// publishChart(topic, json_array);
|
||||
|
||||
// добавляем топик, выводим в ws
|
||||
String path = mqttRootDevice + "/" + topic;
|
||||
String json = "{}";
|
||||
json=json_array;
|
||||
jsonWriteStr(json, "topic", path);
|
||||
ws.textAll(json);
|
||||
|
||||
|
||||
json_array = "";
|
||||
i = 0;
|
||||
}
|
||||
}
|
||||
} while (psn < sz);
|
||||
|
||||
configFile.close();
|
||||
|
||||
json_array = "{\"status\":[" + json_array + "]}";
|
||||
json_array.replace("},]}", "}]}");
|
||||
//publishChart(topic, json_array);
|
||||
|
||||
// добавляем топик, выводим в ws
|
||||
String path = mqttRootDevice + "/" + topic;
|
||||
String json = "{}";
|
||||
json=json_array;
|
||||
jsonWriteStr(json, "topic", path);
|
||||
ws.textAll(json);
|
||||
|
||||
}
|
||||
|
||||
void choose_log_date_and_send() {
|
||||
|
||||
String all_line = logging_KeyList;
|
||||
while (all_line.length() != 0) {
|
||||
String tmp = selectToMarker(all_line, ",");
|
||||
@@ -205,7 +276,8 @@ void sendLogData(String file, String topic) {
|
||||
json_array = "{\"status\":[" + json_array + "]}";
|
||||
json_array.replace("},]}", "}]}");
|
||||
publishChart(topic, json_array);
|
||||
json_array = "";
|
||||
|
||||
json_array = "";
|
||||
i = 0;
|
||||
}
|
||||
}
|
||||
@@ -216,6 +288,7 @@ void sendLogData(String file, String topic) {
|
||||
json_array = "{\"status\":[" + json_array + "]}";
|
||||
json_array.replace("},]}", "}]}");
|
||||
publishChart(topic, json_array);
|
||||
|
||||
}
|
||||
|
||||
void cleanLogAndData() {
|
||||
|
||||
@@ -19,6 +19,12 @@ void Output::execute(String value) {
|
||||
eventGen2(_key, value);
|
||||
jsonWriteStr(configLiveJson, _key, value);
|
||||
publishStatus(_key, value);
|
||||
String path = mqttRootDevice + "/" + _key + "/status";
|
||||
String json = "{}";
|
||||
jsonWriteStr(json, "status", value);
|
||||
String MyJson = json;
|
||||
jsonWriteStr(MyJson, "topic", path);
|
||||
ws.textAll(MyJson);
|
||||
//publishLastUpdateTime(_key, timeNow->getTime());
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,12 @@ void PwmOut::execute(String state) {
|
||||
jsonWriteInt(configStoreJson, _key, state.toInt());
|
||||
saveStore();
|
||||
publishStatus(_key, state);
|
||||
String path = mqttRootDevice + "/" + _key + "/status";
|
||||
String json = "{}";
|
||||
jsonWriteStr(json, "status", state);
|
||||
String MyJson = json;
|
||||
jsonWriteStr(MyJson, "topic", path);
|
||||
ws.textAll(MyJson);
|
||||
}
|
||||
|
||||
MyPwmOutVector* myPwmOut = nullptr;
|
||||
|
||||
@@ -45,6 +45,12 @@ void SensorAnalog::readAnalog() {
|
||||
eventGen2(_key, String(valueFloat));
|
||||
jsonWriteStr(configLiveJson, _key, String(valueFloat));
|
||||
publishStatus(_key, String(valueFloat));
|
||||
String path = mqttRootDevice + "/" + _key + "/status";
|
||||
String json = "{}";
|
||||
jsonWriteStr(json, "status", String(valueFloat));
|
||||
String MyJson = json;
|
||||
jsonWriteStr(MyJson, "topic", path);
|
||||
ws.textAll(MyJson);
|
||||
SerialPrint("I", "Sensor", "'" + _key + "' data: " + String(valueFloat));
|
||||
}
|
||||
|
||||
|
||||
@@ -48,16 +48,34 @@ void SensorBme280::read() {
|
||||
eventGen2(_paramsTmp.key, String(tmp));
|
||||
jsonWriteStr(configLiveJson, _paramsTmp.key, String(tmp));
|
||||
publishStatus(_paramsTmp.key, String(tmp));
|
||||
String path = mqttRootDevice + "/" +_paramsTmp.key + "/status";
|
||||
String json = "{}";
|
||||
jsonWriteStr(json, "status", String(tmp));
|
||||
String MyJson = json;
|
||||
jsonWriteStr(MyJson, "topic", path);
|
||||
ws.textAll(MyJson);
|
||||
SerialPrint("I", "Sensor", "'" + _paramsTmp.key + "' data: " + String(tmp));
|
||||
|
||||
eventGen2(_paramsHum.key, String(hum));
|
||||
jsonWriteStr(configLiveJson, _paramsHum.key, String(hum));
|
||||
publishStatus(_paramsHum.key, String(hum));
|
||||
path = mqttRootDevice + "/" +_paramsHum.key + "/status";
|
||||
json = "{}";
|
||||
jsonWriteStr(json, "status", String(hum));
|
||||
MyJson = json;
|
||||
jsonWriteStr(MyJson, "topic", path);
|
||||
ws.textAll(MyJson);
|
||||
SerialPrint("I", "Sensor", "'" + _paramsHum.key + "' data: " + String(hum));
|
||||
|
||||
eventGen2(_paramsPrs.key, String(prs));
|
||||
jsonWriteStr(configLiveJson, _paramsPrs.key, String(prs));
|
||||
publishStatus(_paramsPrs.key, String(prs));
|
||||
path = mqttRootDevice + "/" +_paramsPrs.key + "/status";
|
||||
json = "{}";
|
||||
jsonWriteStr(json, "status", String(prs));
|
||||
MyJson = json;
|
||||
jsonWriteStr(MyJson, "topic", path);
|
||||
ws.textAll(MyJson);
|
||||
SerialPrint("I", "Sensor", "'" + _paramsPrs.key + "' data: " + String(prs));
|
||||
}
|
||||
|
||||
|
||||
@@ -44,11 +44,23 @@ void SensorBmp280::read() {
|
||||
eventGen2(_paramsTmp.key, String(tmp));
|
||||
jsonWriteStr(configLiveJson, _paramsTmp.key, String(tmp));
|
||||
publishStatus(_paramsTmp.key, String(tmp));
|
||||
String path = mqttRootDevice + "/" +_paramsTmp.key + "/status";
|
||||
String json = "{}";
|
||||
jsonWriteStr(json, "status", String(tmp));
|
||||
String MyJson = json;
|
||||
jsonWriteStr(MyJson, "topic", path);
|
||||
ws.textAll(MyJson);
|
||||
SerialPrint("I", "Sensor", "'" + _paramsTmp.key + "' data: " + String(tmp));
|
||||
|
||||
eventGen2(_paramsPrs.key, String(prs));
|
||||
jsonWriteStr(configLiveJson, _paramsPrs.key, String(prs));
|
||||
publishStatus(_paramsPrs.key, String(prs));
|
||||
path = mqttRootDevice + "/" +_paramsPrs.key + "/status";
|
||||
json = "{}";
|
||||
jsonWriteStr(json, "status", String(prs));
|
||||
MyJson = json;
|
||||
jsonWriteStr(MyJson, "topic", path);
|
||||
ws.textAll(MyJson);
|
||||
SerialPrint("I", "Sensor", "'" + _paramsPrs.key + "' data: " + String(prs));
|
||||
}
|
||||
|
||||
|
||||
@@ -41,11 +41,23 @@ void SensorCcs811::read() {
|
||||
eventGen2(_paramsPpm.key, String(co2));
|
||||
jsonWriteStr(configLiveJson, _paramsPpm.key, String(co2));
|
||||
publishStatus(_paramsPpm.key, String(co2));
|
||||
String path = mqttRootDevice + "/" +_paramsPpm.key + "/status";
|
||||
String json = "{}";
|
||||
jsonWriteStr(json, "status", String(co2));
|
||||
String MyJson = json;
|
||||
jsonWriteStr(MyJson, "topic", path);
|
||||
ws.textAll(MyJson);
|
||||
SerialPrint("I", "Sensor", "'" + _paramsPpm.key + "' data: " + String(co2));
|
||||
|
||||
eventGen2(_paramsPpb.key, String(ppm));
|
||||
jsonWriteStr(configLiveJson, _paramsPpb.key, String(ppm));
|
||||
publishStatus(_paramsPpb.key, String(ppm));
|
||||
path = mqttRootDevice + "/" +_paramsPpb.key + "/status";
|
||||
json = "{}";
|
||||
jsonWriteStr(json, "status", String(ppm));
|
||||
MyJson = json;
|
||||
jsonWriteStr(MyJson, "topic", path);
|
||||
ws.textAll(MyJson);
|
||||
SerialPrint("I", "Sensor", "'" + _paramsPpb.key + "' data: " + String(ppm));
|
||||
} else {
|
||||
SerialPrint("E", "Sensor CCS", "Error");
|
||||
|
||||
@@ -39,6 +39,12 @@ void SensorDallas::readDallas() {
|
||||
eventGen2(_key, String(value));
|
||||
jsonWriteStr(configLiveJson, _key, String(value));
|
||||
publishStatus(_key, String(value));
|
||||
String path = mqttRootDevice + "/" +_key + "/status";
|
||||
String json = "{}";
|
||||
jsonWriteStr(json, "status", String(value));
|
||||
String MyJson = json;
|
||||
jsonWriteStr(MyJson, "topic", path);
|
||||
ws.textAll(MyJson);
|
||||
SerialPrint("I", "Sensor", "'" + _key + "' data: " + String(value));
|
||||
}
|
||||
|
||||
|
||||
@@ -44,11 +44,23 @@ void SensorDht::readTmpHum() {
|
||||
eventGen2(_paramsTmp.key, String(tmp));
|
||||
jsonWriteStr(configLiveJson, _paramsTmp.key, String(tmp));
|
||||
publishStatus(_paramsTmp.key, String(tmp));
|
||||
String path = mqttRootDevice + "/" +_paramsTmp.key + "/status";
|
||||
String json = "{}";
|
||||
jsonWriteStr(json, "status", String(tmp));
|
||||
String MyJson = json;
|
||||
jsonWriteStr(MyJson, "topic", path);
|
||||
ws.textAll(MyJson);
|
||||
SerialPrint("I", "Sensor", "'" + _paramsTmp.key + "' data: " + String(tmp));
|
||||
|
||||
eventGen2(_paramsHum.key, String(hum));
|
||||
jsonWriteStr(configLiveJson, _paramsHum.key, String(hum));
|
||||
publishStatus(_paramsHum.key, String(hum));
|
||||
path = mqttRootDevice + "/" +_paramsHum.key + "/status";
|
||||
json = "{}";
|
||||
jsonWriteStr(json, "status", String(hum));
|
||||
MyJson = json;
|
||||
jsonWriteStr(MyJson, "topic", path);
|
||||
ws.textAll(MyJson);
|
||||
SerialPrint("I", "Sensor", "'" + _paramsHum.key + "' data: " + String(hum));
|
||||
|
||||
} else {
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
//#include "items/vSensorImpulsIn.h"
|
||||
//
|
||||
//#include "BufferExecute.h"
|
||||
//#include "Class/LineParsing.h"
|
||||
//#include "Global.h"
|
||||
//#include "SoftUART.h"
|
||||
//
|
||||
//SensorImpulsIn::SensorImpulsIn(const paramsImpulsIn& paramsImpuls) {
|
||||
// _paramsImpuls = paramsImpulsIn(paramsImpuls);
|
||||
// pinMode(14, INPUT);
|
||||
// //pinMode(_paramsImpuls.pin, INPUT_PULLUP);
|
||||
// //attachInterrupt(digitalPinToInterrupt(14), MYinterrupt, CHANGE);
|
||||
//}
|
||||
//
|
||||
//SensorImpulsIn::~SensorImpulsIn() {}
|
||||
//
|
||||
////void SensorImpulsIn::read() {
|
||||
// float voltage; //= (impulsIn->values()->voltage * _paramsV.c) + _paramsV.k;
|
||||
//
|
||||
// eventGen2(_paramsImpuls.key, String(voltage));
|
||||
// jsonWriteStr(configLiveJson, _paramsImpuls.key, String(voltage));
|
||||
// publishStatus(_paramsImpuls.key, String(voltage));
|
||||
// SerialPrint("I", "Sensor", "'" + _paramsImpuls.key + "' data: " + String(voltage));
|
||||
//}
|
||||
//
|
||||
//MySensorImpulsInVector* mySensorImpulsIn = nullptr;
|
||||
//
|
||||
//void impulsInSensor() {
|
||||
// myLineParsing.update();
|
||||
// String key = myLineParsing.gkey();
|
||||
// String pin = myLineParsing.gpin();
|
||||
// String c = myLineParsing.gc();
|
||||
// String k = myLineParsing.gk();
|
||||
// myLineParsing.clear();
|
||||
//
|
||||
// static paramsImpulsIn paramsImpuls;
|
||||
//
|
||||
// paramsImpuls.key = key;
|
||||
// paramsImpuls.pin = pin.toInt();
|
||||
// paramsImpuls.c = c.toFloat();
|
||||
// paramsImpuls.k = k.toFloat();
|
||||
//
|
||||
// static bool firstTime = true;
|
||||
// if (firstTime) mySensorImpulsIn = new MySensorImpulsInVector();
|
||||
// firstTime = false;
|
||||
// mySensorImpulsIn->push_back(SensorImpulsIn(paramsImpuls));
|
||||
//}
|
||||
//
|
||||
//void MYinterrupt() {
|
||||
// Serial.println("interrupt!");
|
||||
//}
|
||||
@@ -37,6 +37,12 @@ void SensorNode::onChange(String newValue, String incommingKey) {
|
||||
eventGen2(_params.key, newValue);
|
||||
jsonWriteStr(configLiveJson, _params.key, newValue);
|
||||
publishStatus(_params.key, newValue);
|
||||
String path = mqttRootDevice + "/" +_params.key + "/status";
|
||||
String json = "{}";
|
||||
jsonWriteStr(json, "status", newValue);
|
||||
String MyJson = json;
|
||||
jsonWriteStr(MyJson, "topic", path);
|
||||
ws.textAll(MyJson);
|
||||
|
||||
_updateTime = timeNow->getDateTimeDotFormated();
|
||||
|
||||
@@ -48,17 +54,72 @@ void SensorNode::onChange(String newValue, String incommingKey) {
|
||||
void SensorNode::publish() {
|
||||
if (_minutesPassed < _params.tm1.toInt()) {
|
||||
publishAnyJsonKey(_params.key, "info", String(_minutesPassed) + " min");
|
||||
|
||||
String path = mqttRootDevice + "/" + _params.key + "/status";
|
||||
String json = "{}";
|
||||
jsonWriteStr(json, "info", String(_minutesPassed) + " min");
|
||||
String MyJson = json;
|
||||
jsonWriteStr(MyJson, "topic", path);
|
||||
ws.textAll(MyJson);
|
||||
|
||||
|
||||
publishAnyJsonKey(_params.key, "color", "");
|
||||
|
||||
|
||||
path = mqttRootDevice + "/" + _params.key + "/status";
|
||||
json = "{}";
|
||||
jsonWriteStr(json, "color", "");
|
||||
MyJson = json;
|
||||
jsonWriteStr(MyJson, "topic", path);
|
||||
ws.textAll(MyJson);
|
||||
|
||||
} else if (_minutesPassed >= _params.tm1.toInt() && _minutesPassed < _params.tm2.toInt()) {
|
||||
publishAnyJsonKey(_params.key, "info", String(_minutesPassed) + " min");
|
||||
|
||||
String path = mqttRootDevice + "/" + _params.key + "/status";
|
||||
String json = "{}";
|
||||
jsonWriteStr(json, "info", String(_minutesPassed) + " min");
|
||||
String MyJson = json;
|
||||
jsonWriteStr(MyJson, "topic", path);
|
||||
ws.textAll(MyJson);
|
||||
|
||||
publishAnyJsonKey(_params.key, "color", "orange");
|
||||
path = mqttRootDevice + "/" + _params.key + "/status";
|
||||
json = "{}";
|
||||
jsonWriteStr(json, "color", "orange");
|
||||
MyJson = json;
|
||||
jsonWriteStr(MyJson, "topic", path);
|
||||
ws.textAll(MyJson);
|
||||
|
||||
} else if (_minutesPassed >= _params.tm2.toInt()) {
|
||||
if (_updateTime == "") {
|
||||
publishAnyJsonKey(_params.key, "info", "offline");
|
||||
|
||||
|
||||
String path = mqttRootDevice + "/" + _params.key + "/status";
|
||||
String json = "{}";
|
||||
jsonWriteStr(json, "info", "offline");
|
||||
String MyJson = json;
|
||||
jsonWriteStr(MyJson, "topic", path);
|
||||
ws.textAll(MyJson);
|
||||
} else {
|
||||
publishAnyJsonKey(_params.key, "info", _updateTime);
|
||||
String path = mqttRootDevice + "/" + _params.key + "/status";
|
||||
String json = "{}";
|
||||
jsonWriteStr(json, "info", _updateTime);
|
||||
String MyJson = json;
|
||||
jsonWriteStr(MyJson, "topic", path);
|
||||
ws.textAll(MyJson);
|
||||
|
||||
|
||||
}
|
||||
publishAnyJsonKey(_params.key, "color", "red");
|
||||
String path = mqttRootDevice + "/" + _params.key + "/status";
|
||||
String json = "{}";
|
||||
jsonWriteStr(json, "color", "red");
|
||||
String MyJson = json;
|
||||
jsonWriteStr(MyJson, "topic", path);
|
||||
ws.textAll(MyJson);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -38,26 +38,56 @@ void SensorPzem::read() {
|
||||
eventGen2(_paramsV.key, String(voltage));
|
||||
jsonWriteStr(configLiveJson, _paramsV.key, String(voltage));
|
||||
publishStatus(_paramsV.key, String(voltage));
|
||||
String path = mqttRootDevice + "/" +_paramsV.key + "/status";
|
||||
String json = "{}";
|
||||
jsonWriteStr(json, "status", String(voltage));
|
||||
String MyJson = json;
|
||||
jsonWriteStr(MyJson, "topic", path);
|
||||
ws.textAll(MyJson);
|
||||
SerialPrint("I", "Sensor", "'" + _paramsV.key + "' data: " + String(voltage));
|
||||
|
||||
eventGen2(_paramsA.key, String(current));
|
||||
jsonWriteStr(configLiveJson, _paramsA.key, String(current));
|
||||
publishStatus(_paramsA.key, String(current));
|
||||
path = mqttRootDevice + "/" +_paramsA.key + "/status";
|
||||
json = "{}";
|
||||
jsonWriteStr(json, "status", String(current));
|
||||
MyJson = json;
|
||||
jsonWriteStr(MyJson, "topic", path);
|
||||
ws.textAll(MyJson);
|
||||
SerialPrint("I", "Sensor", "'" + _paramsA.key + "' data: " + String(current));
|
||||
|
||||
eventGen2(_paramsWatt.key, String(power));
|
||||
jsonWriteStr(configLiveJson, _paramsWatt.key, String(power));
|
||||
publishStatus(_paramsWatt.key, String(power));
|
||||
path = mqttRootDevice + "/" +_paramsWatt.key + "/status";
|
||||
json = "{}";
|
||||
jsonWriteStr(json, "status", String(power));
|
||||
MyJson = json;
|
||||
jsonWriteStr(MyJson, "topic", path);
|
||||
ws.textAll(MyJson);
|
||||
SerialPrint("I", "Sensor", "'" + _paramsWatt.key + "' data: " + String(power));
|
||||
|
||||
eventGen2(_paramsWattHrs.key, String(energy));
|
||||
jsonWriteStr(configLiveJson, _paramsWattHrs.key, String(energy));
|
||||
publishStatus(_paramsWattHrs.key, String(energy));
|
||||
path = mqttRootDevice + "/" +_paramsWattHrs.key + "/status";
|
||||
json = "{}";
|
||||
jsonWriteStr(json, "status", String(energy));
|
||||
MyJson = json;
|
||||
jsonWriteStr(MyJson, "topic", path);
|
||||
ws.textAll(MyJson);
|
||||
SerialPrint("I", "Sensor", "'" + _paramsWattHrs.key + "' data: " + String(energy));
|
||||
|
||||
eventGen2(_paramsHz.key, String(freq));
|
||||
jsonWriteStr(configLiveJson, _paramsHz.key, String(freq));
|
||||
publishStatus(_paramsHz.key, String(freq));
|
||||
path = mqttRootDevice + "/" +_paramsHz.key + "/status";
|
||||
json = "{}";
|
||||
jsonWriteStr(json, "status", String(freq));
|
||||
MyJson = json;
|
||||
jsonWriteStr(MyJson, "topic", path);
|
||||
ws.textAll(MyJson);
|
||||
SerialPrint("I", "Sensor", "'" + _paramsHz.key + "' data: " + String(freq));
|
||||
} else {
|
||||
SerialPrint("E", "Sensor PZEM", "Error, UART switched off");
|
||||
|
||||
@@ -49,11 +49,24 @@ void SensorSht20::read() {
|
||||
eventGen2(_paramsTmp.key, String(tmp));
|
||||
jsonWriteStr(configLiveJson, _paramsTmp.key, String(tmp));
|
||||
publishStatus(_paramsTmp.key, String(tmp));
|
||||
String path = mqttRootDevice + "/" +_paramsTmp.key + "/status";
|
||||
String json = "{}";
|
||||
jsonWriteStr(json, "status", String(tmp));
|
||||
String MyJson = json;
|
||||
jsonWriteStr(MyJson, "topic", path);
|
||||
ws.textAll(MyJson);
|
||||
|
||||
SerialPrint("I", "Sensor", "'" + _paramsTmp.key + "' data: " + String(tmp));
|
||||
|
||||
eventGen2(_paramsHum.key, String(hum));
|
||||
jsonWriteStr(configLiveJson, _paramsHum.key, String(hum));
|
||||
publishStatus(_paramsHum.key, String(hum));
|
||||
path = mqttRootDevice + "/" +_paramsHum.key + "/status";
|
||||
json = "{}";
|
||||
jsonWriteStr(json, "status", String(hum));
|
||||
MyJson = json;
|
||||
jsonWriteStr(MyJson, "topic", path);
|
||||
ws.textAll(MyJson);
|
||||
SerialPrint("I", "Sensor", "'" + _paramsHum.key + "' data: " + String(hum));
|
||||
}
|
||||
|
||||
|
||||
@@ -53,20 +53,22 @@ void SensorUltrasonic::readUltrasonic() {
|
||||
value = duration_ / 29 / 2;
|
||||
|
||||
value = testFilter.filtered(value);
|
||||
|
||||
value = map(value, _map1, _map2, _map3, _map4);
|
||||
float valueFloat = value * _c;
|
||||
|
||||
if (counter > 10) {
|
||||
eventGen2(_key, String(valueFloat));
|
||||
jsonWriteStr(configLiveJson, _key, String(valueFloat));
|
||||
publishStatus(_key, String(valueFloat));
|
||||
String path = mqttRootDevice + "/" +_key + "/status";
|
||||
String json = "{}";
|
||||
jsonWriteStr(json, "status", String(valueFloat));
|
||||
String MyJson = json;
|
||||
jsonWriteStr(MyJson, "topic", path);
|
||||
ws.textAll(MyJson);
|
||||
SerialPrint("I", "Sensor", "'" + _key + "' data: " + String(valueFloat));
|
||||
}
|
||||
}
|
||||
|
||||
MySensorUltrasonicVector* mySensorUltrasonic = nullptr;
|
||||
|
||||
void ultrasonic() {
|
||||
myLineParsing.update();
|
||||
String interval = myLineParsing.gint();
|
||||
@@ -75,15 +77,12 @@ void ultrasonic() {
|
||||
String map = myLineParsing.gmap();
|
||||
String c = myLineParsing.gc();
|
||||
myLineParsing.clear();
|
||||
|
||||
unsigned int trig = selectFromMarkerToMarker(pin, ",", 0).toInt();
|
||||
unsigned int echo = selectFromMarkerToMarker(pin, ",", 1).toInt();
|
||||
|
||||
int map1 = selectFromMarkerToMarker(map, ",", 0).toInt();
|
||||
int map2 = selectFromMarkerToMarker(map, ",", 1).toInt();
|
||||
int map3 = selectFromMarkerToMarker(map, ",", 2).toInt();
|
||||
int map4 = selectFromMarkerToMarker(map, ",", 3).toInt();
|
||||
|
||||
static bool firstTime = true;
|
||||
if (firstTime) mySensorUltrasonic = new MySensorUltrasonicVector();
|
||||
firstTime = false;
|
||||
|
||||
@@ -28,6 +28,12 @@ void SensorUptime::read() {
|
||||
eventGen2(_paramsUpt.key, upt);
|
||||
jsonWriteStr(configLiveJson, _paramsUpt.key, upt);
|
||||
publishStatus(_paramsUpt.key, upt);
|
||||
String path = mqttRootDevice + "/" +_paramsUpt.key + "/status";
|
||||
String json = "{}";
|
||||
jsonWriteStr(json, "status", upt);
|
||||
String MyJson = json;
|
||||
jsonWriteStr(MyJson, "topic", path);
|
||||
ws.textAll(MyJson);
|
||||
SerialPrint("I", "Sensor", "'" + _paramsUpt.key + "' data: " + upt);
|
||||
}
|
||||
|
||||
@@ -38,12 +44,9 @@ void uptimeSensor() {
|
||||
String key = myLineParsing.gkey();
|
||||
String interval = myLineParsing.gint();
|
||||
myLineParsing.clear();
|
||||
|
||||
static paramsUptime paramsUpt;
|
||||
|
||||
paramsUpt.key = key;
|
||||
paramsUpt.interval = interval.toInt() * 1000;
|
||||
|
||||
static bool firstTime = true;
|
||||
if (firstTime) mySensorUptime = new MySensorUptimeVector();
|
||||
firstTime = false;
|
||||
|
||||
13
src/main.cpp
13
src/main.cpp
@@ -35,11 +35,12 @@
|
||||
#include "items/vSensorUltrasonic.h"
|
||||
#include "items/vSensorUptime.h"
|
||||
|
||||
//#include "WebServer.h"
|
||||
void not_async_actions();
|
||||
|
||||
Timings metric;
|
||||
boolean initialized = false;
|
||||
|
||||
extern int flagq ;
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
Serial.flush();
|
||||
@@ -94,8 +95,14 @@ void loop() {
|
||||
#ifdef OTA_UPDATES_ENABLED
|
||||
ArduinoOTA.handle();
|
||||
#endif
|
||||
#ifdef WS_enable
|
||||
ws.cleanupClients();
|
||||
#ifdef WEBSOCKET_ENABLED
|
||||
|
||||
ws.cleanupClients();
|
||||
if ( flagq == 1){
|
||||
SerialPrint("I", "WS ", "choose_log_date_and_send()");
|
||||
choose_log_date_and_sendWS();
|
||||
flagq = 0;
|
||||
}
|
||||
#endif
|
||||
timeNow->loop();
|
||||
mqttLoop();
|
||||
|
||||
Reference in New Issue
Block a user