mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-30 20:09:14 +03:00
Выводим данные mysensors на dashboard!!!
This commit is contained in:
@@ -616,19 +616,27 @@
|
|||||||
"name": "42. MySensorsGate",
|
"name": "42. MySensorsGate",
|
||||||
"type": "Reading",
|
"type": "Reading",
|
||||||
"subtype": "MySensorsGate",
|
"subtype": "MySensorsGate",
|
||||||
"id": "t",
|
"id": "gt",
|
||||||
"widget": "anydataTmp",
|
"widget": "nil",
|
||||||
"page": "Сенсоры",
|
"page": "",
|
||||||
"descr": "Температура",
|
"descr": "",
|
||||||
"map": "1,1024,1,100",
|
|
||||||
"plus": 0,
|
|
||||||
"multiply": 1,
|
|
||||||
"round": 1,
|
|
||||||
"num": 42
|
"num": 42
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"global": 0,
|
"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",
|
"type": "Reading",
|
||||||
"subtype": "Pcf8574",
|
"subtype": "Pcf8574",
|
||||||
"id": "Pcf",
|
"id": "Pcf",
|
||||||
@@ -638,11 +646,11 @@
|
|||||||
"int": "0",
|
"int": "0",
|
||||||
"addr": "0x20",
|
"addr": "0x20",
|
||||||
"index": 1,
|
"index": 1,
|
||||||
"num": 43
|
"num": 44
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"global": 0,
|
"global": 0,
|
||||||
"name": "44. PWM ESP32",
|
"name": "45. PWM ESP32",
|
||||||
"type": "Writing",
|
"type": "Writing",
|
||||||
"subtype": "Pwm32",
|
"subtype": "Pwm32",
|
||||||
"id": "pwm",
|
"id": "pwm",
|
||||||
@@ -656,11 +664,11 @@
|
|||||||
"PWM_resolution": 10,
|
"PWM_resolution": 10,
|
||||||
"val": 0,
|
"val": 0,
|
||||||
"apin": -1,
|
"apin": -1,
|
||||||
"num": 44
|
"num": 45
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"global": 0,
|
"global": 0,
|
||||||
"name": "45. Телеграм-Лайт",
|
"name": "46. Телеграм-Лайт",
|
||||||
"type": "Writing",
|
"type": "Writing",
|
||||||
"subtype": "TelegramLT",
|
"subtype": "TelegramLT",
|
||||||
"id": "tg",
|
"id": "tg",
|
||||||
@@ -669,14 +677,14 @@
|
|||||||
"descr": "",
|
"descr": "",
|
||||||
"token": "",
|
"token": "",
|
||||||
"chatID": "",
|
"chatID": "",
|
||||||
"num": 45
|
"num": 46
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"header": "Экраны"
|
"header": "Экраны"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"global": 0,
|
"global": 0,
|
||||||
"name": "46. LCD экран 2004",
|
"name": "47. LCD экран 2004",
|
||||||
"type": "Reading",
|
"type": "Reading",
|
||||||
"subtype": "Lcd2004",
|
"subtype": "Lcd2004",
|
||||||
"id": "Lcd",
|
"id": "Lcd",
|
||||||
@@ -688,10 +696,10 @@
|
|||||||
"size": "20,4",
|
"size": "20,4",
|
||||||
"coord": "0,0",
|
"coord": "0,0",
|
||||||
"id2show": "id датчика",
|
"id2show": "id датчика",
|
||||||
"num": 46
|
"num": 47
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "47. LCD экран 1602",
|
"name": "48. LCD экран 1602",
|
||||||
"type": "Reading",
|
"type": "Reading",
|
||||||
"subtype": "Lcd2004",
|
"subtype": "Lcd2004",
|
||||||
"id": "Lcd",
|
"id": "Lcd",
|
||||||
@@ -703,6 +711,6 @@
|
|||||||
"size": "16,2",
|
"size": "16,2",
|
||||||
"coord": "0,0",
|
"coord": "0,0",
|
||||||
"id2show": "id датчика",
|
"id2show": "id датчика",
|
||||||
"num": 47
|
"num": 48
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
//Версия прошивки
|
//Версия прошивки
|
||||||
#define FIRMWARE_VERSION 433
|
#define FIRMWARE_VERSION 434
|
||||||
|
|
||||||
#ifdef esp8266_1mb_ota
|
#ifdef esp8266_1mb_ota
|
||||||
#define FIRMWARE_NAME "esp8266_1mb_ota"
|
#define FIRMWARE_NAME "esp8266_1mb_ota"
|
||||||
|
|||||||
@@ -113,6 +113,8 @@ build_src_filter =
|
|||||||
${env:esp8266_4mb_fromitems.build_src_filter}
|
${env:esp8266_4mb_fromitems.build_src_filter}
|
||||||
|
|
||||||
[env:esp32_4mb]
|
[env:esp32_4mb]
|
||||||
|
upload_port = COM8
|
||||||
|
monitor_port = COM8
|
||||||
lib_deps =
|
lib_deps =
|
||||||
${common_env_data.lib_deps_external}
|
${common_env_data.lib_deps_external}
|
||||||
${env:esp32_4mb_fromitems.lib_deps}
|
${env:esp32_4mb_fromitems.lib_deps}
|
||||||
|
|||||||
@@ -50,12 +50,8 @@ String parseToString(const MyMessage& message) {
|
|||||||
|
|
||||||
class MySensorsGate : public IoTItem {
|
class MySensorsGate : public IoTItem {
|
||||||
private:
|
private:
|
||||||
int _pin;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MySensorsGate(String parameters) : IoTItem(parameters) {
|
MySensorsGate(String parameters) : IoTItem(parameters) {
|
||||||
jsonRead(parameters, "pin", _pin);
|
|
||||||
// init place
|
|
||||||
SerialPrint("i", "MySensors", "Gate initialized");
|
SerialPrint("i", "MySensors", "Gate initialized");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,12 +62,6 @@ class MySensorsGate : public IoTItem {
|
|||||||
loopMySensorsExecute();
|
loopMySensorsExecute();
|
||||||
}
|
}
|
||||||
|
|
||||||
void setValue(const IoTValue& Value, bool genEvent = true) {
|
|
||||||
value = Value;
|
|
||||||
// set value place
|
|
||||||
regEvent(value.valD, "MySensorsGate", false, genEvent);
|
|
||||||
}
|
|
||||||
|
|
||||||
~MySensorsGate(){};
|
~MySensorsGate(){};
|
||||||
|
|
||||||
void loopMySensorsExecute() {
|
void loopMySensorsExecute() {
|
||||||
@@ -92,16 +82,10 @@ class MySensorsGate : public IoTItem {
|
|||||||
if (childSensorId == "255") {
|
if (childSensorId == "255") {
|
||||||
if (command == "3") { //это особое внутреннее сообщение
|
if (command == "3") { //это особое внутреннее сообщение
|
||||||
if (type == "11") { //название ноды
|
if (type == "11") { //название ноды
|
||||||
SerialPrint("i", "MySensors", "Node name: " + value);
|
SerialPrint("i", "MySensors", "===================== " + value + " =====================");
|
||||||
//*
|
|
||||||
// publishAnyJsonKey("MySensors", "Node name:", value);
|
|
||||||
// publishAnyJsonKeyWS("MySensors", "Node name:", value);
|
|
||||||
}
|
}
|
||||||
if (type == "12") { //версия ноды
|
if (type == "12") { //версия ноды
|
||||||
SerialPrint("i", "MySensors", "Node version: " + value);
|
SerialPrint("i", "MySensors", "Node version: " + value);
|
||||||
//*
|
|
||||||
// publishAnyJsonKey("MySensors", "Node version: ", value);
|
|
||||||
// publishAnyJsonKeyWS("MySensors", "Node version: ", value);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -111,48 +95,29 @@ class MySensorsGate : public IoTItem {
|
|||||||
String widget;
|
String widget;
|
||||||
String descr;
|
String descr;
|
||||||
sensorType(type.toInt(), num, widget, 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("#", " ");
|
descr.replace("#", " ");
|
||||||
SerialPrint("i", "MySensors", "Presentation: " + key + ": " + descr);
|
SerialPrint("i", "MySensors", "Presentation: " + key + ": " + descr);
|
||||||
|
|
||||||
//*
|
|
||||||
// publishAnyJsonKey("MySensors", key, descr);
|
|
||||||
// publishAnyJsonKeyWS("MySensors", key, descr);
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
if (command == "1") { //это данные
|
if (command == "1") { //это данные
|
||||||
if (value != "") {
|
if (value != "") {
|
||||||
if (presentBeenStarted) {
|
if (presentBeenStarted) {
|
||||||
presentBeenStarted = false;
|
presentBeenStarted = false;
|
||||||
SerialPrint("i", "MySensors", "!!!Presentation of node: " + nodeId + " completed successfully!!!");
|
SerialPrint("i", "MySensors", "===================== " + nodeId + " =====================");
|
||||||
// myNotAsyncActions->make(do_deviceInit);
|
|
||||||
}
|
}
|
||||||
// if (mySensorNode != nullptr) {
|
|
||||||
// for (unsigned int i = 0; i < mySensorNode->size(); i++) {
|
String incommingID = nodeId + "-" + childSensorId;
|
||||||
// mySensorNode->at(i).onChange(value, key); //вызываем поочередно все экземпляры, там где подойдет там и выполнится
|
|
||||||
// //*
|
bool found = false;
|
||||||
// publishAnyJsonKey("MySensors", key, value);
|
|
||||||
// publishAnyJsonKeyWS("MySensors", key, value);
|
for (std::list<IoTItem*>::iterator it = IoTItems.begin(); it != IoTItems.end(); ++it) {
|
||||||
// }
|
if ((*it)->getID() == incommingID) {
|
||||||
// }
|
found = true;
|
||||||
SerialPrint("i", "MySensors", "node: " + nodeId + ", sensor: " + childSensorId + ", command: " + command + ", type: " + type + ", val: " + value);
|
(*it)->setValue(value, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SerialPrint("i", "MySensors", "node: " + nodeId + ", sensor: " + childSensorId + ", command: " + command + ", type: " + type + ", val: " + value + ", found: " + String(found));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (command == "2") { //это запрос значения переменной
|
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) {
|
void* getAPI_MySensorsGate(String subtype, String param) {
|
||||||
if (subtype == F("MySensorsGate")) {
|
if (subtype == F("MySensorsGate")) {
|
||||||
return new MySensorsGate(param);
|
return new MySensorsGate(param);
|
||||||
|
} else if (subtype == F("MySensorsNode")) {
|
||||||
|
return new MySensorsNode(param);
|
||||||
} else {
|
} else {
|
||||||
return nullptr;
|
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);
|
|
||||||
// }
|
|
||||||
@@ -28,7 +28,7 @@
|
|||||||
// в файле MyGatewayTransportSerial.cpp в строчке 35
|
// в файле MyGatewayTransportSerial.cpp в строчке 35
|
||||||
#define MY_GATEWAY_SERIAL
|
#define MY_GATEWAY_SERIAL
|
||||||
|
|
||||||
#define CHILD_ID 1
|
//#define CHILD_ID 1
|
||||||
|
|
||||||
#include <MySensors.h>
|
#include <MySensors.h>
|
||||||
|
|
||||||
|
|||||||
@@ -6,13 +6,20 @@
|
|||||||
"name": "MySensorsGate",
|
"name": "MySensorsGate",
|
||||||
"type": "Reading",
|
"type": "Reading",
|
||||||
"subtype": "MySensorsGate",
|
"subtype": "MySensorsGate",
|
||||||
"id": "t",
|
"id": "gt",
|
||||||
|
"widget": "nil",
|
||||||
|
"page": "",
|
||||||
|
"descr": ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"global": 0,
|
||||||
|
"name": "MySensorsNode",
|
||||||
|
"type": "Reading",
|
||||||
|
"subtype": "MySensorsNode",
|
||||||
|
"id": "nd",
|
||||||
"widget": "anydataTmp",
|
"widget": "anydataTmp",
|
||||||
"page": "Сенсоры",
|
"page": "MySensors",
|
||||||
"descr": "Температура",
|
"descr": "Температура",
|
||||||
"map": "1,1024,1,100",
|
|
||||||
"plus": 0,
|
|
||||||
"multiply": 1,
|
|
||||||
"round": 1
|
"round": 1
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|||||||
Reference in New Issue
Block a user