2021-12-22 14:49:25 +01:00
|
|
|
#include "EspFileSystem.h"
|
2022-09-15 14:02:24 +02:00
|
|
|
#include "Global.h"
|
2021-12-22 14:49:25 +01:00
|
|
|
|
|
|
|
|
bool fileSystemInit() {
|
|
|
|
|
if (!FileFS.begin()) {
|
2021-12-22 21:13:24 +01:00
|
|
|
SerialPrint(F("E"), F("FS"), F("Init ERROR, may be FS was not flashed"));
|
2021-12-22 14:49:25 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
2021-12-22 21:13:24 +01:00
|
|
|
SerialPrint(F("i"), F("FS"), F("Init completed"));
|
2021-12-22 14:49:25 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
2021-12-22 23:47:35 +01:00
|
|
|
|
|
|
|
|
void globalVarsSync() {
|
2021-12-23 17:48:01 +01:00
|
|
|
settingsFlashJson = readFile(F("settings.json"), 4096);
|
2021-12-22 23:47:35 +01:00
|
|
|
settingsFlashJson.replace("\r\n", "");
|
2022-02-03 21:37:32 +01:00
|
|
|
|
2022-10-20 00:18:41 +03:00
|
|
|
valuesFlashJson = readFile(F("values.json"), 4096);
|
|
|
|
|
valuesFlashJson.replace("\r\n", "");
|
|
|
|
|
|
2022-02-03 21:37:32 +01:00
|
|
|
mqttPrefix = jsonReadStr(settingsFlashJson, F("mqttPrefix"));
|
|
|
|
|
mqttRootDevice = mqttPrefix + "/" + chipId;
|
|
|
|
|
jsonWriteStr_(settingsFlashJson, "root", mqttRootDevice);
|
2022-02-07 16:36:29 +01:00
|
|
|
jsonWriteStr_(settingsFlashJson, "id", chipId);
|
2022-02-08 16:47:17 +01:00
|
|
|
|
2022-10-09 21:38:01 +02:00
|
|
|
// jsonWriteStr_(errorsHeapJson, "errors_", ""); //метка для парсинга удалить
|
|
|
|
|
// jsonWriteStr_(ssidListHeapJson, "ssids_", ""); //метка для парсинга удалить
|
2021-12-23 00:33:45 +01:00
|
|
|
}
|
|
|
|
|
|
2022-12-04 01:37:27 +01:00
|
|
|
//к удалению. не используется
|
2023-02-08 11:40:38 +03:00
|
|
|
// String getParamsJson() {
|
|
|
|
|
// String json;
|
|
|
|
|
// serializeJson(*getLocalItemsAsJSON(), json);
|
|
|
|
|
// jsonWriteStr_(json, "params", "");
|
|
|
|
|
// return json;
|
|
|
|
|
// }
|
2021-12-23 00:33:45 +01:00
|
|
|
|
2022-02-28 01:10:14 +01:00
|
|
|
void syncSettingsFlashJson() {
|
|
|
|
|
writeFile(F("settings.json"), settingsFlashJson);
|
2022-02-02 23:39:41 +01:00
|
|
|
}
|
|
|
|
|
|
2022-10-20 00:18:41 +03:00
|
|
|
void syncValuesFlashJson() {
|
|
|
|
|
writeFile(F("values.json"), valuesFlashJson);
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-02 23:39:41 +01:00
|
|
|
const String getChipId() {
|
|
|
|
|
return String(ESP_getChipId()) + "-" + String(ESP_getFlashChipId());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void setChipId() {
|
|
|
|
|
chipId = getChipId();
|
2022-02-16 00:53:52 +01:00
|
|
|
SerialPrint("i", "System", "id: " + chipId);
|
2022-02-02 23:39:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const String getUniqueId(const char* name) {
|
|
|
|
|
return String(name) + getMacAddress();
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-19 01:41:15 +02:00
|
|
|
const String getWebVersion() {
|
|
|
|
|
String text = readFile("/index.html", 2000);
|
|
|
|
|
text = selectFromMarkerToMarker(text, "title", 1);
|
|
|
|
|
text = selectFromMarkerToMarker(text, " ", 2);
|
|
|
|
|
text.replace("</", "");
|
2022-09-20 22:07:28 +02:00
|
|
|
text.replace(".", "");
|
2022-09-19 01:41:15 +02:00
|
|
|
return text;
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-02 23:39:41 +01:00
|
|
|
uint32_t ESP_getChipId(void) {
|
|
|
|
|
#ifdef ESP32
|
|
|
|
|
uint32_t id = 0;
|
|
|
|
|
for (uint32_t i = 0; i < 17; i = i + 8) {
|
|
|
|
|
id |= ((ESP.getEfuseMac() >> (40 - i)) & 0xff) << i;
|
|
|
|
|
}
|
|
|
|
|
return id;
|
|
|
|
|
#else
|
|
|
|
|
return ESP.getChipId();
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint32_t ESP_getFlashChipId(void) {
|
|
|
|
|
#ifdef ESP32
|
|
|
|
|
// Нет аналогичной (без доп.кода) функций в 32
|
|
|
|
|
// надо использовать другой id - варианты есть
|
|
|
|
|
return ESP_getChipId();
|
|
|
|
|
#else
|
|
|
|
|
return ESP.getFlashChipId();
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const String getMacAddress() {
|
|
|
|
|
uint8_t mac[6];
|
|
|
|
|
char buf[13] = {0};
|
|
|
|
|
#if defined(ESP8266)
|
|
|
|
|
WiFi.macAddress(mac);
|
|
|
|
|
sprintf(buf, MACSTR, MAC2STR(mac));
|
|
|
|
|
#else
|
|
|
|
|
esp_read_mac(mac, ESP_MAC_WIFI_STA);
|
|
|
|
|
sprintf(buf, MACSTR, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
|
|
|
|
#endif
|
|
|
|
|
return String(buf);
|
2021-12-22 23:47:35 +01:00
|
|
|
}
|