From 3285a70a88844f27fa6d9e318e78c1522383e1d5 Mon Sep 17 00:00:00 2001 From: Dmitry Borisenko <67171972+IoTManagerProject@users.noreply.github.com> Date: Sat, 3 Dec 2022 00:58:42 +0100 Subject: [PATCH] =?UTF-8?q?=D0=92=D1=8B=D0=B2=D0=BE=D0=B4=D0=B8=D0=BC=20?= =?UTF-8?q?=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D0=B5=20mysensors=20=D0=BD=D0=B0?= =?UTF-8?q?=20dashboard!!!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data_svelte/items.json | 44 ++++---- include/Const.h | 2 +- platformio.ini | 2 + src/modules/exec/MySensors/MySensorsGate.cpp | 103 +++++++------------ src/modules/exec/MySensors/MySensorsGate.h | 2 +- src/modules/exec/MySensors/modinfo.json | 17 ++- 6 files changed, 81 insertions(+), 89 deletions(-) diff --git a/data_svelte/items.json b/data_svelte/items.json index 1aa24c3d..40047ca5 100644 --- a/data_svelte/items.json +++ b/data_svelte/items.json @@ -616,19 +616,27 @@ "name": "42. MySensorsGate", "type": "Reading", "subtype": "MySensorsGate", - "id": "t", - "widget": "anydataTmp", - "page": "Сенсоры", - "descr": "Температура", - "map": "1,1024,1,100", - "plus": 0, - "multiply": 1, - "round": 1, + "id": "gt", + "widget": "nil", + "page": "", + "descr": "", "num": 42 }, { "global": 0, - "name": "43. Расширитель портов Pcf8574", + "name": "43. MySensorsNode", + "type": "Reading", + "subtype": "MySensorsNode", + "id": "nd", + "widget": "anydataTmp", + "page": "MySensors", + "descr": "Температура", + "round": 1, + "num": 43 + }, + { + "global": 0, + "name": "44. Расширитель портов Pcf8574", "type": "Reading", "subtype": "Pcf8574", "id": "Pcf", @@ -638,11 +646,11 @@ "int": "0", "addr": "0x20", "index": 1, - "num": 43 + "num": 44 }, { "global": 0, - "name": "44. PWM ESP32", + "name": "45. PWM ESP32", "type": "Writing", "subtype": "Pwm32", "id": "pwm", @@ -656,11 +664,11 @@ "PWM_resolution": 10, "val": 0, "apin": -1, - "num": 44 + "num": 45 }, { "global": 0, - "name": "45. Телеграм-Лайт", + "name": "46. Телеграм-Лайт", "type": "Writing", "subtype": "TelegramLT", "id": "tg", @@ -669,14 +677,14 @@ "descr": "", "token": "", "chatID": "", - "num": 45 + "num": 46 }, { "header": "Экраны" }, { "global": 0, - "name": "46. LCD экран 2004", + "name": "47. LCD экран 2004", "type": "Reading", "subtype": "Lcd2004", "id": "Lcd", @@ -688,10 +696,10 @@ "size": "20,4", "coord": "0,0", "id2show": "id датчика", - "num": 46 + "num": 47 }, { - "name": "47. LCD экран 1602", + "name": "48. LCD экран 1602", "type": "Reading", "subtype": "Lcd2004", "id": "Lcd", @@ -703,6 +711,6 @@ "size": "16,2", "coord": "0,0", "id2show": "id датчика", - "num": 47 + "num": 48 } ] \ No newline at end of file diff --git a/include/Const.h b/include/Const.h index 37d7d7d3..9e571944 100644 --- a/include/Const.h +++ b/include/Const.h @@ -1,7 +1,7 @@ #pragma once //Версия прошивки -#define FIRMWARE_VERSION 433 +#define FIRMWARE_VERSION 434 #ifdef esp8266_1mb_ota #define FIRMWARE_NAME "esp8266_1mb_ota" diff --git a/platformio.ini b/platformio.ini index e5806c94..4f7be49f 100644 --- a/platformio.ini +++ b/platformio.ini @@ -113,6 +113,8 @@ build_src_filter = ${env:esp8266_4mb_fromitems.build_src_filter} [env:esp32_4mb] +upload_port = COM8 +monitor_port = COM8 lib_deps = ${common_env_data.lib_deps_external} ${env:esp32_4mb_fromitems.lib_deps} diff --git a/src/modules/exec/MySensors/MySensorsGate.cpp b/src/modules/exec/MySensors/MySensorsGate.cpp index d6be44d1..14176adc 100644 --- a/src/modules/exec/MySensors/MySensorsGate.cpp +++ b/src/modules/exec/MySensors/MySensorsGate.cpp @@ -50,12 +50,8 @@ String parseToString(const MyMessage& message) { class MySensorsGate : public IoTItem { private: - int _pin; - public: MySensorsGate(String parameters) : IoTItem(parameters) { - jsonRead(parameters, "pin", _pin); - // init place SerialPrint("i", "MySensors", "Gate initialized"); } @@ -66,12 +62,6 @@ class MySensorsGate : public IoTItem { loopMySensorsExecute(); } - void setValue(const IoTValue& Value, bool genEvent = true) { - value = Value; - // set value place - regEvent(value.valD, "MySensorsGate", false, genEvent); - } - ~MySensorsGate(){}; void loopMySensorsExecute() { @@ -92,16 +82,10 @@ class MySensorsGate : public IoTItem { if (childSensorId == "255") { if (command == "3") { //это особое внутреннее сообщение if (type == "11") { //название ноды - SerialPrint("i", "MySensors", "Node name: " + value); - //* - // publishAnyJsonKey("MySensors", "Node name:", value); - // publishAnyJsonKeyWS("MySensors", "Node name:", value); + SerialPrint("i", "MySensors", "===================== " + value + " ====================="); } if (type == "12") { //версия ноды SerialPrint("i", "MySensors", "Node version: " + value); - //* - // publishAnyJsonKey("MySensors", "Node version: ", value); - // publishAnyJsonKeyWS("MySensors", "Node version: ", value); } } } else { @@ -111,48 +95,29 @@ class MySensorsGate : public IoTItem { String widget; String descr; sensorType(type.toInt(), num, widget, descr); - // if (jsonReadBool(settingsFlashJson, "gateAuto")) { - // if (!isItemAdded(key)) { - // addItemAuto(num, key, widget, descr); - // descr.replace("#", " "); - // SerialPrint("i", "MySensors", "Add new item: " + key + ": " + descr); - // //* - // //publishAnyJsonKey("MySensors", key, descr); - // //publishAnyJsonKeyWS("MySensors", key, descr); - // - // } else { - // descr.replace("#", " "); - // SerialPrint("i", "MySensors", "Item already exist: " + key + ": " + descr); - // - // //* - // //publishAnyJsonKey("MySensors", key, descr); - // //publishAnyJsonKeyWS("MySensors", key, descr); - // } - //} else { + descr.replace("#", " "); SerialPrint("i", "MySensors", "Presentation: " + key + ": " + descr); - - //* - // publishAnyJsonKey("MySensors", key, descr); - // publishAnyJsonKeyWS("MySensors", key, descr); - //} } if (command == "1") { //это данные if (value != "") { if (presentBeenStarted) { presentBeenStarted = false; - SerialPrint("i", "MySensors", "!!!Presentation of node: " + nodeId + " completed successfully!!!"); - // myNotAsyncActions->make(do_deviceInit); + SerialPrint("i", "MySensors", "===================== " + nodeId + " ====================="); } - // 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", "MySensors", "node: " + nodeId + ", sensor: " + childSensorId + ", command: " + command + ", type: " + type + ", val: " + value); + + String incommingID = nodeId + "-" + childSensorId; + + bool found = false; + + for (std::list::iterator it = IoTItems.begin(); it != IoTItems.end(); ++it) { + if ((*it)->getID() == incommingID) { + found = true; + (*it)->setValue(value, true); + } + } + + SerialPrint("i", "MySensors", "node: " + nodeId + ", sensor: " + childSensorId + ", command: " + command + ", type: " + type + ", val: " + value + ", found: " + String(found)); } } if (command == "2") { //это запрос значения переменной @@ -377,23 +342,33 @@ class MySensorsGate : public IoTItem { } }; +class MySensorsNode : public IoTItem { + private: + public: + MySensorsNode(String parameters) : IoTItem(parameters) { + SerialPrint("i", "MySensors", "Node initialized"); + } + + void setValue(const IoTValue& Value, bool genEvent = true) { + value = Value; + regEvent(value.valD, "MySensorsNode", false, genEvent); + } + + void doByInterval() { + } + + void loop() { + } + + ~MySensorsNode(){}; +}; + void* getAPI_MySensorsGate(String subtype, String param) { if (subtype == F("MySensorsGate")) { return new MySensorsGate(param); + } else if (subtype == F("MySensorsNode")) { + return new MySensorsNode(param); } else { return nullptr; } } - -//для того что бы выключить оригинальный лог нужно перейти в файл библиотеки 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); -// } \ No newline at end of file diff --git a/src/modules/exec/MySensors/MySensorsGate.h b/src/modules/exec/MySensors/MySensorsGate.h index 8c1a2ae2..969f8343 100644 --- a/src/modules/exec/MySensors/MySensorsGate.h +++ b/src/modules/exec/MySensors/MySensorsGate.h @@ -28,7 +28,7 @@ // в файле MyGatewayTransportSerial.cpp в строчке 35 #define MY_GATEWAY_SERIAL -#define CHILD_ID 1 +//#define CHILD_ID 1 #include diff --git a/src/modules/exec/MySensors/modinfo.json b/src/modules/exec/MySensors/modinfo.json index 63b8c4bc..c89384af 100644 --- a/src/modules/exec/MySensors/modinfo.json +++ b/src/modules/exec/MySensors/modinfo.json @@ -6,13 +6,20 @@ "name": "MySensorsGate", "type": "Reading", "subtype": "MySensorsGate", - "id": "t", + "id": "gt", + "widget": "nil", + "page": "", + "descr": "" + }, + { + "global": 0, + "name": "MySensorsNode", + "type": "Reading", + "subtype": "MySensorsNode", + "id": "nd", "widget": "anydataTmp", - "page": "Сенсоры", + "page": "MySensors", "descr": "Температура", - "map": "1,1024,1,100", - "plus": 0, - "multiply": 1, "round": 1 } ],