mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-28 15:12:19 +03:00
bugfix Ble
This commit is contained in:
@@ -18,7 +18,15 @@ private:
|
|||||||
// описание параметров передаваемых из настроек датчика из веба
|
// описание параметров передаваемых из настроек датчика из веба
|
||||||
String _MAC;
|
String _MAC;
|
||||||
String _sensor;
|
String _sensor;
|
||||||
int timeRecv;
|
int timeRecv = 0;
|
||||||
|
int _minutesPassed = 0;
|
||||||
|
String json = "{}";
|
||||||
|
int orange = 0;
|
||||||
|
int red = 0;
|
||||||
|
int offline = 0;
|
||||||
|
int _int;
|
||||||
|
bool dataFromNode = false;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
String whoIAm(/*String &mac, String &sens*/)
|
String whoIAm(/*String &mac, String &sens*/)
|
||||||
{
|
{
|
||||||
@@ -38,6 +46,9 @@ public:
|
|||||||
if (timeRecv > 0)
|
if (timeRecv > 0)
|
||||||
{
|
{
|
||||||
value.valS = s;
|
value.valS = s;
|
||||||
|
dataFromNode = true;
|
||||||
|
_minutesPassed = 0;
|
||||||
|
setNewWidgetAttributes();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -55,12 +66,18 @@ public:
|
|||||||
value.isDecimal = 1;
|
value.isDecimal = 1;
|
||||||
value.valD = valStr.toFloat();
|
value.valD = valStr.toFloat();
|
||||||
regEvent(value.valD, _id);
|
regEvent(value.valD, _id);
|
||||||
|
dataFromNode = true;
|
||||||
|
_minutesPassed = 0;
|
||||||
|
setNewWidgetAttributes();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
value.isDecimal = 0;
|
value.isDecimal = 0;
|
||||||
value.valS = valStr;
|
value.valS = valStr;
|
||||||
regEvent(value.valS, _id);
|
regEvent(value.valS, _id);
|
||||||
|
dataFromNode = true;
|
||||||
|
_minutesPassed = 0;
|
||||||
|
setNewWidgetAttributes();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -99,12 +116,56 @@ public:
|
|||||||
}
|
}
|
||||||
regEvent(value.valS, _id);
|
regEvent(value.valS, _id);
|
||||||
}
|
}
|
||||||
|
_minutesPassed++;
|
||||||
|
setNewWidgetAttributes();
|
||||||
|
}
|
||||||
|
void onMqttWsAppConnectEvent()
|
||||||
|
{
|
||||||
|
setNewWidgetAttributes();
|
||||||
|
}
|
||||||
|
void setNewWidgetAttributes()
|
||||||
|
{
|
||||||
|
|
||||||
|
int minutes_ = _minutesPassed * _int / 60;
|
||||||
|
jsonWriteStr(json, F("info"), prettyMinutsTimeout(minutes_));
|
||||||
|
if (dataFromNode)
|
||||||
|
{
|
||||||
|
if (orange != 0 && red != 0 && offline != 0)
|
||||||
|
{
|
||||||
|
if (minutes_ < orange)
|
||||||
|
{
|
||||||
|
jsonWriteStr(json, F("color"), "");
|
||||||
|
}
|
||||||
|
if (minutes_ >= orange && minutes_ < red)
|
||||||
|
{
|
||||||
|
jsonWriteStr(json, F("color"), F("orange")); // сделаем виджет оранжевым
|
||||||
|
}
|
||||||
|
if (minutes_ >= red && minutes_ < offline)
|
||||||
|
{
|
||||||
|
jsonWriteStr(json, F("color"), F("red")); // сделаем виджет красным
|
||||||
|
}
|
||||||
|
if (minutes_ >= offline)
|
||||||
|
{
|
||||||
|
jsonWriteStr(json, F("info"), F("offline"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
jsonWriteStr(json, F("info"), F("awaiting"));
|
||||||
|
}
|
||||||
|
sendSubWidgetsValues(_id, json);
|
||||||
}
|
}
|
||||||
|
|
||||||
BleSens(String parameters) : IoTItem(parameters)
|
BleSens(String parameters) : IoTItem(parameters)
|
||||||
{
|
{
|
||||||
_MAC = jsonReadStr(parameters, "MAC");
|
_MAC = jsonReadStr(parameters, "MAC");
|
||||||
_sensor = jsonReadStr(parameters, "sensor");
|
_sensor = jsonReadStr(parameters, "sensor");
|
||||||
|
jsonRead(parameters, F("orange"), orange);
|
||||||
|
jsonRead(parameters, F("red"), red);
|
||||||
|
jsonRead(parameters, F("offline"), offline);
|
||||||
|
jsonRead(parameters, F("int"), _int);
|
||||||
|
dataFromNode = false;
|
||||||
BleSensArray.push_back(this);
|
BleSensArray.push_back(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -186,8 +247,9 @@ public:
|
|||||||
BLEdata.remove("acts");
|
BLEdata.remove("acts");
|
||||||
BLEdata.remove("cont");
|
BLEdata.remove("cont");
|
||||||
BLEdata.remove("track");
|
BLEdata.remove("track");
|
||||||
|
BLEdata.remove("id");
|
||||||
|
|
||||||
String mac_address = BLEdata["id"].as<const char *>();
|
String mac_address = BLEdata["MAC"].as<const char *>();
|
||||||
mac_address.replace(":", "");
|
mac_address.replace(":", "");
|
||||||
// дописываем время прихода пакета данных
|
// дописываем время прихода пакета данных
|
||||||
BLEdata["last"] = millis();
|
BLEdata["last"] = millis();
|
||||||
@@ -199,13 +261,15 @@ public:
|
|||||||
// {
|
// {
|
||||||
// String val = BLEdata.as<String>();
|
// String val = BLEdata.as<String>();
|
||||||
String output;
|
String output;
|
||||||
|
BLEdata.remove("servicedatauuid");
|
||||||
serializeJson(BLEdata, output);
|
serializeJson(BLEdata, output);
|
||||||
SerialPrint("i", F("BLE"), _id + " " + output);
|
SerialPrint("i", F("BLE"), mac_address + " " + output);
|
||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SerialPrint("i", F("BLE"), "found: " + mac_address);
|
||||||
}
|
}
|
||||||
BLEdata.remove("servicedatauuid");
|
|
||||||
SerialPrint("i", F("BLE"), "found: " + mac_address);
|
|
||||||
// Перебираем все зарегистрированные сенсоры BleSens
|
// Перебираем все зарегистрированные сенсоры BleSens
|
||||||
for (std::vector<BleSens *>::iterator it = BleSensArray.begin();
|
for (std::vector<BleSens *>::iterator it = BleSensArray.begin();
|
||||||
it != BleSensArray.end(); ++it)
|
it != BleSensArray.end(); ++it)
|
||||||
@@ -246,9 +310,7 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
~BleScan(){
|
~BleScan() { BleSensArray.clear(); };
|
||||||
BleSensArray.clear();
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//=======================================================================================================
|
//=======================================================================================================
|
||||||
@@ -267,4 +329,4 @@ void *getAPI_Ble(String subtype, String param)
|
|||||||
{
|
{
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -12,7 +12,7 @@
|
|||||||
"int": 135,
|
"int": 135,
|
||||||
"scanDuration": 10,
|
"scanDuration": 10,
|
||||||
"filter": "servicedatauuid",
|
"filter": "servicedatauuid",
|
||||||
"debug":1
|
"debug": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "bluetooth датчик",
|
"name": "bluetooth датчик",
|
||||||
@@ -26,6 +26,9 @@
|
|||||||
"int": 30,
|
"int": 30,
|
||||||
"global": 0,
|
"global": 0,
|
||||||
"round": 1,
|
"round": 1,
|
||||||
|
"orange": 60,
|
||||||
|
"red": 120,
|
||||||
|
"offline": 180,
|
||||||
"MAC": "",
|
"MAC": "",
|
||||||
"sensor": ""
|
"sensor": ""
|
||||||
}
|
}
|
||||||
@@ -49,6 +52,9 @@
|
|||||||
"moduleDesc": "Позволяет получить данные с Bluetooth часов и термометров Mijia, Xiaomi, Cleargrass, ...",
|
"moduleDesc": "Позволяет получить данные с Bluetooth часов и термометров Mijia, Xiaomi, Cleargrass, ...",
|
||||||
"propInfo": {
|
"propInfo": {
|
||||||
"round": "Округление после запятой.",
|
"round": "Округление после запятой.",
|
||||||
|
"orange": "количество минут после которого окрасить виджет в оранжевый цвет",
|
||||||
|
"red": "количество минут после которого окрасить виджет в красный цвет",
|
||||||
|
"offline": "количество минут после которого отобразить что устройство offline, если все три orange red и offline поставить в ноль - то функция окраски выключится",
|
||||||
"int": "Интервал сканирования BLE окружения (BleScan) / В BleSens темп обновления времнени поступления данных, сами даные обновляются по мене сканирования/поступления",
|
"int": "Интервал сканирования BLE окружения (BleScan) / В BleSens темп обновления времнени поступления данных, сами даные обновляются по мене сканирования/поступления",
|
||||||
"scanDuration": "Длительность сканирования ",
|
"scanDuration": "Длительность сканирования ",
|
||||||
"filter": "Позволяет установить фильтр по параметру передаваемому датчиком. Влияет только на вывод лога при debug=1, что бы было легче найти датчики, если много устройств в эфире",
|
"filter": "Позволяет установить фильтр по параметру передаваемому датчиком. Влияет только на вывод лога при debug=1, что бы было легче найти датчики, если много устройств в эфире",
|
||||||
@@ -59,27 +65,27 @@
|
|||||||
"defActive": false,
|
"defActive": false,
|
||||||
"usedLibs": {
|
"usedLibs": {
|
||||||
"esp32_4mb": [
|
"esp32_4mb": [
|
||||||
"https://github.com/h2zero/NimBLE-Arduino.git",
|
"https://github.com/Mit4el/NimBLE-Arduino.git",
|
||||||
"https://github.com/Mit4el/decoder.git"
|
"https://github.com/Mit4el/decoder.git"
|
||||||
],
|
],
|
||||||
"esp32_16mb": [
|
"esp32_16mb": [
|
||||||
"https://github.com/h2zero/NimBLE-Arduino.git",
|
"https://github.com/Mit4el/NimBLE-Arduino.git",
|
||||||
"https://github.com/Mit4el/decoder.git"
|
"https://github.com/Mit4el/decoder.git"
|
||||||
],
|
],
|
||||||
"esp32_4mb3f": [
|
"esp32_4mb3f": [
|
||||||
"https://github.com/h2zero/NimBLE-Arduino.git",
|
"https://github.com/Mit4el/NimBLE-Arduino.git",
|
||||||
"https://github.com/Mit4el/decoder.git"
|
"https://github.com/Mit4el/decoder.git"
|
||||||
],
|
],
|
||||||
"esp32cam_4mb": [
|
"esp32cam_4mb": [
|
||||||
"https://github.com/h2zero/NimBLE-Arduino.git",
|
"https://github.com/Mit4el/NimBLE-Arduino.git",
|
||||||
"https://github.com/Mit4el/decoder.git"
|
"https://github.com/Mit4el/decoder.git"
|
||||||
],
|
],
|
||||||
"esp32s3_16mb": [
|
"esp32s3_16mb": [
|
||||||
"https://github.com/h2zero/NimBLE-Arduino.git",
|
"https://github.com/Mit4el/NimBLE-Arduino.git",
|
||||||
"https://github.com/Mit4el/decoder.git"
|
"https://github.com/Mit4el/decoder.git"
|
||||||
],
|
],
|
||||||
"esp32c3m_4mb": [
|
"esp32c3m_4mb": [
|
||||||
"https://github.com/h2zero/NimBLE-Arduino.git",
|
"https://github.com/Mit4el/NimBLE-Arduino.git",
|
||||||
"https://github.com/Mit4el/decoder.git"
|
"https://github.com/Mit4el/decoder.git"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user