устранение багов

This commit is contained in:
Dmitry Borisenko
2022-10-12 03:14:55 +02:00
parent 2c7adf468b
commit 6912d5f68d
16 changed files with 126 additions and 184 deletions

View File

@@ -276,58 +276,7 @@
"num": 20
},
{
"name": "21. Частотомер на ADC, Частота",
"type": "Reading",
"subtype": "FreqMeterF",
"id": "freq",
"widget": "anydataHtz",
"page": "Частотомер",
"descr": "Частота",
"plus": 0,
"multiply": 1,
"round": 1,
"pin-Esp32": 33,
"samples": 512,
"samplingFrequency": 5000,
"int": 5,
"num": 21
},
{
"name": "22. Частотомер на ADC, Процент Пульсации",
"type": "Reading",
"subtype": "FreqMeterPcFl",
"id": "pctFlicker",
"widget": "anydataPct",
"page": "Частотомер",
"descr": "Процент Пульсации",
"plus": 0,
"multiply": 1,
"round": 1,
"pin-Esp32": 33,
"samples": 512,
"samplingFrequency": 5000,
"int": 5,
"num": 22
},
{
"name": "23. Частотомер на ADC, Индекс Пульсации",
"type": "Reading",
"subtype": "FreqMeterFlIn",
"id": "flickerIndex",
"widget": "anydataDef",
"page": "Частотомер",
"descr": "Индекс Пульсации",
"plus": 0,
"multiply": 1,
"round": 10,
"pin-Esp32": 33,
"samples": 512,
"samplingFrequency": 5000,
"int": 5,
"num": 23
},
{
"name": "24. GY21 Температура",
"name": "21. GY21 Температура",
"type": "Reading",
"subtype": "GY21t",
"id": "tmp4",
@@ -336,10 +285,10 @@
"descr": "Температура",
"round": 1,
"int": 15,
"num": 24
"num": 21
},
{
"name": "25. GY21 Влажность",
"name": "22. GY21 Влажность",
"type": "Reading",
"subtype": "GY21h",
"id": "Hum4",
@@ -348,10 +297,10 @@
"descr": "Влажность",
"round": 1,
"int": 15,
"num": 25
"num": 22
},
{
"name": "26. HDC1080 Температура",
"name": "23. HDC1080 Температура",
"type": "Reading",
"subtype": "Hdc1080t",
"id": "Temp1080",
@@ -361,10 +310,10 @@
"int": 15,
"addr": "0x40",
"round": 1,
"num": 26
"num": 23
},
{
"name": "27. HDC1080 Влажность",
"name": "24. HDC1080 Влажность",
"type": "Reading",
"subtype": "Hdc1080h",
"id": "Hum1080",
@@ -374,10 +323,10 @@
"int": 15,
"addr": "0x40",
"round": 1,
"num": 27
"num": 24
},
{
"name": "28. MAX6675 Температура",
"name": "25. MAX6675 Температура",
"type": "Reading",
"subtype": "Max6675t",
"id": "maxtmp",
@@ -388,10 +337,10 @@
"DO": 12,
"CS": 13,
"CLK": 14,
"num": 28
"num": 25
},
{
"name": "29. PZEM 004t Напряжение",
"name": "26. PZEM 004t Напряжение",
"type": "Reading",
"subtype": "Pzem004v",
"id": "v",
@@ -401,10 +350,10 @@
"int": 15,
"addr": "0xF8",
"round": 1,
"num": 29
"num": 26
},
{
"name": "30. PZEM 004t Сила тока",
"name": "27. PZEM 004t Сила тока",
"type": "Reading",
"subtype": "Pzem004a",
"id": "a",
@@ -414,10 +363,10 @@
"int": 15,
"addr": "0xF8",
"round": 1,
"num": 30
"num": 27
},
{
"name": "31. PZEM 004t Мощность",
"name": "28. PZEM 004t Мощность",
"type": "Reading",
"subtype": "Pzem004w",
"id": "w",
@@ -427,10 +376,10 @@
"int": 15,
"addr": "0xF8",
"round": 1,
"num": 31
"num": 28
},
{
"name": "32. PZEM 004t Энергия",
"name": "29. PZEM 004t Энергия",
"type": "Reading",
"subtype": "Pzem004wh",
"id": "wh",
@@ -440,10 +389,10 @@
"int": 15,
"addr": "0xF8",
"round": 1,
"num": 32
"num": 29
},
{
"name": "33. PZEM 004t Частота",
"name": "30. PZEM 004t Частота",
"type": "Reading",
"subtype": "Pzem004hz",
"id": "hz",
@@ -453,10 +402,10 @@
"int": 15,
"addr": "0xF8",
"round": 1,
"num": 33
"num": 30
},
{
"name": "34. PZEM 004t Косинус",
"name": "31. PZEM 004t Косинус",
"type": "Reading",
"subtype": "Pzem004pf",
"id": "pf",
@@ -466,11 +415,11 @@
"int": 15,
"addr": "0xF8",
"round": 1,
"num": 34
"num": 31
},
{
"name": "35. Сканер кнопок 433 MHz",
"num": 35,
"name": "32. Сканер кнопок 433 MHz",
"num": 32,
"type": "Reading",
"subtype": "RCswitch",
"id": "rsw",
@@ -479,7 +428,7 @@
"pinTx": 12
},
{
"name": "36. Sht20 Температура",
"name": "33. Sht20 Температура",
"type": "Reading",
"subtype": "Sht20t",
"id": "tmp2",
@@ -488,10 +437,10 @@
"descr": "Температура",
"int": 15,
"round": 1,
"num": 36
"num": 33
},
{
"name": "37. Sht20 Влажность",
"name": "34. Sht20 Влажность",
"type": "Reading",
"subtype": "Sht20h",
"id": "Hum2",
@@ -500,10 +449,10 @@
"descr": "Влажность",
"int": 15,
"round": 1,
"num": 37
"num": 34
},
{
"name": "38. Sht30 Температура",
"name": "35. Sht30 Температура",
"type": "Reading",
"subtype": "Sht30t",
"id": "tmp30",
@@ -512,10 +461,10 @@
"descr": "SHT30 Температура",
"int": 15,
"round": 1,
"num": 38
"num": 35
},
{
"name": "39. Sht30 Влажность",
"name": "36. Sht30 Влажность",
"type": "Reading",
"subtype": "Sht30h",
"id": "Hum30",
@@ -524,11 +473,11 @@
"descr": "SHT30 Влажность",
"int": 15,
"round": 1,
"num": 39
"num": 36
},
{
"name": "40. HC-SR04 Ультразвуковой дальномер",
"num": 40,
"name": "37. HC-SR04 Ультразвуковой дальномер",
"num": 37,
"type": "Reading",
"subtype": "Sonar",
"id": "sonar",
@@ -540,7 +489,7 @@
"int": 5
},
{
"name": "41. UART",
"name": "38. UART",
"type": "Reading",
"subtype": "UART",
"page": "",
@@ -550,13 +499,13 @@
"tx": 12,
"rx": 13,
"speed": 9600,
"num": 41
"num": 38
},
{
"header": "Исполнительные устройства"
},
{
"name": "42. Кнопка подключенная к пину",
"name": "39. Кнопка подключенная к пину",
"type": "Writing",
"subtype": "ButtonIn",
"id": "btn",
@@ -569,10 +518,10 @@
"pinMode": "INPUT",
"debounceDelay": 50,
"fixState": 0,
"num": 42
"num": 39
},
{
"name": "43. Управление пином",
"name": "40. Управление пином",
"type": "Writing",
"subtype": "ButtonOut",
"id": "btn",
@@ -582,10 +531,10 @@
"int": 0,
"inv": 0,
"pin": 2,
"num": 43
"num": 40
},
{
"name": "44. Сервопривод",
"name": "41. Сервопривод",
"type": "Writing",
"subtype": "IoTServo",
"id": "servo",
@@ -596,10 +545,10 @@
"pin": 12,
"apin": -1,
"amap": "0, 4096, 0, 180",
"num": 44
"num": 41
},
{
"name": "45. Расширитель портов Mcp23017",
"name": "42. Расширитель портов Mcp23017",
"type": "Reading",
"subtype": "Mcp23017",
"id": "Mcp",
@@ -609,10 +558,10 @@
"int": "0",
"addr": "0x20",
"index": 1,
"num": 45
"num": 42
},
{
"name": "46. MP3 плеер",
"name": "43. MP3 плеер",
"type": "Reading",
"subtype": "Mp3",
"id": "mp3",
@@ -622,10 +571,10 @@
"int": 1,
"pins": "14,12",
"volume": 20,
"num": 46
"num": 43
},
{
"name": "47. Расширитель портов Pcf8574",
"name": "44. Расширитель портов Pcf8574",
"type": "Reading",
"subtype": "Pcf8574",
"id": "Pcf",
@@ -635,10 +584,10 @@
"int": "0",
"addr": "0x20",
"index": 1,
"num": 47
"num": 44
},
{
"name": "48. PWM ESP32",
"name": "45. PWM ESP32",
"type": "Writing",
"subtype": "Pwm32",
"id": "pwm",
@@ -652,10 +601,10 @@
"PWM_resolution": 10,
"val": 0,
"apin": -1,
"num": 48
"num": 45
},
{
"name": "49. Телеграм-Лайт",
"name": "46. Телеграм-Лайт",
"type": "Writing",
"subtype": "TelegramLT",
"id": "tg",
@@ -664,13 +613,13 @@
"descr": "",
"token": "",
"chatID": "",
"num": 49
"num": 46
},
{
"header": "Экраны"
},
{
"name": "50. LCD экран 2004",
"name": "47. LCD экран 2004",
"type": "Reading",
"subtype": "Lcd2004",
"id": "Lcd",
@@ -682,10 +631,10 @@
"size": "20,4",
"coord": "0,0",
"id2show": "id датчика",
"num": 50
"num": 47
},
{
"name": "51. LCD экран 1602",
"name": "48. LCD экран 1602",
"type": "Reading",
"subtype": "Lcd2004",
"id": "Lcd",
@@ -697,6 +646,6 @@
"size": "16,2",
"coord": "0,0",
"id2show": "id датчика",
"num": 51
"num": 48
}
]

View File

@@ -19,5 +19,6 @@
"pinSCL": 0,
"pinSDA": 0,
"i2cFreq": 100000,
"wg": "group1",
"settings_": ""
}

View File

@@ -15,6 +15,8 @@
#define JSON_BUFFER_SIZE 2048
#define WEB_SOCKETS_FRAME_SIZE 2048
//#define LOOP_DEBUG
//выбор сервера
//#define ASYNC_WEB_SERVER
//#define ASYNC_WEB_SOCKETS

View File

@@ -137,6 +137,8 @@ extern Time_t _time_local;
extern Time_t _time_utc;
extern bool _time_isTrust;
extern unsigned long loopPeriod;
// extern DynamicJsonDocument settingsFlashJsonDoc;
// extern DynamicJsonDocument paramsFlashJsonDoc;
// extern DynamicJsonDocument paramsHeapJsonDoc;

View File

@@ -10,8 +10,5 @@
extern void periodicTasksInit();
extern void printGlobalVarSize();
extern void handleError(String errorId, String errorValue);
extern void handleError(String errorId, int errorValue);
extern String ESP_getResetReason(void);
extern String ESP32GetResetReason(uint32_t cpu_no);

View File

@@ -20,7 +20,8 @@
"mqttin": 0,
"pinSCL": 0,
"pinSDA": 0,
"i2cFreq": 100000
"i2cFreq": 100000,
"wg": "group1"
},
"projectProp": {
"platformio": {
@@ -90,7 +91,7 @@
},
{
"path": "src/modules/sensors/FreqMeter",
"active": true
"active": false
},
{
"path": "src/modules/sensors/GY21",

View File

@@ -57,7 +57,6 @@ lib_deps =
adafruit/Adafruit BMP280 Library
beegee-tokyo/DHT sensor library for ESPx
milesburton/DallasTemperature@^3.9.1
kosme/arduinoFFT@^1.5.6
https://github.com/JonasGMorsch/GY-21.git
ClosedCube HDC1080
adafruit/MAX6675 library
@@ -83,7 +82,6 @@ build_src_filter =
+<modules/sensors/Bmp280>
+<modules/sensors/Dht1122>
+<modules/sensors/Ds18b20>
+<modules/sensors/FreqMeter>
+<modules/sensors/GY21>
+<modules/sensors/Hdc1080>
+<modules/sensors/Max6675>
@@ -110,7 +108,6 @@ lib_deps =
adafruit/Adafruit BMP280 Library
beegee-tokyo/DHT sensor library for ESPx
milesburton/DallasTemperature@^3.9.1
kosme/arduinoFFT@^1.5.6
https://github.com/JonasGMorsch/GY-21.git
ClosedCube HDC1080
adafruit/MAX6675 library
@@ -137,7 +134,6 @@ build_src_filter =
+<modules/sensors/Bmp280>
+<modules/sensors/Dht1122>
+<modules/sensors/Ds18b20>
+<modules/sensors/FreqMeter>
+<modules/sensors/GY21>
+<modules/sensors/Hdc1080>
+<modules/sensors/Max6675>

View File

@@ -2,7 +2,8 @@
const String getThisDevice() {
String thisDevice = "{}";
jsonWriteStr_(thisDevice, F("devicelist_"), ""); //метка для парсинга нужна для udp валидации может быть рабочей группой в последствии
jsonWriteStr_(thisDevice, F("devicelist_"), ""); //метка для парсинга
jsonWriteStr_(thisDevice, F("wg"), jsonReadStr(settingsFlashJson, F("wg"))); //рабочая группа
jsonWriteStr_(thisDevice, F("ip"), jsonReadStr(settingsFlashJson, F("ip")));
jsonWriteStr_(thisDevice, F("id"), jsonReadStr(settingsFlashJson, F("id")));
jsonWriteStr_(thisDevice, F("name"), jsonReadStr(settingsFlashJson, F("name")));
@@ -52,7 +53,7 @@ void asyncUdpInit() {
});
}
//будем отправлять каждые 30 секунд презентацию данного устройства
//будем отправлять каждые 60 секунд презентацию данного устройства
ts.add(
UDP, 60000, [&](void*) { // UDPP
if (isNetworkActive()) {
@@ -68,7 +69,9 @@ void asyncUdpInit() {
}
bool udpPacketValidation(String& data) {
if (data.indexOf("devicelist_") != -1) {
// SerialPrint("i", F("UDP"), data);
String workgroup = jsonReadStr(settingsFlashJson, "wg");
if (workgroup != "" && data.indexOf(workgroup) != -1) {
return true;
} else {
return false;

View File

@@ -68,6 +68,8 @@ String mqttRootDevice = "";
unsigned long unixTime = 0;
unsigned long unixTimeShort = 0;
unsigned long loopPeriod;
bool isTimeSynch = false;
Time_t _time_local;
Time_t _time_utc;

View File

@@ -116,38 +116,22 @@ void setup() {
}
void loop() {
// if(millis()%2000==0){
// //watch->settimeUnix(time(&iotTimeNow));
// Serial.println(watch->gettime("d-m-Y, H:i:s, M"));
// delay(1);
// }
//обновление задач таскера
ts.update();
//отправка json
#ifdef QUEUE_FROM_STR
if (sendJsonFiles) sendJsonFiles->loop();
#ifdef LOOP_DEBUG
unsigned long st = millis();
#endif
ts.update();
#ifdef STANDARD_WEB_SERVER
//обработка web сервера 1
HTTP.handleClient();
#endif
#ifdef STANDARD_WEB_SOCKETS
//обработка web сокетов
standWebSocket.loop();
#endif
//обновление mqtt
mqttLoop();
#ifdef STANDARD_WEB_SERVER
//обработка web сервера 2
// HTTP.handleClient();
#endif
// передаем управление каждому элементу конфигурации для выполнения своих функций
for (std::list<IoTItem *>::iterator it = IoTItems.begin(); it != IoTItems.end(); ++it) {
(*it)->loop();
@@ -159,33 +143,43 @@ void loop() {
}
handleOrder();
handleEvent();
#ifdef STANDARD_WEB_SERVER
//обработка web сервера 3
// HTTP.handleClient();
#ifdef LOOP_DEBUG
loopPeriod = millis() - st;
if (loopPeriod > 2) Serial.println(loopPeriod);
#endif
// сохраняем значения IoTItems в файл каждую секунду, если были изменения (установлены маркеры на сохранение)
// currentMillis = millis();
// if (currentMillis - prevMillis >= 1000) {
// prevMillis = millis();
// volStrForSave = "";
// for (std::list<IoTItem *>::iterator it = IoTItems.begin(); it != IoTItems.end(); ++it) {
// if ((*it)->needSave) {
// (*it)->needSave = false;
// volStrForSave = volStrForSave + (*it)->getID() + "=" + (*it)->getValue() + ";";
// }
// }
//
// if (volStrForSave != "") {
// Serial.print("volStrForSave: ");
// Serial.println(volStrForSave.c_str());
// }
//}
}
//отправка json
//#ifdef QUEUE_FROM_STR
// if (sendJsonFiles) sendJsonFiles->loop();
//#endif
// if(millis()%2000==0){
// //watch->settimeUnix(time(&iotTimeNow));
// Serial.println(watch->gettime("d-m-Y, H:i:s, M"));
// delay(1);
// }
// сохраняем значения IoTItems в файл каждую секунду, если были изменения (установлены маркеры на сохранение)
// currentMillis = millis();
// if (currentMillis - prevMillis >= 1000) {
// prevMillis = millis();
// volStrForSave = "";
// for (std::list<IoTItem *>::iterator it = IoTItems.begin(); it != IoTItems.end(); ++it) {
// if ((*it)->needSave) {
// (*it)->needSave = false;
// volStrForSave = volStrForSave + (*it)->getID() + "=" + (*it)->getValue() + ";";
// }
// }
//
// if (volStrForSave != "") {
// Serial.print("volStrForSave: ");
// Serial.println(volStrForSave.c_str());
// }
//}
// File dir = FileFS.open("/", "r");
// String out;
// printDirectory(dir, out);

View File

@@ -278,7 +278,7 @@ void publishWidgets() {
DeserializationError error = deserializeJson(doc, file);
if (error) {
SerialPrint("E", F("MQTT"), error.f_str());
handleError("jse3", 1);
jsonWriteInt(errorsHeapJson, F("jse3"), 1); //Ошибка чтения json файла с виджетами при отправки в mqtt
}
JsonArray arr = doc.as<JsonArray>();
for (JsonVariant value : arr) {

View File

@@ -13,9 +13,11 @@ void ntpInit() {
if (unixTime < MIN_DATETIME) {
isTimeSynch = false;
// SerialPrint("E", "NTP", "Time not synched");
jsonWriteInt(errorsHeapJson, F("tme1"), 1);
synchTime();
return;
}
jsonWriteInt(errorsHeapJson, F("tme1"), 0);
breakEpochToTime(unixTime + jsonReadInt(settingsFlashJson, F("timezone")) * 60 * 60, _time_local);
breakEpochToTime(unixTime, _time_utc);
isTimeSynch = true;

View File

@@ -31,14 +31,6 @@ void periodicTasksInit() {
SerialPrint("i", "Task", "Periodic tasks init");
}
void handleError(String errorId, String errorValue) {
jsonWriteStr_(errorsHeapJson, errorId, errorValue);
}
void handleError(String errorId, int errorValue) {
jsonWriteInt_(errorsHeapJson, errorId, errorValue);
}
void printGlobalVarSize() {
size_t settingsFlashJsonSize = settingsFlashJson.length();
// SerialPrint(F("i"), F("settingsFlashJson"), String(settingsFlashJsonSize));

View File

@@ -176,10 +176,14 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length)
// Страница веб интерфейса dev
//----------------------------------------------------------------------//
if (headerStr == "/dev|") {
// standWebSocket.sendTXT(num, errorsHeapJson);
// standWebSocket.sendTXT(num, settingsFlashJson);
// sendFileToWs("/config.json", num, 1024);
// sendFileToWs("/items.json", num, 1024);
sendStringToWs("errors", errorsHeapJson, num);
sendStringToWs("settin", settingsFlashJson, num);
sendFileToWsByFrames("/config.json", "config", "", num, WEB_SOCKETS_FRAME_SIZE);
sendFileToWsByFrames("/items.json", "itemsj", "", num, WEB_SOCKETS_FRAME_SIZE);
// sendFileToWsByFrames("/layout.json", "layout", "", num, WEB_SOCKETS_FRAME_SIZE);
}
if (headerStr == "/test|") {
}
//----------------------------------------------------------------------//
@@ -216,8 +220,6 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length)
SerialPrint("i", F("=>WS"), "Msg from svelte web, WS No: " + String(num) + ", msg: " + msg);
}
if (headerStr == "/test|") {
}
} break;
case WStype_BIN: {
@@ -306,7 +308,7 @@ void sendFileToWsByFrames(const String& filename, const String& header, const St
}
size_t totalSize = file.size();
Serial.println("Send file '" + String(filename) + "', file size: " + String(totalSize));
// Serial.println("Send file '" + String(filename) + "', file size: " + String(totalSize));
char buf[32];
sprintf(buf, "%04d", json.length() + 12);
@@ -346,7 +348,7 @@ void sendFileToWsByFrames(const String& filename, const String& header, const St
continuation = true;
}
Serial.println(String(i) + ") " + "ws: " + String(client_id) + " fr sz: " + String(size) + " fin: " + String(fin) + " cnt: " + String(continuation));
// Serial.println(String(i) + ") " + "ws: " + String(client_id) + " fr sz: " + String(size) + " fin: " + String(fin) + " cnt: " + String(continuation));
if (client_id == -1) {
standWebSocket.broadcastBIN(frameBuf, size, fin, continuation);

View File

@@ -12,7 +12,6 @@ void* getAPI_Bme280(String subtype, String params);
void* getAPI_Bmp280(String subtype, String params);
void* getAPI_Dht1122(String subtype, String params);
void* getAPI_Ds18b20(String subtype, String params);
void* getAPI_FreqMeter(String subtype, String params);
void* getAPI_GY21(String subtype, String params);
void* getAPI_Hdc1080(String subtype, String params);
void* getAPI_Max6675(String subtype, String params);
@@ -46,7 +45,6 @@ if ((tmpAPI = getAPI_Bme280(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Bmp280(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Dht1122(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Ds18b20(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_FreqMeter(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_GY21(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Hdc1080(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Max6675(subtype, params)) != nullptr) return tmpAPI;

View File

@@ -318,8 +318,9 @@ String jsonWriteFloat(String& json, String name, float value, bool e) {
}
void jsonErrorDetected() {
jsonWriteInt(errorsHeapJson, F("jse2"), 1);
int number = jsonReadInt(errorsHeapJson, F("jse2n"));
number++;
jsonWriteInt(errorsHeapJson, F("jse2n"), number);
// пример как отправить ошибку с количеством
// jsonWriteInt(errorsHeapJson, F("jse2"), 1);
// int number = jsonReadInt(errorsHeapJson, F("jse2n"));
// number++;
// jsonWriteInt(errorsHeapJson, F("jse2n"), number);
}