mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-28 23:22:19 +03:00
renaming
This commit is contained in:
@@ -6,7 +6,7 @@ static const char* MODULE = "Clock";
|
||||
|
||||
void startTimeSync() {
|
||||
if (!hasTimeSynced()) {
|
||||
pm.info("Start syncing");
|
||||
pm.info("Start sync");
|
||||
reconfigTime();
|
||||
}
|
||||
}
|
||||
@@ -42,7 +42,7 @@ void reconfigTime() {
|
||||
while (!hasTimeSynced() && i < 4) {
|
||||
Serial.print(".");
|
||||
i++;
|
||||
delay(300);
|
||||
delay(30);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
57
src/Cmd.cpp
57
src/Cmd.cpp
@@ -120,13 +120,13 @@ void button() {
|
||||
|
||||
if (button_param == "scen") {
|
||||
jsonWriteStr(configSetupJson, "scen", start_state);
|
||||
Scenario_init();
|
||||
loadScenario();
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
if (button_param.indexOf("line") != -1) {
|
||||
String str = button_param;
|
||||
while (str.length() != 0) {
|
||||
while (str.length()) {
|
||||
if (str == "") return;
|
||||
String tmp = selectToMarker(str, ","); //line1,
|
||||
String number = deleteBeforeDelimiter(tmp, "e"); //1,
|
||||
@@ -137,7 +137,7 @@ void button() {
|
||||
str = deleteBeforeDelimiter(str, ",");
|
||||
}
|
||||
}
|
||||
createWidget(widget_name, page_name, page_number, "widgets/widget.toggle.json", "button" + button_number);
|
||||
createWidget(widget_name, page_name, page_number, "toggle", "button" + button_number);
|
||||
}
|
||||
|
||||
void buttonSet() {
|
||||
@@ -151,7 +151,7 @@ void buttonSet() {
|
||||
|
||||
if (button_param == "scen") {
|
||||
jsonWriteStr(configSetupJson, "scen", button_state);
|
||||
Scenario_init();
|
||||
loadScenario();
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
@@ -187,6 +187,7 @@ void buttonChange() {
|
||||
}
|
||||
order_loop += "buttonSet " + button_number + " " + current_state + ",";
|
||||
jsonWriteStr(configLiveJson, "button" + button_number, current_state);
|
||||
|
||||
MqttClient::publishStatus("button" + button_number, current_state);
|
||||
}
|
||||
|
||||
@@ -221,7 +222,7 @@ void pwm() {
|
||||
//analogWriteFreq(32000);
|
||||
jsonWriteStr(configLiveJson, "pwm" + pwm_number, start_state);
|
||||
|
||||
createWidget(widget_name, page_name, page_number, "widgets/widget.range.json", "pwm" + pwm_number);
|
||||
createWidget(widget_name, page_name, page_number, "range", "pwm" + pwm_number);
|
||||
}
|
||||
|
||||
void pwmSet() {
|
||||
@@ -290,7 +291,7 @@ void inputDigit() {
|
||||
String start_state = sCmd.next();
|
||||
String page_number = sCmd.next();
|
||||
jsonWriteStr(configLiveJson, "digit" + number, start_state);
|
||||
createWidget(widget_name, page_name, page_number, "widgets/widget.inputNum.json", "digit" + number);
|
||||
createWidget(widget_name, page_name, page_number, "inputNum", "digit" + number);
|
||||
}
|
||||
|
||||
void digitSet() {
|
||||
@@ -312,7 +313,7 @@ void inputTime() {
|
||||
String start_state = sCmd.next();
|
||||
String page_number = sCmd.next();
|
||||
jsonWriteStr(configLiveJson, "time" + number, start_state);
|
||||
createWidget(widget_name, page_name, page_number, "widgets/widget.inputTime.json", "time" + number);
|
||||
createWidget(widget_name, page_name, page_number, "inputTime", "time" + number);
|
||||
}
|
||||
|
||||
void timeSet() {
|
||||
@@ -342,7 +343,7 @@ void text() {
|
||||
String page_name = sCmd.next();
|
||||
String page_number = sCmd.next();
|
||||
|
||||
createWidget(widget_name, page_name, page_number, "widgets/widget.anyData.json", "text" + number);
|
||||
createWidget(widget_name, page_name, page_number, "anydata", "text" + number);
|
||||
}
|
||||
|
||||
void textSet() {
|
||||
@@ -475,7 +476,7 @@ void servo_() {
|
||||
|
||||
jsonWriteStr(configLiveJson, "servo" + servo_number, start_state);
|
||||
|
||||
createWidgetParam(widget_name, page_name, page_number, "widgets/widget.range.json", "servo" + servo_number, "min", min_value, "max", max_value, "k", "1");
|
||||
createWidgetParam(widget_name, page_name, page_number, "range", "servo" + servo_number, "min", min_value, "max", max_value, "k", "1");
|
||||
}
|
||||
|
||||
void servoSet() {
|
||||
@@ -580,7 +581,7 @@ void firmwareVersion() {
|
||||
String page_name = sCmd.next();
|
||||
String page_number = sCmd.next();
|
||||
jsonWriteStr(configLiveJson, "firmver", FIRMWARE_VERSION);
|
||||
createWidgetByType(widget_name, page_name, page_number, "any-data", "firmver");
|
||||
createWidgetByType(widget_name, page_name, page_number, "anydata", "firmver");
|
||||
}
|
||||
|
||||
void addCommandLoop(const String &cmdStr) {
|
||||
@@ -599,30 +600,28 @@ void loopCmd() {
|
||||
}
|
||||
}
|
||||
|
||||
void txtExecution(String file) {
|
||||
String command_all = readFile(file, 2048) + "\r\n";
|
||||
void fileExecute(const String &filename) {
|
||||
String cmdStr = readFile(filename, 2048);
|
||||
cmdStr += "\r\n";
|
||||
cmdStr.replace("\r\n", "\n");
|
||||
cmdStr.replace("\r", "\n");
|
||||
|
||||
command_all.replace("\r\n", "\n");
|
||||
command_all.replace("\r", "\n");
|
||||
|
||||
while (command_all.length() != 0) {
|
||||
String tmp = selectToMarker(command_all, "\n");
|
||||
sCmd.readStr(tmp);
|
||||
command_all = deleteBeforeDelimiter(command_all, "\n");
|
||||
while (cmdStr.length() != 0) {
|
||||
String buf = selectToMarker(cmdStr, "\n");
|
||||
sCmd.readStr(buf);
|
||||
cmdStr = deleteBeforeDelimiter(cmdStr, "\n");
|
||||
}
|
||||
command_all = "";
|
||||
}
|
||||
|
||||
void stringExecution(String str) {
|
||||
str = str + "\r\n";
|
||||
void stringExecute(String &cmdStr) {
|
||||
cmdStr = cmdStr + "\r\n";
|
||||
|
||||
str.replace("\r\n", "\n");
|
||||
str.replace("\r", "\n");
|
||||
cmdStr.replace("\r\n", "\n");
|
||||
cmdStr.replace("\r", "\n");
|
||||
|
||||
while (str.length() != 0) {
|
||||
String tmp = selectToMarker(str, "\n");
|
||||
sCmd.readStr(tmp);
|
||||
|
||||
str = deleteBeforeDelimiter(str, "\n");
|
||||
while (cmdStr.length()) {
|
||||
String buf = selectToMarker(cmdStr, "\n");
|
||||
sCmd.readStr(buf);
|
||||
cmdStr = deleteBeforeDelimiter(cmdStr, "\n");
|
||||
}
|
||||
}
|
||||
@@ -17,8 +17,6 @@ AsyncWebServer server(80);
|
||||
|
||||
DallasTemperature sensors;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Global vars
|
||||
*/
|
||||
@@ -73,3 +71,4 @@ boolean mqttParamsChanged = false;
|
||||
boolean udp_data_parse = false;
|
||||
boolean mqtt_send_settings_to_udp = false;
|
||||
boolean i2c_scanning = false;
|
||||
boolean fscheck_flag = false;
|
||||
|
||||
15
src/Init.cpp
15
src/Init.cpp
@@ -19,7 +19,7 @@ void loadConfig() {
|
||||
|
||||
void All_init() {
|
||||
Device_init();
|
||||
Scenario_init();
|
||||
loadScenario();
|
||||
Timer_countdown_init();
|
||||
}
|
||||
|
||||
@@ -57,17 +57,17 @@ void Device_init() {
|
||||
#ifdef LAYOUT_IN_RAM
|
||||
all_widgets = "";
|
||||
#else
|
||||
removeFile("/layout.txt");
|
||||
removeFile(String("layout.txt"));
|
||||
#endif
|
||||
|
||||
txtExecution("100с.txt");
|
||||
fileExecute(String(DEVICE_CONFIG_FILE));
|
||||
//outcoming_date();
|
||||
}
|
||||
//-------------------------------сценарии-----------------------------------------------------
|
||||
|
||||
void Scenario_init() {
|
||||
void loadScenario() {
|
||||
if (jsonReadStr(configSetupJson, "scen") == "1") {
|
||||
scenario = readFile("100s.txt", 2048);
|
||||
scenario = readFile(String(DEVICE_SCENARIO_FILE), 2048);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,20 +107,15 @@ void handle_statistics() {
|
||||
urls += "iot-manager_esp32";
|
||||
#endif
|
||||
urls += "&";
|
||||
//-----------------------------------------------------------------
|
||||
#ifdef ESP8266
|
||||
urls += ESP.getResetReason();
|
||||
//Serial.println(ESP.getResetReason());
|
||||
#endif
|
||||
#ifdef ESP32
|
||||
urls += "Power on";
|
||||
#endif
|
||||
urls += "&";
|
||||
//-----------------------------------------------------------------
|
||||
urls += "ver: ";
|
||||
urls += String(FIRMWARE_VERSION);
|
||||
//-----------------------------------------------------------------
|
||||
String stat = getURL(urls);
|
||||
//Serial.println(stat);
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,8 @@
|
||||
|
||||
void sendLogData(String file, String topic);
|
||||
|
||||
static const char* MODULE = "Log";
|
||||
|
||||
#ifdef LOGGING_ENABLED
|
||||
//===============================================Логирование============================================================
|
||||
//logging temp1 1 10 Температура Датчики 2
|
||||
@@ -17,15 +19,18 @@ void logging() {
|
||||
String page_name = sCmd.next();
|
||||
String page_number = sCmd.next();
|
||||
logging_value_names_list += value_name + ",";
|
||||
enter_to_logging_counter++; //считаем количество входов в эту функцию
|
||||
jsonWriteStr(configOptionJson, value_name + "_c", maxCount); //создаем в файловой системе переменную количества точек на графике с отметкой _c что значит count
|
||||
createChart(widget_name, page_name, page_number, "widgets/widget.chart.json", value_name + "_ch", maxCount); //создаем график в приложении с топиком _ch /prefix/3234045-1589487/value_name_ch
|
||||
enter_to_logging_counter++; //считаем количество входов в эту функцию
|
||||
jsonWriteStr(configOptionJson, value_name + "_c", maxCount); //создаем в файловой системе переменную количества точек на графике с отметкой _c что значит count
|
||||
|
||||
//создаем график в приложении с топиком _ch /prefix/3234045-1589487/value_name_ch
|
||||
createChart(widget_name, page_name, page_number, "chart", value_name + "_ch", maxCount);
|
||||
|
||||
if (enter_to_logging_counter == LOG1) {
|
||||
ts.add(
|
||||
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");
|
||||
pm.info("logging for " + tmp_buf_1 + " done");
|
||||
},
|
||||
nullptr, false);
|
||||
}
|
||||
@@ -34,7 +39,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");
|
||||
pm.info("logging for " + tmp_buf_2 + " done");
|
||||
},
|
||||
nullptr, false);
|
||||
}
|
||||
@@ -43,7 +48,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");
|
||||
pm.info("logging for " + tmp_buf_3 + " done");
|
||||
},
|
||||
nullptr, false);
|
||||
}
|
||||
@@ -52,7 +57,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");
|
||||
pm.info("logging for " + tmp_buf_4 + " done");
|
||||
},
|
||||
nullptr, false);
|
||||
}
|
||||
@@ -61,7 +66,7 @@ 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");
|
||||
pm.info("logging for " + tmp_buf_5 + " done");
|
||||
},
|
||||
nullptr, false);
|
||||
}
|
||||
@@ -74,10 +79,10 @@ void deleteOldDate(const String filename, size_t max_lines_cnt, String date_to_a
|
||||
String log_date = readFile(filename, 5120);
|
||||
size_t lines_cnt = itemsCount(log_date, "\r\n");
|
||||
|
||||
Serial.printf("[I] log %s (%d lines)\n", filename.c_str(), lines_cnt);
|
||||
pm.info("log " + filename + " (" + String(lines_cnt, DEC) + ")");
|
||||
|
||||
if ((lines_cnt > max_lines_cnt + 1) || !lines_cnt) {
|
||||
removeFile("/" + filename);
|
||||
removeFile(filename);
|
||||
lines_cnt = 0;
|
||||
}
|
||||
|
||||
@@ -92,7 +97,6 @@ void deleteOldDate(const String filename, size_t max_lines_cnt, String date_to_a
|
||||
addFile(filename, getTimeUnix() + " " + date_to_add);
|
||||
}
|
||||
}
|
||||
log_date = "";
|
||||
}
|
||||
|
||||
//=========================================Выбор какие данные отправлять==================================================================
|
||||
@@ -103,19 +107,18 @@ void choose_log_date_and_send() {
|
||||
sendLogData("log." + tmp + ".txt", tmp + "_ch");
|
||||
all_line = deleteBeforeDelimiter(all_line, ",");
|
||||
}
|
||||
all_line = "";
|
||||
}
|
||||
//=========================================Отправка данных===================================================================================
|
||||
void sendLogData(String file, String topic) {
|
||||
String log_date = readFile(file, 5000);
|
||||
if (log_date != "Failed") {
|
||||
String log_date = readFile(file, 5120);
|
||||
if (log_date != "failed") {
|
||||
log_date.replace("\r\n", "\n");
|
||||
log_date.replace("\r", "\n");
|
||||
String buf = "{}";
|
||||
String json_array;
|
||||
String unix_time;
|
||||
String value;
|
||||
while (log_date.length() != 0) {
|
||||
while (log_date.length()) {
|
||||
String tmp = selectToMarker(log_date, "\n");
|
||||
log_date = deleteBeforeDelimiter(log_date, "\n");
|
||||
unix_time = selectToMarker(tmp, " ");
|
||||
@@ -133,40 +136,18 @@ void sendLogData(String file, String topic) {
|
||||
value = "";
|
||||
log_date = "";
|
||||
json_array = "{\"status\":[" + json_array + "]}";
|
||||
Serial.println(json_array);
|
||||
|
||||
pm.info(json_array);
|
||||
|
||||
MqttClient::publishChart(topic, json_array);
|
||||
json_array = "";
|
||||
printMemoryStatus("[I] send log date");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
//----------------------------------------------
|
||||
File configFile = SPIFFS.open("/" + file, "r");
|
||||
if (!configFile) {
|
||||
return;
|
||||
}
|
||||
configFile.seek(0, SeekSet); //поставим курсор в начало файла
|
||||
while (configFile.position() != configFile.size()) {
|
||||
String tmp = configFile.readStringUntil('\r\n');
|
||||
String unix_time = selectToMarker (tmp, " ");
|
||||
String value = deleteBeforeDelimiter(tmp, " ");
|
||||
String final_line = "{\"status\":{\"x\":" + unix_time + ",\"y1\":" + value + "}}";
|
||||
//Serial.println(final_line);
|
||||
sendCHART(topic, final_line);
|
||||
}
|
||||
getMemoryLoad("[I] after send log date");
|
||||
*/
|
||||
|
||||
//=========================================Очистка данных===================================================================================
|
||||
void clean_log_date() {
|
||||
String all_line = logging_value_names_list;
|
||||
while (all_line.length() != 0) {
|
||||
while (all_line.length()) {
|
||||
String tmp = selectToMarker(all_line, ",");
|
||||
removeFile("/log." + tmp + ".txt");
|
||||
removeFile("log." + tmp + ".txt");
|
||||
all_line = deleteBeforeDelimiter(all_line, ",");
|
||||
}
|
||||
all_line = "";
|
||||
}
|
||||
#endif
|
||||
@@ -29,7 +29,7 @@ void init() {
|
||||
if (!just_load) mqtt_lost_error++;
|
||||
}
|
||||
} else {
|
||||
pm.error("WiFi connection lost");
|
||||
pm.error("connection lost");
|
||||
ts.remove(WIFI_MQTT_CONNECTION_CHECK);
|
||||
wifi_lost_error++;
|
||||
startAPMode();
|
||||
@@ -86,7 +86,7 @@ boolean connect() {
|
||||
mqttRootDevice = mqttPrefix + "/" + chipId;
|
||||
|
||||
pm.info("broker " + addr + ":" + String(port, DEC));
|
||||
pm.info("root " + mqttRootDevice);
|
||||
pm.info("topic " + mqttRootDevice);
|
||||
|
||||
setLedStatus(LED_FAST);
|
||||
mqtt.setServer(addr.c_str(), port);
|
||||
@@ -115,10 +115,8 @@ void handleSubscribedUpdates(char* topic, uint8_t* payload, size_t length) {
|
||||
payloadStr += (char)payload[i];
|
||||
}
|
||||
pm.info(payloadStr);
|
||||
|
||||
if (payloadStr == "HELLO") {
|
||||
//данные которые отправляем при подключении или отбновлении страницы
|
||||
pm.info("Send web page updates");
|
||||
if (payloadStr.startsWith("HELLO")) {
|
||||
pm.info("Full update");
|
||||
publishWidgets();
|
||||
publishState();
|
||||
#ifdef LOGGING_ENABLED
|
||||
@@ -148,11 +146,11 @@ void handleSubscribedUpdates(char* topic, uint8_t* payload, size_t length) {
|
||||
upgrade = true;
|
||||
}
|
||||
} else if (topicStr.indexOf("devc")) {
|
||||
writeFile("100с.txt", payloadStr);
|
||||
writeFile(String(DEVICE_CONFIG_FILE), payloadStr);
|
||||
Device_init();
|
||||
} else if (topicStr.indexOf("devs")) {
|
||||
writeFile("100s.txt", payloadStr);
|
||||
Scenario_init();
|
||||
writeFile(String(DEVICE_SCENARIO_FILE), payloadStr);
|
||||
loadScenario();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -225,13 +223,14 @@ void publishWidgets() {
|
||||
|
||||
#ifndef LAYOUT_IN_RAM
|
||||
void publishWidgets() {
|
||||
auto file = seekFile("/layout.txt");
|
||||
auto file = seekFile("layout.txt");
|
||||
if (!file) {
|
||||
pm.error("on seek layout.txt");
|
||||
return;
|
||||
}
|
||||
while (file.position() != file.size()) {
|
||||
while (file.available()) {
|
||||
String payload = file.readStringUntil('\n');
|
||||
pm.info("publish: " + payload);
|
||||
pm.info("widgets: " + payload);
|
||||
publishData("config", payload);
|
||||
}
|
||||
file.close();
|
||||
@@ -243,14 +242,13 @@ void publishState() {
|
||||
// {"name":"MODULES","lang":"","ip":"192.168.43.60","DS":"34.00","rel1":"1","rel2":"1"}
|
||||
// "name":"MODULES","lang":"","ip":"192.168.43.60","DS":"34.00","rel1":"1","rel2":"1"
|
||||
// "name":"MODULES","lang":"","ip":"192.168.43.60","DS":"34.00","rel1":"1","rel2":"1",
|
||||
String current_config = configLiveJson;
|
||||
printMemoryStatus("[I] after send all date");
|
||||
current_config.replace("{", "");
|
||||
current_config.replace("}", "");
|
||||
current_config += ",";
|
||||
String str = configLiveJson;
|
||||
str.replace("{", "");
|
||||
str.replace("}", "");
|
||||
str += ",";
|
||||
|
||||
while (current_config.length()) {
|
||||
String tmp = selectToMarker(current_config, ",");
|
||||
while (str.length()) {
|
||||
String tmp = selectToMarker(str, ",");
|
||||
|
||||
String topic = selectToMarker(tmp, ":");
|
||||
topic.replace("\"", "");
|
||||
@@ -261,7 +259,7 @@ void publishState() {
|
||||
if (topic != "name" && topic != "lang" && topic != "ip" && topic.indexOf("_in") < 0) {
|
||||
publishStatus(topic, state);
|
||||
}
|
||||
current_config = deleteBeforeDelimiter(current_config, ",");
|
||||
str = deleteBeforeDelimiter(str, ",");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ void loopScenario() {
|
||||
|
||||
if (flag) {
|
||||
tmp = deleteBeforeDelimiter(tmp, "\n"); //удаляем строку самого сценария оставляя только команды
|
||||
stringExecution(tmp); //выполняем все команды
|
||||
stringExecute(tmp); //выполняем все команды
|
||||
|
||||
Serial.println("[SCENARIO] '" + condition + "'");
|
||||
//Serial.println(" " + tmp);
|
||||
|
||||
@@ -81,7 +81,7 @@ void sensors_init() {
|
||||
//=========================================================================================================================================
|
||||
//=========================================Модуль измерения уровня в баке==================================================================
|
||||
#ifdef LEVEL_ENABLED
|
||||
//levelPr p 14 12 Вода#в#баке,#% Датчики fill-gauge 125 20 1
|
||||
//levelPr p 14 12 Вода#в#баке,#% Датчики fillgauge 125 20 1
|
||||
void levelPr() {
|
||||
String value_name = sCmd.next();
|
||||
String trig = sCmd.next();
|
||||
@@ -102,7 +102,7 @@ void levelPr() {
|
||||
createWidgetByType(widget_name, page_name, page_number, type, value_name);
|
||||
sensors_reading_map[0] = 1;
|
||||
}
|
||||
//ultrasonicCm cm 14 12 Дистанция,#см Датчики fill-gauge 1
|
||||
//ultrasonicCm cm 14 12 Дистанция,#см Датчики fillgauge 1
|
||||
void ultrasonicCm() {
|
||||
String value_name = sCmd.next();
|
||||
String trig = sCmd.next();
|
||||
@@ -399,7 +399,7 @@ void dhtC() {
|
||||
String widget_name = sCmd.next();
|
||||
String page_name = sCmd.next();
|
||||
String page_number = sCmd.next();
|
||||
createWidgetByType(widget_name, page_name, page_number, "any-data", "dhtComfort");
|
||||
createWidgetByType(widget_name, page_name, page_number, "anydata", "dhtComfort");
|
||||
sensors_reading_map[7] = 1;
|
||||
}
|
||||
|
||||
@@ -459,7 +459,7 @@ void dhtD() {
|
||||
String widget_name = sCmd.next();
|
||||
String page_name = sCmd.next();
|
||||
String page_number = sCmd.next();
|
||||
createWidgetByType(widget_name, page_name, page_number, "any-data", "dhtDewpoint");
|
||||
createWidgetByType(widget_name, page_name, page_number, "anydata", "dhtDewpoint");
|
||||
sensors_reading_map[8] = 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "Global.h"
|
||||
|
||||
void init_updater() {
|
||||
#ifdef ESP8266
|
||||
if (WiFi.status() == WL_CONNECTED) last_version = getURL("http://91.204.228.124:1100/update/esp8266/version.txt");
|
||||
@@ -28,8 +29,9 @@ void upgrade_firmware() {
|
||||
String scenario_for_update;
|
||||
String config_for_update;
|
||||
String configSetup_for_update;
|
||||
scenario_for_update = readFile("100s.txt", 4000);
|
||||
config_for_update = readFile("100с.txt", 4000);
|
||||
|
||||
scenario_for_update = readFile(String(DEVICE_SCENARIO_FILE), 4000);
|
||||
config_for_update = readFile(String(DEVICE_CONFIG_FILE), 4000);
|
||||
configSetup_for_update = configSetupJson;
|
||||
|
||||
Serial.println("Start upgrade SPIFFS, please wait...");
|
||||
@@ -46,8 +48,8 @@ void upgrade_firmware() {
|
||||
#endif
|
||||
|
||||
if (ret == HTTP_UPDATE_OK) {
|
||||
writeFile("100s.txt", scenario_for_update);
|
||||
writeFile("100с.txt", config_for_update);
|
||||
writeFile(String(DEVICE_SCENARIO_FILE), scenario_for_update);
|
||||
writeFile(String(DEVICE_CONFIG_FILE), config_for_update);
|
||||
writeFile("config.json", configSetup_for_update);
|
||||
saveConfig();
|
||||
|
||||
|
||||
@@ -15,27 +15,34 @@ bool fileSystemInit() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void removeFile(const String filename) {
|
||||
if (!LittleFS.remove(filepath(filename))) {
|
||||
pm.error("remove " + filename);
|
||||
void removeFile(const String& filename) {
|
||||
String path = filepath(filename);
|
||||
if (LittleFS.exists(path)) {
|
||||
if (!LittleFS.remove(path)) {
|
||||
pm.error("remove " + path);
|
||||
}
|
||||
} else {
|
||||
pm.info("not exist" + path);
|
||||
}
|
||||
}
|
||||
|
||||
File seekFile(const String filename, size_t position) {
|
||||
auto file = LittleFS.open(filepath(filename), "r");
|
||||
File seekFile(const String& filename, size_t position) {
|
||||
String path = filepath(filename);
|
||||
auto file = LittleFS.open(path, "r");
|
||||
if (!file) {
|
||||
pm.error("open " + filename);
|
||||
pm.error("open " + path);
|
||||
}
|
||||
// поставим курсор в начало файла
|
||||
file.seek(position, SeekSet);
|
||||
return file;
|
||||
}
|
||||
|
||||
String readFileString(const String filename, const String to_find) {
|
||||
String res = "Failed";
|
||||
auto file = LittleFS.open(filepath(filename), "r");
|
||||
const String readFileString(const String& filename, const String& to_find) {
|
||||
String path = filepath(filename);
|
||||
String res = "failed";
|
||||
auto file = LittleFS.open(path, "r");
|
||||
if (!file) {
|
||||
return "Failed";
|
||||
return "failed";
|
||||
}
|
||||
if (file.find(to_find.c_str())) {
|
||||
res = file.readStringUntil('\n');
|
||||
@@ -44,19 +51,21 @@ String readFileString(const String filename, const String to_find) {
|
||||
return res;
|
||||
}
|
||||
|
||||
String addFile(const String filename, const String str) {
|
||||
auto file = LittleFS.open(filepath(filename), "a");
|
||||
const String addFile(const String& filename, const String& str) {
|
||||
String path = filepath(filename);
|
||||
auto file = LittleFS.open(path, "a");
|
||||
if (!file) {
|
||||
return "Failed";
|
||||
return "failed";
|
||||
}
|
||||
file.println(str);
|
||||
file.close();
|
||||
return "Sucсess";
|
||||
return "sucсess";
|
||||
}
|
||||
|
||||
bool copyFile(const String src, const String dst, bool overwrite) {
|
||||
bool copyFile(const String& src, const String& dst, bool overwrite) {
|
||||
String srcPath = filepath(src);
|
||||
String dstPath = filepath(dst);
|
||||
pm.info("copy " + srcPath + " to " + dstPath);
|
||||
if (!LittleFS.exists(srcPath)) {
|
||||
pm.error("not exist: " + srcPath);
|
||||
return false;
|
||||
@@ -81,35 +90,37 @@ bool copyFile(const String src, const String dst, bool overwrite) {
|
||||
return true;
|
||||
}
|
||||
|
||||
String writeFile(const String filename, const String str) {
|
||||
auto file = LittleFS.open(filepath(filename), "w");
|
||||
const String writeFile(const String& filename, const String& str) {
|
||||
String path = filepath(filename);
|
||||
auto file = LittleFS.open(path, "w");
|
||||
if (!file) {
|
||||
return "Failed";
|
||||
return "failed";
|
||||
}
|
||||
file.print(str);
|
||||
file.close();
|
||||
return "Sucсess";
|
||||
return "sucсess";
|
||||
}
|
||||
|
||||
String readFile(const String filename, size_t max_size) {
|
||||
auto file = LittleFS.open(filepath(filename), "r");
|
||||
const String readFile(const String& filename, size_t max_size) {
|
||||
String path = filepath(filename);
|
||||
auto file = LittleFS.open(path, "r");
|
||||
if (!file) {
|
||||
return "Failed";
|
||||
return "failed";
|
||||
}
|
||||
size_t size = file.size();
|
||||
if (size > max_size) {
|
||||
file.close();
|
||||
return "Large";
|
||||
return "large";
|
||||
}
|
||||
String temp = file.readString();
|
||||
file.close();
|
||||
return temp;
|
||||
}
|
||||
|
||||
String getFileSize(const String filename) {
|
||||
const String getFileSize(const String filename) {
|
||||
auto file = LittleFS.open(filepath(filename), "r");
|
||||
if (!file) {
|
||||
return "Failed";
|
||||
return "failed";
|
||||
}
|
||||
size_t size = file.size();
|
||||
file.close();
|
||||
|
||||
@@ -1,54 +1,9 @@
|
||||
#include "Utils/PresetUtils.h"
|
||||
|
||||
static const char* item_names[NUM_ITEMS] = {"relay", "pwm",
|
||||
"dht11", "dht22", "analog",
|
||||
"bmp280", "bme280", "dallas",
|
||||
"termostat", "ultrasonic",
|
||||
"motion", "stepper",
|
||||
"servo", "firmware"};
|
||||
static const char* config_file_fmt PROGMEM = "/conf/%s%03d.txt";
|
||||
|
||||
static const char* config_file_fmt = "/conf/%03d%s.txt";
|
||||
|
||||
const String getPresetFile(uint8_t preset, ConfigType_t type) {
|
||||
const String getConfigFile(uint8_t preset, ConfigType_t type) {
|
||||
char buf[64];
|
||||
sprintf(buf, config_file_fmt, preset, type == CT_MACRO ? "c" : "s");
|
||||
sprintf_P(buf, config_file_fmt, (type == CT_CONFIG) ? "c" : "s", preset);
|
||||
return String(buf);
|
||||
}
|
||||
|
||||
const String getItemName(Item_t item) {
|
||||
return String(item_names[item]);
|
||||
}
|
||||
|
||||
const Item_t getPresetItem(uint8_t num) {
|
||||
Item_t res = NUM_ITEMS;
|
||||
if (num >= 1 && num <= 7) {
|
||||
res = RELAY;
|
||||
} else if (num == 8) {
|
||||
res = PWM;
|
||||
} else if (num == 9) {
|
||||
res = DHT11;
|
||||
} else if (num == 10) {
|
||||
res = DHT22;
|
||||
} else if (num == 11) {
|
||||
res = ANALOG;
|
||||
} else if (num == 12) {
|
||||
res = BMP280;
|
||||
} else if (num == 13) {
|
||||
res = BME280;
|
||||
} else if (num == 14) {
|
||||
res = DALLAS;
|
||||
} else if (num == 15) {
|
||||
res = TERMOSTAT;
|
||||
} else if (num == 16) {
|
||||
res = ULTRASONIC;
|
||||
} else if (num >= 17 || num <= 18) {
|
||||
res = MOTION;
|
||||
} else if (num == 19) {
|
||||
res = STEPPER;
|
||||
} else if (num == 20) {
|
||||
res = SERVO;
|
||||
} else if (num == 21) {
|
||||
res = FIRMWARE;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
@@ -28,7 +28,7 @@ time_t getSystemTime() {
|
||||
}
|
||||
|
||||
bool hasTimeSynced() {
|
||||
time_t now = time(nullptr);
|
||||
unsigned long now = time(nullptr);
|
||||
return now > millis();
|
||||
}
|
||||
|
||||
|
||||
30
src/Utils/i2c_bus.cpp
Normal file
30
src/Utils/i2c_bus.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
#include "Utils/i2c_bus.h"
|
||||
|
||||
#include "Global.h"
|
||||
|
||||
void do_i2c_scanning() {
|
||||
String tmp = i2c_scan();
|
||||
if (tmp == "error") {
|
||||
tmp = i2c_scan();
|
||||
}
|
||||
jsonWriteStr(configLiveJson, "i2c", tmp);
|
||||
}
|
||||
|
||||
const String i2c_scan() {
|
||||
String out;
|
||||
byte count = 0;
|
||||
Wire.begin();
|
||||
for (byte i = 8; i < 120; i++) {
|
||||
Wire.beginTransmission(i);
|
||||
if (Wire.endTransmission() == 0) {
|
||||
count++;
|
||||
out += String(count) + ". 0x" + String(i, HEX) + "; ";
|
||||
delay(1);
|
||||
}
|
||||
}
|
||||
if (count == 0) {
|
||||
return "error";
|
||||
} else {
|
||||
return out;
|
||||
}
|
||||
}
|
||||
31
src/Web.cpp
31
src/Web.cpp
@@ -11,7 +11,7 @@ static const uint8_t MAX_PRESET = 21;
|
||||
bool parseRequestForPreset(AsyncWebServerRequest* request, uint8_t& preset) {
|
||||
if (request->hasArg("preset")) {
|
||||
preset = request->getParam("preset")->value().toInt();
|
||||
return (preset >= MIN_PRESET && preset <= MAX_PRESET) || preset == 100;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -22,15 +22,13 @@ void web_init() {
|
||||
server.on("/set", HTTP_GET, [](AsyncWebServerRequest* request) {
|
||||
uint8_t preset;
|
||||
if (parseRequestForPreset(request, preset)) {
|
||||
pm.info("activate # " + String(preset, DEC) + "(" + getItemName(getPresetItem(preset)) + ")");
|
||||
String srcMacro = preset == 21 ? "configs/100с.txt" : getPresetFile(preset, CT_MACRO);
|
||||
String srcScenario = preset == 21 ? "configs/100s.txt" : getPresetFile(preset, CT_SCENARIO);
|
||||
copyFile(srcMacro, "100с.txt");
|
||||
copyFile(srcScenario, "100s.txt");
|
||||
|
||||
pm.info("activate #" + String(preset, DEC));
|
||||
String configFile = DEVICE_CONFIG_FILE;
|
||||
String scenarioFile = DEVICE_SCENARIO_FILE;
|
||||
copyFile(getConfigFile(preset, CT_CONFIG), configFile);
|
||||
copyFile(getConfigFile(preset, CT_SCENARIO), scenarioFile);
|
||||
Device_init();
|
||||
Scenario_init();
|
||||
|
||||
loadScenario();
|
||||
request->redirect("/?set.device");
|
||||
}
|
||||
|
||||
@@ -45,18 +43,18 @@ void web_init() {
|
||||
if (value == "0") {
|
||||
jsonWriteStr(configSetupJson, "scen", value);
|
||||
saveConfig();
|
||||
Scenario_init();
|
||||
loadScenario();
|
||||
}
|
||||
if (value == "1") {
|
||||
jsonWriteStr(configSetupJson, "scen", value);
|
||||
saveConfig();
|
||||
Scenario_init();
|
||||
loadScenario();
|
||||
}
|
||||
request->send(200, "text/text", "OK");
|
||||
}
|
||||
//--------------------------------------------------------------------------------
|
||||
if (request->hasArg("sceninit")) {
|
||||
Scenario_init();
|
||||
loadScenario();
|
||||
request->send(200, "text/text", "OK");
|
||||
}
|
||||
//--------------------------------------------------------------------------------
|
||||
@@ -72,12 +70,12 @@ void web_init() {
|
||||
if (value == "0") {
|
||||
jsonWriteStr(configSetupJson, "udponoff", value);
|
||||
saveConfig();
|
||||
Scenario_init();
|
||||
loadScenario();
|
||||
}
|
||||
if (value == "1") {
|
||||
jsonWriteStr(configSetupJson, "udponoff", value);
|
||||
saveConfig();
|
||||
Scenario_init();
|
||||
loadScenario();
|
||||
}
|
||||
request->send(200, "text/text", "OK");
|
||||
}
|
||||
@@ -222,6 +220,11 @@ void web_init() {
|
||||
i2c_scanning = true;
|
||||
request->redirect("/?set.utilities");
|
||||
}
|
||||
|
||||
if (request->hasArg("fscheck")) {
|
||||
fscheck_flag = true;
|
||||
request->redirect("/?set.utilities");
|
||||
}
|
||||
});
|
||||
//==============================upgrade settings=============================================
|
||||
server.on("/check", HTTP_GET, [](AsyncWebServerRequest* request) {
|
||||
|
||||
@@ -1,18 +1,24 @@
|
||||
#include "Global.h"
|
||||
|
||||
static const char* MODULE = "Widget";
|
||||
|
||||
const String getWidgetFile(const String& name);
|
||||
|
||||
bool loadWidget(const String filename, String& buf) {
|
||||
buf = readFile(filename, 1024);
|
||||
return !(buf == "Failed" || buf == "Large");
|
||||
bool loadWidget(const String& filename, String& buf) {
|
||||
buf = readFile(filename, 2048);
|
||||
bool res = !(buf == "Failed" || buf == "Large");
|
||||
if (!res) {
|
||||
pm.error("on load" + filename);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
void createWidget(String widget, String page, String pageNumber, String filename, String topic) {
|
||||
String buf;
|
||||
String buf = "{}";
|
||||
if (!loadWidget(filename, buf)) {
|
||||
pm.error("failed " + widget);
|
||||
return;
|
||||
}
|
||||
|
||||
widget.replace("#", " ");
|
||||
page.replace("#", " ");
|
||||
|
||||
@@ -29,7 +35,7 @@ void createWidget(String widget, String page, String pageNumber, String filename
|
||||
}
|
||||
|
||||
void createWidgetParam(String widget, String page, String pageNumber, String filename, String topic, String name1, String param1, String name2, String param2, String name3, String param3) {
|
||||
String buf;
|
||||
String buf = "";
|
||||
if (!loadWidget(filename, buf)) {
|
||||
return;
|
||||
}
|
||||
@@ -54,7 +60,7 @@ void createWidgetParam(String widget, String page, String pageNumber, String fil
|
||||
}
|
||||
|
||||
void createChart(String widget, String page, String pageNumber, String filename, String topic, String maxCount) {
|
||||
String buf;
|
||||
String buf = "";
|
||||
if (!loadWidget(filename, buf)) {
|
||||
return;
|
||||
}
|
||||
@@ -77,9 +83,11 @@ void createChart(String widget, String page, String pageNumber, String filename,
|
||||
}
|
||||
|
||||
void createWidgetByType(String widget, String page, String pageNumber, String type, String topic) {
|
||||
pm.info("create" + type);
|
||||
createWidget(widget, page, pageNumber, getWidgetFile(type), topic);
|
||||
}
|
||||
|
||||
const String getWidgetFile(const String& name) {
|
||||
return "widgets/" + name + ".json";
|
||||
pm.info("get " + name);
|
||||
return "/widgets/" + name + ".json";
|
||||
}
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
#include "Global.h"
|
||||
|
||||
void do_i2c_scanning() {
|
||||
if (i2c_scanning) {
|
||||
i2c_scanning = false;
|
||||
String tmp = i2c_scan();
|
||||
if (tmp == "error") {
|
||||
tmp = i2c_scan();
|
||||
Serial.println(tmp);
|
||||
jsonWriteStr(configLiveJson, "i2c", tmp);
|
||||
} else {
|
||||
Serial.println(tmp);
|
||||
jsonWriteStr(configLiveJson, "i2c", tmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String i2c_scan() {
|
||||
String out;
|
||||
byte count = 0;
|
||||
Wire.begin();
|
||||
for (byte i = 8; i < 120; i++) {
|
||||
Wire.beginTransmission(i);
|
||||
if (Wire.endTransmission() == 0) {
|
||||
count++;
|
||||
out += String(count) + ". 0x" + String(i, HEX) + "; ";
|
||||
delay(1);
|
||||
}
|
||||
}
|
||||
if (count == 0) {
|
||||
return "error";
|
||||
} else {
|
||||
return out;
|
||||
}
|
||||
}
|
||||
18
src/main.cpp
18
src/main.cpp
@@ -1,11 +1,15 @@
|
||||
#include "Global.h"
|
||||
|
||||
#include "HttpServer.h"
|
||||
#include "Utils/i2c_bus.h"
|
||||
|
||||
void not_async_actions();
|
||||
|
||||
static const char* MODULE = "Main";
|
||||
|
||||
void do_fscheck(String& results) {
|
||||
}
|
||||
|
||||
void setup() {
|
||||
WiFi.setAutoConnect(false);
|
||||
WiFi.persistent(false);
|
||||
@@ -73,7 +77,7 @@ void setup() {
|
||||
}
|
||||
|
||||
void saveConfig() {
|
||||
writeFile("config.json", configSetupJson);
|
||||
writeFile(String("config.json"), configSetupJson);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
@@ -114,7 +118,17 @@ void not_async_actions() {
|
||||
do_mqtt_send_settings_to_udp();
|
||||
#endif
|
||||
|
||||
do_i2c_scanning();
|
||||
if (i2c_scanning) {
|
||||
do_i2c_scanning();
|
||||
i2c_scanning = false;
|
||||
}
|
||||
|
||||
if (fscheck_flag) {
|
||||
String buf;
|
||||
do_fscheck(buf);
|
||||
jsonWriteStr(configLiveJson, "fscheck", buf);
|
||||
fscheck_flag = false;
|
||||
}
|
||||
}
|
||||
|
||||
String getURL(const String& urls) {
|
||||
|
||||
Reference in New Issue
Block a user