версия 420

This commit is contained in:
Dmitry Borisenko
2022-09-13 16:39:55 +02:00
parent cd2cebaeb8
commit 0a1d606149
12 changed files with 78 additions and 31 deletions

View File

@@ -4,6 +4,8 @@ void periodicTasksInit() {
//задачи редкого выполнения
ts.add(
PTASK, 1000 * 30, [&](void*) {
// fs
getFSInfo();
// heap
String heap = prettyBytes(ESP.getFreeHeap());
SerialPrint(F("i"), F("HEAP"), heap);

View File

@@ -170,6 +170,17 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length)
standWebSocket.sendTXT(num, settingsFlashJson);
}
//----------------------------------------------------------------------//
// Страница веб интерфейса dev
//----------------------------------------------------------------------//
if (headerStr == "/dev|") {
standWebSocket.sendTXT(num, errorsHeapJson);
sendFileToWs("/layout.json", num, 1024);
standWebSocket.sendTXT(num, settingsFlashJson);
sendFileToWs("/config.json", num, 1024);
sendFileToWs("/items.json", num, 1024);
}
//----------------------------------------------------------------------//
// отдельные команды веб интерфейса
//----------------------------------------------------------------------//

View File

@@ -22,7 +22,7 @@ void* getAPI_ButtonOut(String subtype, String params);
void* getAPI_IoTServo(String subtype, String params);
void* getAPI_Mcp23017(String subtype, String params);
void* getAPI_Mp3(String subtype, String params);
void* getAPI_Pwm8266(String subtype, String params);
void* getAPI_Pwm32(String subtype, String params);
void* getAPI_TelegramLT(String subtype, String params);
void* getAPI_Lcd2004(String subtype, String params);
@@ -50,7 +50,7 @@ if ((tmpAPI = getAPI_ButtonOut(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_IoTServo(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Mcp23017(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Mp3(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Pwm8266(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Pwm32(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_TelegramLT(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Lcd2004(subtype, params)) != nullptr) return tmpAPI;
return nullptr;

View File

@@ -290,4 +290,37 @@ String FileList(String path) {
output += "]";
return output;
}
#endif
#endif
#if defined(ESP8266)
bool getInfo(FSInfo& info) {
return FileFS.info(info);
}
// Информация о ФС
void getFSInfo() {
FSInfo buf;
if (getInfo(buf)) {
size_t totalBytes = buf.totalBytes; // всего
size_t usedBytes = buf.usedBytes; // использовано
// size_t maxOpenFiles = buf.maxOpenFiles; // лимит на открые файлы
// size_t blockSize = buf.blockSize;
// size_t pageSize = buf.pageSize;
// size_t maxPathLength = buf.maxPathLength; // лимит на пути и имена файлов
size_t freeBytes = totalBytes - usedBytes;
float freePer = ((float)freeBytes / totalBytes) * 100;
jsonWriteStr(errorsHeapJson, F("freeBytes"), String(freePer) + "% (" + prettyBytes(freeBytes) + ")");
} else {
SerialPrint("E", F("FS"), F("FS info error"));
}
}
#endif
#if defined(ESP32)
void getFSInfo() {
size_t totalBytes = FileFS.totalBytes(); // всего
size_t usedBytes = FileFS.usedBytes(); // использовано
size_t freeBytes = totalBytes - usedBytes;
float freePer = ((float)freeBytes / totalBytes) * 100;
jsonWriteStr(errorsHeapJson, F("freeBytes"), String(freePer) + "% (" + prettyBytes(freeBytes) + ")");
}
#endif

View File

@@ -24,29 +24,23 @@ void updateDeviceStatus() {
WiFiClient client;
HTTPClient http;
http.begin(client, url);
// http.setAuthorization("admin", "admin");
http.addHeader("Content-Type", "application/json");
// String mac = WiFi.macAddress().c_str();
String json = "";
jsonWriteStr_(json, "idesp", getChipId());
jsonWriteStr_(json, "nameesp", jsonReadStr(settingsFlashJson, F("name")));
jsonWriteStr_(json, "firmwarename", String(FIRMWARE_NAME));
jsonWriteStr_(json, "firmwarever", String(FIRMWARE_VERSION));
jsonWriteStr_(json, "rebootreason", ESP_getResetReason());
int httpCode = http.POST(json);
// int httpCode = http.POST("?idesp=" + getChipId() +
// "&nameesp=" + jsonReadStr(settingsFlashJson, F("name")) +
// "&firmwarename=" + String(FIRMWARE_NAME) +
// "&firmwarever=" + String(FIRMWARE_VERSION) +
// "&rebootreason=" + ESP_getResetReason() + "");
if (httpCode > 0) {
ret = httpCode;
if (httpCode == HTTP_CODE_OK) {
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
String httpRequestData = "idesp=" + getChipId() +
"&nameesp=" + jsonReadStr(settingsFlashJson, F("name")) +
"&firmwarename=" + String(FIRMWARE_NAME) +
"&firmwarever=" + String(FIRMWARE_VERSION) +
"&rebootreason=" + ESP_getResetReason() +
"&uptime=" + jsonReadStr(errorsHeapJson, F("upt"));
int httpResponseCode = http.POST(httpRequestData);
if (httpResponseCode > 0) {
ret = httpResponseCode;
if (httpResponseCode == HTTP_CODE_OK) {
String payload = http.getString();
ret += " " + payload;
}
} else {
ret = http.errorToString(httpCode).c_str();
ret = http.errorToString(httpResponseCode).c_str();
}
http.end();
}