mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-27 06:32:19 +03:00
добавление mysensors в процессе не рабочая версия
This commit is contained in:
@@ -24,8 +24,9 @@ void* getAPI_IoTServo(String subtype, String params);
|
||||
void* getAPI_Mcp23017(String subtype, String params);
|
||||
void* getAPI_Mp3(String subtype, String params);
|
||||
void* getAPI_Multitouch(String subtype, String params);
|
||||
void* getAPI_MySensorsGate(String subtype, String params);
|
||||
void* getAPI_Pcf8574(String subtype, String params);
|
||||
void* getAPI_Pwm8266(String subtype, String params);
|
||||
void* getAPI_Pwm32(String subtype, String params);
|
||||
void* getAPI_TelegramLT(String subtype, String params);
|
||||
void* getAPI_Lcd2004(String subtype, String params);
|
||||
|
||||
@@ -55,8 +56,9 @@ if ((tmpAPI = getAPI_IoTServo(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_Mcp23017(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_Mp3(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_Multitouch(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_MySensorsGate(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_Pcf8574(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_Pwm8266(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_Pwm32(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_TelegramLT(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_Lcd2004(subtype, params)) != nullptr) return tmpAPI;
|
||||
return nullptr;
|
||||
|
||||
52
src/modules/exec/MySensors/MySensorsData.cpp
Normal file
52
src/modules/exec/MySensors/MySensorsData.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
#include "Global.h"
|
||||
#include "classes/IoTItem.h"
|
||||
#include "Arduino.h"
|
||||
#include "MySensorsData.h"
|
||||
|
||||
#ifdef MYSENSORS
|
||||
|
||||
void receive(const MyMessage& message) {
|
||||
String inMsg = String(message.getSender()) + "," + // node-id
|
||||
String(message.getSensor()) + "," + // child-sensor-id
|
||||
String(message.getType()) + "," + // type of var
|
||||
String(message.getCommand()) + "," + // command
|
||||
parseToString(message) + ";"; // value
|
||||
|
||||
SerialPrint("i", F("MySensorsGate"), inMsg);
|
||||
|
||||
mysensorBuf += inMsg;
|
||||
}
|
||||
|
||||
String parseToString(const MyMessage& message) {
|
||||
String value = "error";
|
||||
switch (message.getPayloadType()) {
|
||||
case 0: // Payload type is string
|
||||
value = message.getString();
|
||||
return value;
|
||||
case 1: // Payload type is byte
|
||||
value = String(message.getByte());
|
||||
return value;
|
||||
case 2: // Payload type is INT16
|
||||
value = String(message.getInt());
|
||||
return value;
|
||||
case 3: // Payload type is UINT16
|
||||
value = String(message.getUInt());
|
||||
return value;
|
||||
case 4: // Payload type is INT32
|
||||
value = String(message.getInt());
|
||||
return value;
|
||||
case 5: // Payload type is UINT32
|
||||
value = String(message.getUInt());
|
||||
return value;
|
||||
case 6: // Payload type is binary
|
||||
value = String(message.getBool());
|
||||
return value;
|
||||
case 7: // Payload type is float32
|
||||
value = String(message.getFloat());
|
||||
return value;
|
||||
default:
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
12
src/modules/exec/MySensors/MySensorsData.h
Normal file
12
src/modules/exec/MySensors/MySensorsData.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#include "Global.h"
|
||||
#ifdef MYSENSORS
|
||||
#define MY_DEBUG
|
||||
#define MY_RADIO_RF24
|
||||
#define MY_RF24_PA_LEVEL RF24_PA_HIGH // RF24_PA_MIN, RF24_PA_LOW, RF24_PA_HIGH, RF24_PA_MAX
|
||||
//#define MY_ENCRYPTION_SIMPLE_PASSWD "XpenBam"
|
||||
//#define MY_RF24_DATARATE RF24_2MBPS
|
||||
#define MY_GATEWAY_SERIAL
|
||||
#include "MySensors.h"
|
||||
extern void receive(const MyMessage &message);
|
||||
extern String parseToString(const MyMessage &message);
|
||||
#endif
|
||||
353
src/modules/exec/MySensors/MySensorsGate.cpp
Normal file
353
src/modules/exec/MySensors/MySensorsGate.cpp
Normal file
@@ -0,0 +1,353 @@
|
||||
#include "Global.h"
|
||||
#include "classes/IoTItem.h"
|
||||
#include "Arduino.h"
|
||||
|
||||
class MySensorsGate : public IoTItem {
|
||||
private:
|
||||
int _pin;
|
||||
|
||||
public:
|
||||
MySensorsGate(String parameters) : IoTItem(parameters) {
|
||||
jsonRead(parameters, "pin", _pin);
|
||||
// init place
|
||||
SerialPrint("i", "MySensors", "Gate initialized");
|
||||
}
|
||||
|
||||
void doByInterval() {
|
||||
}
|
||||
|
||||
void loop() {
|
||||
loopMySensorsExecute();
|
||||
}
|
||||
|
||||
void setValue(const IoTValue& Value, bool genEvent = true) {
|
||||
value = Value;
|
||||
// set value place
|
||||
regEvent(value.valD, "MySensorsGate", false, genEvent);
|
||||
}
|
||||
|
||||
~MySensorsGate(){};
|
||||
|
||||
void loopMySensorsExecute() {
|
||||
if (mysensorBuf.length()) {
|
||||
String tmp = selectToMarker(mysensorBuf, ";");
|
||||
|
||||
String nodeId = selectFromMarkerToMarker(tmp, ",", 0); // node-id
|
||||
String childSensorId = selectFromMarkerToMarker(tmp, ",", 1); // child-sensor-id
|
||||
String type = selectFromMarkerToMarker(tmp, ",", 2); // type of var
|
||||
String command = selectFromMarkerToMarker(tmp, ",", 3); // command
|
||||
String value = selectFromMarkerToMarker(tmp, ",", 4); // value
|
||||
|
||||
static bool presentBeenStarted = false;
|
||||
|
||||
String key = nodeId + "-" + childSensorId;
|
||||
static String infoJson = "{}";
|
||||
|
||||
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);
|
||||
}
|
||||
if (type == "12") { //версия ноды
|
||||
SerialPrint("i", "MySensors", "Node version: " + value);
|
||||
//*
|
||||
// publishAnyJsonKey("MySensors", "Node version: ", value);
|
||||
// publishAnyJsonKeyWS("MySensors", "Node version: ", value);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (command == "0") { //это презентация
|
||||
presentBeenStarted = true;
|
||||
int num;
|
||||
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);
|
||||
}
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
if (command == "2") { //это запрос значения переменной
|
||||
SerialPrint("i", "MySensors", "Request a variable value");
|
||||
}
|
||||
}
|
||||
|
||||
mysensorBuf = deleteBeforeDelimiter(mysensorBuf, ";");
|
||||
}
|
||||
}
|
||||
|
||||
void sensorType(int index, int& num, String& widget, String& descr) {
|
||||
switch (index) {
|
||||
case 0:
|
||||
descr = F("Door#and#window#sensors");
|
||||
widget = F("alarm");
|
||||
num = 1;
|
||||
break;
|
||||
case 1:
|
||||
descr = F("Motion#sensors");
|
||||
widget = F("alarm");
|
||||
num = 1;
|
||||
break;
|
||||
case 2:
|
||||
descr = F("Smoke#sensor");
|
||||
widget = F("fillgauge");
|
||||
num = 1;
|
||||
break;
|
||||
case 3:
|
||||
descr = F("Binary#device#(on/off)");
|
||||
widget = F("toggleBtn");
|
||||
num = 2;
|
||||
break;
|
||||
case 4:
|
||||
descr = F("Dimmable#device");
|
||||
// to do
|
||||
// widget = F("range");
|
||||
// num = 2;
|
||||
break;
|
||||
case 5:
|
||||
descr = F("Window#covers#or#shades");
|
||||
// to do
|
||||
// widget = F("range");
|
||||
// num = 2;
|
||||
break;
|
||||
case 6:
|
||||
descr = F("Temperature#sensor");
|
||||
widget = F("anydataTemp");
|
||||
num = 1;
|
||||
break;
|
||||
case 7:
|
||||
descr = F("Humidity#sensor");
|
||||
widget = F("anydataHum");
|
||||
num = 1;
|
||||
break;
|
||||
case 8:
|
||||
descr = F("Pressure#sensor");
|
||||
widget = F("anydataPress");
|
||||
num = 1;
|
||||
break;
|
||||
case 9:
|
||||
descr = F("Wind#sensor");
|
||||
widget = F("anydataTime");
|
||||
num = 1;
|
||||
break;
|
||||
case 10:
|
||||
descr = F("Rain#sensor");
|
||||
widget = F("anydataTime");
|
||||
num = 1;
|
||||
break;
|
||||
case 11:
|
||||
descr = F("UV#sensor");
|
||||
widget = F("anydataTime");
|
||||
num = 1;
|
||||
break;
|
||||
case 12:
|
||||
descr = F("Weight#sensor");
|
||||
widget = F("anydataTime");
|
||||
num = 1;
|
||||
break;
|
||||
case 13:
|
||||
descr = F("Power#measuring#device");
|
||||
widget = F("anydataWtt");
|
||||
num = 1;
|
||||
break;
|
||||
case 14:
|
||||
descr = F("Heater#device");
|
||||
widget = F("anydataTemp");
|
||||
num = 1;
|
||||
break;
|
||||
case 15:
|
||||
descr = F("Distance#sensor");
|
||||
widget = F("anydata");
|
||||
num = 1;
|
||||
break;
|
||||
case 16:
|
||||
descr = F("Light#sensor");
|
||||
widget = F("anydataTime");
|
||||
num = 1;
|
||||
break;
|
||||
case 17:
|
||||
descr = F("Arduino#node#device");
|
||||
widget = F("anydata");
|
||||
num = 1;
|
||||
break;
|
||||
case 18:
|
||||
descr = F("Arduino#repeating#node#device");
|
||||
widget = F("anydata");
|
||||
num = 1;
|
||||
break;
|
||||
case 19:
|
||||
descr = F("Lock#device");
|
||||
widget = F("toggleBtn");
|
||||
num = 2;
|
||||
break;
|
||||
case 20:
|
||||
descr = F("Ir#sender/receiver#device");
|
||||
widget = F("toggleBtn");
|
||||
num = 2;
|
||||
break;
|
||||
case 21:
|
||||
descr = F("Water#meter");
|
||||
widget = F("anydata");
|
||||
num = 1;
|
||||
break;
|
||||
case 22:
|
||||
descr = F("Air#quality#sensor");
|
||||
widget = F("anydata");
|
||||
num = 1;
|
||||
break;
|
||||
case 23:
|
||||
descr = F("Custom#sensor");
|
||||
widget = F("anydata");
|
||||
num = 1;
|
||||
break;
|
||||
case 24:
|
||||
descr = F("Dust#level#sensor");
|
||||
widget = F("anydata");
|
||||
num = 1;
|
||||
break;
|
||||
case 25:
|
||||
descr = F("Scene#controller#device");
|
||||
widget = F("anydata");
|
||||
num = 1;
|
||||
break;
|
||||
case 26:
|
||||
descr = F("RGB#light");
|
||||
widget = F("anydata");
|
||||
num = 1;
|
||||
break;
|
||||
case 27:
|
||||
descr = F("RGBW#light#(with#separate#white#component)");
|
||||
widget = F("anydata");
|
||||
num = 1;
|
||||
break;
|
||||
case 28:
|
||||
descr = F("Color#sensor");
|
||||
widget = F("anydata");
|
||||
num = 1;
|
||||
break;
|
||||
case 29:
|
||||
descr = F("Thermostat/HVAC#device");
|
||||
widget = F("anydata");
|
||||
num = 1;
|
||||
break;
|
||||
case 30:
|
||||
descr = F("Multimeter#device");
|
||||
widget = F("anydataVlt");
|
||||
num = 1;
|
||||
break;
|
||||
case 31:
|
||||
descr = F("Sprinkler#device");
|
||||
widget = F("anydata");
|
||||
num = 1;
|
||||
break;
|
||||
case 32:
|
||||
descr = F("Water#leak#sensor");
|
||||
widget = F("alarm");
|
||||
num = 1;
|
||||
break;
|
||||
case 33:
|
||||
descr = F("Sound#sensor");
|
||||
widget = F("anydata");
|
||||
num = 1;
|
||||
break;
|
||||
case 34:
|
||||
descr = F("Vibration#sensor");
|
||||
widget = F("anydata");
|
||||
num = 1;
|
||||
break;
|
||||
case 35:
|
||||
descr = F("Moisture#sensor");
|
||||
widget = F("anydata");
|
||||
num = 1;
|
||||
break;
|
||||
case 36:
|
||||
descr = F("LCD#text#device");
|
||||
widget = F("anydata");
|
||||
num = 1;
|
||||
break;
|
||||
case 37:
|
||||
descr = F("Gas#meter");
|
||||
widget = F("anydata");
|
||||
num = 1;
|
||||
break;
|
||||
case 38:
|
||||
descr = F("GPS#Sensor");
|
||||
widget = F("anydata");
|
||||
num = 1;
|
||||
break;
|
||||
case 39:
|
||||
descr = F("Water#quality#sensor");
|
||||
widget = F("anydata");
|
||||
num = 1;
|
||||
break;
|
||||
default:
|
||||
descr = F("Unknown");
|
||||
widget = F("anydata");
|
||||
num = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
void* getAPI_MySensorsGate(String subtype, String param) {
|
||||
if (subtype == F("MySensorsGate")) {
|
||||
return new MySensorsGate(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);
|
||||
// }
|
||||
42
src/modules/exec/MySensors/modinfo.json
Normal file
42
src/modules/exec/MySensors/modinfo.json
Normal file
@@ -0,0 +1,42 @@
|
||||
{
|
||||
"menuSection": "Исполнительные устройства",
|
||||
"configItem": [
|
||||
{
|
||||
"global": 0,
|
||||
"name": "MySensorsGate",
|
||||
"type": "Reading",
|
||||
"subtype": "MySensorsGate",
|
||||
"id": "t",
|
||||
"widget": "anydataTmp",
|
||||
"page": "Сенсоры",
|
||||
"descr": "Температура",
|
||||
"map": "1,1024,1,100",
|
||||
"plus": 0,
|
||||
"multiply": 1,
|
||||
"round": 1
|
||||
}
|
||||
],
|
||||
"about": {
|
||||
"authorName": "Dmitry Borisenko",
|
||||
"authorContact": "https://t.me/Dmitry_Borisenko",
|
||||
"authorGit": "https://github.com/DmitryBorisenko33",
|
||||
"specialThanks": "",
|
||||
"moduleName": "MySensorsGate",
|
||||
"moduleVersion": "1.0",
|
||||
"usedRam": {
|
||||
"esp32_4mb": 15,
|
||||
"esp8266_4mb": 15
|
||||
},
|
||||
"title": "My Sensors Gate",
|
||||
"moduleDesc": "",
|
||||
"retInfo": "",
|
||||
"propInfo": {
|
||||
"int": "",
|
||||
"pin": ""
|
||||
}
|
||||
},
|
||||
"defActive": true,
|
||||
"usedLibs": {
|
||||
"esp32_4mb": []
|
||||
}
|
||||
}
|
||||
@@ -104,7 +104,7 @@ class Loging : public IoTItem {
|
||||
//запускаем процедуру удаления старых файлов если память переполняется
|
||||
deleteLastFile();
|
||||
}
|
||||
void SetDoByInterval(String valse) {
|
||||
void SetDoByInterval(String valse) {
|
||||
String value = valse;
|
||||
//если значение логгирования пустое
|
||||
if (value == "") {
|
||||
@@ -152,7 +152,6 @@ void SetDoByInterval(String valse) {
|
||||
}
|
||||
//запускаем процедуру удаления старых файлов если память переполняется
|
||||
deleteLastFile();
|
||||
|
||||
}
|
||||
void createNewFileWithData(String &logData) {
|
||||
logData = logData + ",";
|
||||
@@ -308,14 +307,14 @@ void SetDoByInterval(String valse) {
|
||||
difference = currentMillis - prevMillis;
|
||||
if (difference >= interval) {
|
||||
prevMillis = millis();
|
||||
if(interval != 0){
|
||||
if (interval != 0) {
|
||||
this->doByInterval();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void regEvent(const String& value, const String& consoleInfo, bool error = false, bool genEvent = true) {
|
||||
void regEvent(const String &value, const String &consoleInfo, bool error = false, bool genEvent = true) {
|
||||
String userDate = getItemValue(id + "-date");
|
||||
String currentDate = getTodayDateDotFormated();
|
||||
//отправляем в график данные только когда выбран сегодняшний день
|
||||
@@ -337,7 +336,7 @@ void SetDoByInterval(String valse) {
|
||||
unsigned long getFileUnixLocalTime(String path) {
|
||||
return gmtTimeToLocal(selectToMarkerLast(deleteToMarkerLast(path, "."), "/").toInt() + START_DATETIME);
|
||||
}
|
||||
void setValue(const IoTValue& Value, bool genEvent = true){
|
||||
void setValue(const IoTValue &Value, bool genEvent = true) {
|
||||
value = Value;
|
||||
this->SetDoByInterval(String(value.valD));
|
||||
SerialPrint("i", "Loging", "setValue:" + String(value.valD));
|
||||
@@ -364,12 +363,12 @@ class Date : public IoTItem {
|
||||
value.isDecimal = false;
|
||||
}
|
||||
|
||||
void setValue(const String& valStr, bool genEvent = true) {
|
||||
void setValue(const String &valStr, bool genEvent = true) {
|
||||
value.valS = valStr;
|
||||
setValue(value, genEvent);
|
||||
}
|
||||
|
||||
void setValue(const IoTValue& Value, bool genEvent = true) {
|
||||
void setValue(const IoTValue &Value, bool genEvent = true) {
|
||||
value = Value;
|
||||
regEvent(value.valS, "", false, genEvent);
|
||||
//отправка данных при изменении даты
|
||||
|
||||
Reference in New Issue
Block a user