platformio esp8266, esp32

This commit is contained in:
Yuri Trikoz
2020-06-21 03:43:15 +03:00
parent ac6f51af7b
commit bba7487374
39 changed files with 8579 additions and 166 deletions

View File

@@ -19,17 +19,17 @@ void CMD_init() {
sCmd.addCommand("switch", switch_);
#ifdef analog_enable
#ifdef ANALOG_ENABLED
sCmd.addCommand("analog", analog);
#endif
#ifdef level_enable
#ifdef LEVEL_ENABLED
sCmd.addCommand("levelPr", levelPr);
sCmd.addCommand("ultrasonicCm", ultrasonicCm);
#endif
#ifdef dallas_enable
#ifdef DALLAS_ENABLED
sCmd.addCommand("dallas", dallas);
#endif
#ifdef dht_enable
#ifdef DHT_ENABLED
sCmd.addCommand("dhtT", dhtT);
sCmd.addCommand("dhtH", dhtH);
sCmd.addCommand("dhtPerception", dhtP);
@@ -37,34 +37,34 @@ void CMD_init() {
sCmd.addCommand("dhtDewpoint", dhtD);
#endif
#ifdef bmp_enable
#ifdef BMP_ENABLED
sCmd.addCommand("bmp280T", bmp280T);
sCmd.addCommand("bmp280P", bmp280P);
#endif
#ifdef bme_enable
#ifdef BME_ENABLED
sCmd.addCommand("bme280T", bme280T);
sCmd.addCommand("bme280P", bme280P);
sCmd.addCommand("bme280H", bme280H);
sCmd.addCommand("bme280A", bme280A);
#endif
#ifdef stepper_enable
#ifdef STEPPER_ENABLED
sCmd.addCommand("stepper", stepper);
sCmd.addCommand("stepperSet", stepperSet);
#endif
#ifdef servo_enable
#ifdef SERVO_ENABLED
sCmd.addCommand("servo", servo_);
sCmd.addCommand("servoSet", servoSet);
#endif
#ifdef serial_enable
#ifdef SERIAL_ENABLED
sCmd.addCommand("serialBegin", serialBegin);
sCmd.addCommand("serialWrite", serialWrite);
#endif
#ifdef logging_enable
#ifdef LOGGING_ENABLED
sCmd.addCommand("logging", logging);
#endif
@@ -83,7 +83,7 @@ void CMD_init() {
sCmd.addCommand("mqtt", mqttOrderSend);
sCmd.addCommand("http", httpOrderSend);
#ifdef push_enable
#ifdef PUSH_ENABLED
sCmd.addCommand("push", pushControl);
#endif
@@ -345,7 +345,7 @@ void textSet() {
}
//=====================================================================================================================================
//=========================================Модуль шагового мотора======================================================================
#ifdef stepper_enable
#ifdef STEPPER_ENABLED
//stepper 1 12 13
void stepper() {
String stepper_number = sCmd.next();
@@ -407,7 +407,7 @@ void stepperSet() {
#endif
//====================================================================================================================================================
//=================================================================Сервоприводы=======================================================================
#ifdef servo_enable
#ifdef SERVO_ENABLED
//servo 1 13 50 Мой#сервопривод Сервоприводы 0 100 0 180 2
void servo_() {
String servo_number = sCmd.next();
@@ -501,7 +501,7 @@ void servoSet() {
#endif
//====================================================================================================================================================
//===================================================================================serial===========================================================
#ifdef serial_enable
#ifdef SERIAL_ENABLED
void serialBegin() {
//String s_speed = sCmd.next();
//String rxPin = sCmd.next();
@@ -545,7 +545,7 @@ void firmwareVersion() {
String widget_name = sCmd.next();
String page_name = sCmd.next();
String page_number = sCmd.next();
jsonWriteStr(configLiveJson, "firmver", firmware_version);
jsonWriteStr(configLiveJson, "firmver", FIRMWARE_VERSION);
choose_widget_and_create(widget_name, page_name, page_number, "any-data", "firmver");
}

View File

@@ -7,18 +7,15 @@ UptimeInterval myUptime(10);
void handle_uptime();
void handle_statistics();
void File_system_init() {
if (!LittleFS.begin()) {
Serial.println("[E] LittleFS");
return;
void loadConfig() {
if (fileSystemInit()) {
configSetupJson = readFile("config.json", 4096);
configSetupJson.replace(" ", "");
configSetupJson.replace("\r\n", "");
}
configSetupJson = readFile("config.json", 4096);
configSetupJson.replace(" ", "");
configSetupJson.replace("\r\n", "");
jsonWriteStr(configSetupJson, "chipID", chipId);
jsonWriteStr(configSetupJson, "firmware_version", firmware_version);
jsonWriteStr(configSetupJson, "firmware_version", FIRMWARE_VERSION);
prex = jsonReadStr(configSetupJson, "mqttPrefix") + "/" + chipId;
@@ -62,10 +59,10 @@ void Device_init() {
ts.remove(i);
}
#ifdef layout_in_ram
#ifdef LAYOUT_IN_RAM
all_widgets = "";
#else
LittleFS.remove("/layout.txt");
removeFile("/layout.txt");
#endif
txtExecution("firmware.c.txt");
@@ -85,11 +82,14 @@ void uptime_init() {
handle_uptime();
},
nullptr, true);
ts.add(
STATISTICS, statistics_update, [&](void*) {
handle_statistics();
},
nullptr, true);
if (TELEMETRY_UPDATE_INTERVAL) {
ts.add(
STATISTICS, TELEMETRY_UPDATE_INTERVAL, [&](void*) {
handle_statistics();
},
nullptr, true);
}
}
void handle_uptime() {
@@ -123,7 +123,7 @@ void handle_statistics() {
urls += "&";
//-----------------------------------------------------------------
urls += "ver: ";
urls += String(firmware_version);
urls += String(FIRMWARE_VERSION);
//-----------------------------------------------------------------
String stat = getURL(urls);
//Serial.println(stat);

View File

@@ -1,8 +1,11 @@
#include "Global.h"
//
#include <LITTLEFS.h>
void sendLogData(String file, String topic);
#ifdef logging_enable
#ifdef LOGGING_ENABLED
//===============================================Логирование============================================================
//logging temp1 1 10 Температура Датчики 2
void logging() {
@@ -22,7 +25,7 @@ void logging() {
LOG1, period_min.toInt() * 1000 * 60, [&](void*) {
String tmp_buf_1 = selectFromMarkerToMarker(logging_value_names_list, ",", 0);
deleteOldDate("log." + tmp_buf_1 + ".txt", jsonReadInt(configOptionJson, tmp_buf_1 + "_c"), jsonReadStr(configLiveJson, tmp_buf_1));
Serial.println("[I] LOGGING for sensor '" + tmp_buf_1 + "' done");
Serial.println("[I] LOGGING for sensor '" + tmp_buf_1 + "' done");
},
nullptr, false);
}
@@ -31,7 +34,7 @@ void logging() {
LOG2, period_min.toInt() * 1000 * 60, [&](void*) {
String tmp_buf_2 = selectFromMarkerToMarker(logging_value_names_list, ",", 1);
deleteOldDate("log." + tmp_buf_2 + ".txt", jsonReadInt(configOptionJson, tmp_buf_2 + "_c"), jsonReadStr(configLiveJson, tmp_buf_2));
Serial.println("[I] LOGGING for sensor '" + tmp_buf_2 + "' done");
Serial.println("[I] LOGGING for sensor '" + tmp_buf_2 + "' done");
},
nullptr, false);
}
@@ -40,7 +43,7 @@ void logging() {
LOG3, period_min.toInt() * 1000 * 60, [&](void*) {
String tmp_buf_3 = selectFromMarkerToMarker(logging_value_names_list, ",", 2);
deleteOldDate("log." + tmp_buf_3 + ".txt", jsonReadInt(configOptionJson, tmp_buf_3 + "_c"), jsonReadStr(configLiveJson, tmp_buf_3));
Serial.println("[I] LOGGING for sensor '" + tmp_buf_3 + "' done");
Serial.println("[I] LOGGING for sensor '" + tmp_buf_3 + "' done");
},
nullptr, false);
}
@@ -49,7 +52,7 @@ void logging() {
LOG4, period_min.toInt() * 1000 * 60, [&](void*) {
String tmp_buf_4 = selectFromMarkerToMarker(logging_value_names_list, ",", 3);
deleteOldDate("log." + tmp_buf_4 + ".txt", jsonReadInt(configOptionJson, tmp_buf_4 + "_c"), jsonReadStr(configLiveJson, tmp_buf_4));
Serial.println("[I] LOGGING for sensor '" + tmp_buf_4 + "' done");
Serial.println("[I] LOGGING for sensor '" + tmp_buf_4 + "' done");
},
nullptr, false);
}
@@ -58,35 +61,33 @@ void logging() {
LOG5, period_min.toInt() * 1000 * 60, [&](void*) {
String tmp_buf_5 = selectFromMarkerToMarker(logging_value_names_list, ",", 4);
deleteOldDate("log." + tmp_buf_5 + ".txt", jsonReadInt(configOptionJson, tmp_buf_5 + "_c"), jsonReadStr(configLiveJson, tmp_buf_5));
Serial.println("[I] LOGGING for sensor '" + tmp_buf_5 + "' done");
Serial.println("[I] LOGGING for sensor '" + tmp_buf_5 + "' done");
},
nullptr, false);
}
}
//=========================================Удаление стрых данных и запись новых==================================================================
void deleteOldDate(String file, int seted_number_of_lines, String date_to_add) {
String log_date = readFile(file, 5000);
int current_number_of_lines = itemsCount(log_date, "\r\n");
Serial.println("=====> [i] in log file " + file + " " + current_number_of_lines + " lines");
void deleteOldDate(const String filename, int max_lines_cnt, String date_to_add) {
String log_date = readFile(filename, 5120);
size_t lines_cnt = itemsCount(log_date, "\r\n");
if (current_number_of_lines > seted_number_of_lines + 1) {
LittleFS.remove("/" + file);
current_number_of_lines = 0;
Serial.printf("[I] log %s of %d lines\n", filename.c_str(), lines_cnt);
if ((lines_cnt > max_lines_cnt + 1) || !lines_cnt) {
removeFile("/" + filename);
lines_cnt = 0;
}
if (current_number_of_lines == 0) {
LittleFS.remove("/" + file);
current_number_of_lines = 0;
}
if (current_number_of_lines > seted_number_of_lines) {
if (lines_cnt > max_lines_cnt) {
log_date = deleteBeforeDelimiter(log_date, "\r\n");
if (getTimeUnix() != "failed") {
log_date += getTimeUnix() + " " + date_to_add + "\r\n";
writeFile(file, log_date);
writeFile(filename, log_date);
}
} else {
if (getTimeUnix() != "failed") {
addFile(file, getTimeUnix() + " " + date_to_add);
addFile(filename, getTimeUnix() + " " + date_to_add);
}
}
log_date = "";
@@ -133,7 +134,7 @@ void sendLogData(String file, String topic) {
Serial.println(json_array);
sendCHART(topic, json_array);
json_array = "";
getMemoryLoad("[I] after send log date");
printMemoryStatus("[I] send log date");
}
}
@@ -154,12 +155,13 @@ void sendLogData(String file, String topic) {
}
getMemoryLoad("[I] after send log date");
*/
//=========================================Очистка данных===================================================================================
void clean_log_date() {
String all_line = logging_value_names_list;
while (all_line.length() != 0) {
String tmp = selectToMarker(all_line, ",");
LittleFS.remove("/log." + tmp + ".txt");
removeFile("/log." + tmp + ".txt");
all_line = deleteBeforeDelimiter(all_line, ",");
}
all_line = "";

View File

@@ -1,5 +1,8 @@
#include "Global.h"
//
#include <LittleFS.h>
// Errors
int wifi_lost_error = 0;
int mqtt_lost_error = 0;
@@ -14,7 +17,7 @@ void outcoming_date();
//===============================================ИНИЦИАЛИЗАЦИЯ================================================
void MQTT_init() {
ts.add(
WIFI_MQTT_CONNECTION_CHECK, wifi_mqtt_reconnecting, [&](void*) {
WIFI_MQTT_CONNECTION_CHECK, MQTT_RECONNECT_INTERVAL, [&](void*) {
if (WiFi.status() == WL_CONNECTED) {
Serial.println("[VV] WiFi-ok");
if (client_mqtt.connected()) {
@@ -73,7 +76,7 @@ boolean MQTT_Connecting() {
Serial.println("[V] Callback set, subscribe done");
res = true;
} else {
Serial.println("[E] try again in " + String(wifi_mqtt_reconnecting / 1000) + " sec");
Serial.println("[E] try again in " + String(MQTT_RECONNECT_INTERVAL / 1000) + " sec");
led_blink("fast");
}
}
@@ -133,7 +136,7 @@ void outcoming_date() {
sendAllWigets();
sendAllData();
#ifdef logging_enable
#ifdef LOGGING_ENABLED
choose_log_date_and_send();
#endif
@@ -179,7 +182,7 @@ void sendCONTROL(String id, String topik, String state) {
//=====================================================ОТПРАВЛЯЕМ ВИДЖЕТЫ========================================================
#ifdef layout_in_ram
#ifdef LAYOUT_IN_RAM
void sendAllWigets() {
if (all_widgets != "") {
int counter = 0;
@@ -203,26 +206,26 @@ void sendAllWigets() {
}
#endif
#ifndef layout_in_ram
#ifndef LAYOUT_IN_RAM
void sendAllWigets() {
auto file = LittleFS.open("/layout.txt", "r");
auto file = seekFile("/layout.txt");
if (!file) {
Serial.println("[e] on open layout.txt");
return;
}
file.seek(0, SeekSet); //поставим курсор в начало файла
while (file.position() != file.size()) {
String widget_to_send = file.readStringUntil('\n');
Serial.println("[V] " + widget_to_send);
sendMQTT("config", widget_to_send);
String payload = file.readStringUntil('\n');
Serial.println("[V] " + payload);
sendMQTT("config", payload);
}
file.close();
}
#endif
//=====================================================ОТПРАВЛЯЕМ ДАННЫЕ В ВИДЖЕТЫ ПРИ ОБНОВЛЕНИИ СТРАНИЦЫ========================================================
void sendAllData() { //берет строку json и ключи превращает в топики а значения колючей в них посылает
String current_config = configLiveJson; //{"name":"MODULES","lang":"","ip":"192.168.43.60","DS":"34.00","rel1":"1","rel2":"1"}
getMemoryLoad("[I] after send all date");
printMemoryStatus("[I] after send all date");
current_config.replace("{", "");
current_config.replace("}", ""); //"name":"MODULES","lang":"","ip":"192.168.43.60","DS":"34.00","rel1":"1","rel2":"1"
current_config += ","; //"name":"MODULES","lang":"","ip":"192.168.43.60","DS":"34.00","rel1":"1","rel2":"1",

View File

@@ -23,7 +23,7 @@ void sensors_init() {
static int counter;
counter++;
#ifdef level_enable
#ifdef LEVEL_ENABLED
if (sensors_reading_map[0] == 1)
ultrasonic_reading();
#endif
@@ -31,19 +31,19 @@ void sensors_init() {
if (counter > 10) {
counter = 0;
#ifdef analog_enable
#ifdef ANALOG_ENABLED
if (sensors_reading_map[1] == 1)
analog_reading1();
if (sensors_reading_map[2] == 1)
analog_reading2();
#endif
#ifdef dallas_enable
#ifdef DALLAS_ENABLED
if (sensors_reading_map[3] == 1)
dallas_reading();
#endif
#ifdef dht_enable
#ifdef DHT_ENABLED
if (sensors_reading_map[4] == 1)
dhtT_reading();
if (sensors_reading_map[5] == 1)
@@ -56,14 +56,14 @@ void sensors_init() {
dhtD_reading();
#endif
#ifdef bmp_enable
#ifdef BMP_ENABLED
if (sensors_reading_map[9] == 1)
bmp280T_reading();
if (sensors_reading_map[10] == 1)
bmp280P_reading();
#endif
#ifdef bme_enable
#ifdef BME_ENABLED
if (sensors_reading_map[11] == 1)
bme280T_reading();
if (sensors_reading_map[12] == 1)
@@ -80,7 +80,7 @@ void sensors_init() {
//=========================================================================================================================================
//=========================================Модуль измерения уровня в баке==================================================================
#ifdef level_enable
#ifdef LEVEL_ENABLED
//levelPr p 14 12 Вода#в#баке,#% Датчики fill-gauge 125 20 1
void levelPr() {
String value_name = sCmd.next();
@@ -138,7 +138,7 @@ void ultrasonic_reading() {
distance_cm = duration_ / 29 / 2;
distance_cm = medianFilter.filtered(distance_cm); //отсечение промахов медианным фильтром
counter++;
if (counter > tank_level_times_to_send) {
if (counter > TANK_LEVEL_SAMPLES) {
counter = 0;
level = map(distance_cm,
jsonReadInt(configOptionJson, "e_lev"),
@@ -158,7 +158,7 @@ void ultrasonic_reading() {
#endif
//=========================================================================================================================================
//=========================================Модуль аналогового сенсора======================================================================
#ifdef analog_enable
#ifdef ANALOG_ENABLED
//analog adc 0 Аналоговый#вход,#% Датчики any-data 1 1023 1 100 1
void analog() {
String value_name = sCmd.next();
@@ -226,7 +226,7 @@ void analog_reading2() {
#endif
//=========================================================================================================================================
//=========================================Модуль температурного сенсора ds18b20===========================================================
#ifdef dallas_enable
#ifdef DALLAS_ENABLED
void dallas() {
//String value_name = sCmd.next();
String pin = sCmd.next();
@@ -255,7 +255,7 @@ void dallas_reading() {
#endif
//=========================================================================================================================================
//=========================================Модуль сенсоров DHT=============================================================================
#ifdef dht_enable
#ifdef DHT_ENABLED
//dhtT t 2 dht11 Температура#DHT,#t°C Датчики any-data 1
void dhtT() {
String value_name = sCmd.next();

View File

@@ -68,10 +68,10 @@ void upgrade_firmware() {
Serial.println("Restart...");
ESP.restart();
} else {
Serial.println("[e] on build");
Serial.println("[E] on build");
}
} else {
Serial.println("[e] on upgrade");
Serial.println("[E] on upgrade");
}
}

View File

@@ -1,6 +1,29 @@
#include "Utils/FileUtils.h"
#include <LittleFS.h>
bool fileSystemInit() {
if (!LittleFS.begin()) {
Serial.println("[E] LittleFS");
return false;
}
return true;
}
void removeFile(const String filename) {
if (!LittleFS.remove(filename)) {
Serial.printf("[E] on remove %s", filename.c_str());
}
}
File seekFile(const String filename, size_t position) {
auto file = LittleFS.open(filename, "r");
if (!file) {
Serial.printf("[E] on open %s", filename.c_str());
}
// поставим курсор в начало файла
file.seek(position, SeekSet);
return file;
}
String readFileString(const String filename, const String to_find) {
String res = "Failed";

View File

@@ -22,9 +22,9 @@ void reconfigTime() {
if (WiFi.status() == WL_CONNECTED) {
String ntp = jsonReadStr(configSetupJson, "ntp");
configTime(0, 0, ntp.c_str());
int i = 0;
Serial.println("[I] Start time sync");
Serial.println("[I] Time sync");
#ifdef ESP32
uint8_t i = 0;
struct tm timeinfo;
while (!getLocalTime(&timeinfo) && i <= 4) {
Serial.print(".");
@@ -33,6 +33,7 @@ void reconfigTime() {
}
#endif
#ifdef ESP8266
//uint8_t i = 0;
//while (!time(nullptr) && i < 4) {
// Serial.print(".");
// i++;

View File

@@ -124,7 +124,7 @@ void web_init() {
request->send(200, "text/text", "OK");
}
//--------------------------------------------------------------------------------
#ifdef logging_enable
#ifdef LOGGING_ENABLED
if (request->hasArg("cleanlog")) {
clean_log_date();
request->send(200, "text/text", "OK");
@@ -147,7 +147,7 @@ void web_init() {
}
//--------------------------------------------------------------------------------
if (request->hasArg("updatelist")) {
LittleFS.remove("/dev.csv");
removeFile("/dev.csv");
addFile("dev.csv", "device id;device name;ip address");
request->redirect("/?set.udp");
}
@@ -270,7 +270,7 @@ void web_init() {
request->send(200, "text/text", tmp);
}
//==============================push settings=============================================
#ifdef push_enable
#ifdef PUSH_ENABLED
if (request->hasArg("pushingboxid")) {
jsonWriteStr(configSetupJson, "pushingboxid", request->getParam("pushingboxid")->value());
saveConfig();
@@ -292,10 +292,10 @@ void web_init() {
int case_of_update;
if (WiFi.status() != WL_CONNECTED) last_version = "nowifi";
if (!mb_4_of_memory) last_version = "less";
if (!FLASH_4MB) last_version = "less";
if (last_version == firmware_version) case_of_update = 1;
if (last_version != firmware_version) case_of_update = 2;
if (last_version == FIRMWARE_VERSION) case_of_update = 1;
if (last_version != FIRMWARE_VERSION) case_of_update = 2;
if (last_version == "error") case_of_update = 3;
if (last_version == "") case_of_update = 4;
if (last_version == "less") case_of_update = 5;

View File

@@ -1,10 +1,12 @@
#include "Global.h"
#include "Utils/FileUtils.h"
void Web_server_init() {
/*********************************************************************************
***************************************OTA****************************************
*********************************************************************************/
#ifdef OTA_enable
#ifdef OTA_UPDATES_ENABLED
ArduinoOTA.onStart([]() {
events.send("Update Start", "ota");
});
@@ -34,7 +36,7 @@ void Web_server_init() {
/*********************************************************************************
**************************************MDNS****************************************
*********************************************************************************/
#ifdef MDNS_enable
#ifdef MDNS_ENABLED
MDNS.addService("http", "tcp", 80);
#endif
//LittleFS.begin();
@@ -55,6 +57,7 @@ void Web_server_init() {
**************************************WEB****************************************
*********************************************************************************/
#ifdef ESP32
server.addHandler(new SPIFFSEditor(LittleFS, jsonReadStr(configSetupJson, "weblogin").c_str(), jsonReadStr(configSetupJson, "webpass").c_str()));
#elif defined(ESP8266)
server.addHandler(new SPIFFSEditor(jsonReadStr(configSetupJson, "weblogin").c_str(), jsonReadStr(configSetupJson, "webpass").c_str()));

View File

@@ -63,8 +63,7 @@ bool StartAPMode() {
WiFi.softAP(_ssidAP.c_str(), _passwordAP.c_str());
IPAddress myIP = WiFi.softAPIP();
led_blink("on");
Serial.print("[I] AP IP: ");
Serial.println(myIP);
Serial.printf("[I] AP IP: %s\n", myIP.toString().c_str());
jsonWriteStr(configSetupJson, "ip", myIP.toString());
//if (jsonReadInt(configOptionJson, "pass_status") != 1) {
@@ -89,7 +88,7 @@ boolean RouterFind(String ssid) {
Serial.printf("[I][WIFI] scan result = %d\n", n);
if (n == -2) {
// не было запущено, запускаем
Serial.println("[I][WIFI] scanning has not been triggered, start scanning");
Serial.println("[I][WIFI] start scanning");
// async, show_hidden
WiFi.scanNetworks(true, false);
} else if (n == -1) {

View File

@@ -18,7 +18,7 @@ void createWidget (String widget_name, String page_name, String page_number, St
jsonWriteStr(widget, "descr", widget_name);
jsonWriteStr(widget, "topic", prex + "/" + topic);
#ifdef layout_in_ram
#ifdef LAYOUT_IN_RAM
all_widgets += widget + "\r\n";
#else
addFile("layout.txt", widget);
@@ -46,7 +46,7 @@ void createWidgetParam (String widget_name, String page_name, String page_numbe
if (name2 != "") jsonWriteStr(widget, name2, param2);
if (name3 != "") jsonWriteStr(widget, name3, param3);
#ifdef layout_in_ram
#ifdef LAYOUT_IN_RAM
all_widgets += widget + "\r\n";
#else
addFile("layout.txt", widget);
@@ -72,7 +72,7 @@ void createChart (String widget_name, String page_name, String page_number, Str
jsonWriteStr(widget, "maxCount", maxCount);
jsonWriteStr(widget, "topic", prex + "/" + topic);
#ifdef layout_in_ram
#ifdef LAYOUT_IN_RAM
all_widgets += widget + "\r\n";
#else
addFile("layout.txt", widget);

View File

@@ -10,7 +10,7 @@ void setup() {
setChipId();
File_system_init();
fileSystemInit();
Serial.println("[V] LittleFS");
CMD_init();
@@ -40,14 +40,14 @@ void setup() {
Time_Init();
Serial.println("[V] Time_Init");
#ifdef UDP_enable
#ifdef UDP_ENABLED
UDP_init();
Serial.println("[V] UDP_init");
#endif
ts.add(
TEST, 10000, [&](void*) {
getMemoryLoad("[I] sysinfo ");
printMemoryStatus("[I] sysinfo ");
},
nullptr, true);
@@ -55,7 +55,7 @@ void setup() {
}
void loop() {
#ifdef OTA_enable
#ifdef OTA_UPDATES_ENABLED
ArduinoOTA.handle();
#endif
@@ -69,7 +69,7 @@ void loop() {
handleCMD_loop();
handleButton();
handleScenario();
#ifdef UDP_enable
#ifdef UDP_ENABLED
handleUdp();
#endif
ts.update();
@@ -79,7 +79,7 @@ void not_async_actions() {
do_mqtt_connection();
do_upgrade_url();
do_upgrade();
#ifdef UDP_enable
#ifdef UDP_ENABLED
do_udp_data_parse();
do_mqtt_send_settings_to_udp();
#endif

View File

@@ -50,17 +50,17 @@ void sendCONFIG(String topik, String widgetConfig, String key, String date) {
void led_blink(String satus) {
#ifdef ESP8266
#ifdef blink_pin
pinMode(blink_pin, OUTPUT);
pinMode(LED_PIN, OUTPUT);
if (satus == "off") {
noTone(blink_pin);
digitalWrite(blink_pin, HIGH);
noTone(LED_PIN);
digitalWrite(LED_PIN, HIGH);
}
if (satus == "on") {
noTone(blink_pin);
digitalWrite(blink_pin, LOW);
noTone(LED_PIN);
digitalWrite(LED_PIN, LOW);
}
if (satus == "slow") tone(blink_pin, 1);
if (satus == "fast") tone(blink_pin, 20);
if (satus == "slow") tone(LED_PIN, 1);
if (satus == "fast") tone(LED_PIN, 20);
#endif
#endif
}
@@ -68,7 +68,10 @@ void led_blink(String satus) {
const String getChipId() {
String res;
#ifdef ESP32
res = String(ESP.getEfuseMac());
char buf[32] = {0};
uint32_t mac = ESP.getEfuseMac();
sprintf(buf, "%0X", mac);
res = String(buf);
#endif
#ifdef ESP8266
res = String(ESP.getChipId()) + "-" + String(ESP.getFlashChipId());
@@ -81,7 +84,7 @@ void setChipId() {
Serial.println(chipId);
}
void getMemoryLoad(String text) {
void printMemoryStatus(String text) {
#ifdef ESP8266
uint32_t all_memory = 52864;
#endif

View File

@@ -18,9 +18,9 @@ unsigned int udp_port = 4210;
void handleUdp_esp32();
void add_dev_in_list(String fileName, String id, String dev_name, String ip);
#ifdef UDP_enable
#ifdef UDP_ENABLED
void UDP_init() {
LittleFS.remove("/dev.csv");
removeFile("/dev.csv");
addFile("dev.csv", "device id;device name;ip address");
#ifdef ESP8266
@@ -123,8 +123,8 @@ void do_udp_data_parse() {
}
void add_dev_in_list(String filename, String id, String dev_name, String ip) {
File configFile = LittleFS.open("/" + filename, "r");
if (!configFile.find(id.c_str())) {
auto file = seekFile("/" + filename);
if (!file.find(id.c_str())) {
addFile(filename, id + ";" + dev_name + "; <a href=\"http://" + ip + "\" target=\"_blank\"\">" + ip + "</a>");
}
}