добавление лимитов на цвет ноды

This commit is contained in:
Dmitry Borisenko
2022-12-06 16:22:31 +01:00
parent afb7ce9951
commit e53bbcc7d8
4 changed files with 24 additions and 12 deletions

View File

@@ -627,10 +627,13 @@
"name": "43. MySensorsNode",
"type": "Reading",
"subtype": "MySensorsNode",
"id": "nd",
"id": "n",
"widget": "anydataTmp",
"page": "MySensors",
"descr": "Температура",
"orange": 60,
"red": 120,
"offline": 180,
"round": 1,
"num": 43
},

View File

@@ -113,8 +113,6 @@ build_src_filter =
${env:esp8266_4mb_fromitems.build_src_filter}
[env:esp32_4mb]
;upload_port = COM13
;monitor_port = COM13
lib_deps =
${common_env_data.lib_deps_external}
${env:esp32_4mb_fromitems.lib_deps}

View File

@@ -345,6 +345,9 @@ class MySensorsGate : public IoTItem {
class MySensorsNode : public IoTItem {
private:
String id;
int orange;
int red;
int offline;
int _minutesPassed = 0;
String json = "{}";
bool dataFromNode = false;
@@ -353,6 +356,9 @@ class MySensorsNode : public IoTItem {
MySensorsNode(String parameters) : IoTItem(parameters) {
SerialPrint("i", "MySensors", "Node initialized");
jsonRead(parameters, F("id"), id);
orange = jsonReadInt(parameters, F("orange"));
red = jsonReadInt(parameters, F("red"));
offline = jsonReadInt(parameters, F("offline"));
dataFromNode = false;
}
@@ -386,16 +392,18 @@ class MySensorsNode : public IoTItem {
void setNewWidgetAttributes() {
if (dataFromNode) {
jsonWriteStr(json, "info", String(_minutesPassed) + " min");
if (_minutesPassed < 60) {
jsonWriteStr(json, "color", "");
} else if (_minutesPassed >= 60) {
jsonWriteStr(json, "color", "orange"); //сделаем виджет оранжевым когда более 60 минут нода не выходила на связь
} else if (_minutesPassed >= 120) {
jsonWriteStr(json, "color", "red"); //сделаем виджет красным когда более 120 минут нода не выходила на связь
jsonWriteStr(json, F("info"), String(_minutesPassed) + " min");
if (_minutesPassed < orange) {
jsonWriteStr(json, F("color"), "");
} else if (_minutesPassed >= orange) {
jsonWriteStr(json, F("color"), F("orange")); //сделаем виджет оранжевым
} else if (_minutesPassed >= red) {
jsonWriteStr(json, F("color"), F("red")); //сделаем виджет красным
} else if (_minutesPassed >= offline) {
jsonWriteStr(json, F("info"), F("offline"));
}
} else {
jsonWriteStr(json, "info", "awaiting");
jsonWriteStr(json, F("info"), F("awaiting"));
}
sendSubWidgetsValues(id, json);
}

View File

@@ -16,10 +16,13 @@
"name": "MySensorsNode",
"type": "Reading",
"subtype": "MySensorsNode",
"id": "nd",
"id": "n",
"widget": "anydataTmp",
"page": "MySensors",
"descr": "Температура",
"orange": 60,
"red": 120,
"offline": 180,
"round": 1
}
],