2022-09-13 00:56:34 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "utils/Statistic.h"
|
|
|
|
|
#include <Arduino.h>
|
|
|
|
|
|
|
|
|
|
void stInit() {
|
|
|
|
|
if (TELEMETRY_UPDATE_INTERVAL_MIN) {
|
|
|
|
|
ts.add(
|
|
|
|
|
ST, TELEMETRY_UPDATE_INTERVAL_MIN * 60000, [&](void*) {
|
|
|
|
|
updateDeviceStatus();
|
|
|
|
|
},
|
|
|
|
|
nullptr, true);
|
|
|
|
|
}
|
|
|
|
|
SerialPrint("i", F("Stat"), F("Stat Init"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void updateDeviceStatus() {
|
|
|
|
|
String ret;
|
2023-06-20 21:47:29 +02:00
|
|
|
String serverIP = "http://iotmanager.org";
|
|
|
|
|
// jsonRead(settingsFlashJson, F("serverip"), serverIP);
|
2022-09-13 00:56:34 +02:00
|
|
|
String url = serverIP + F("/projects/esprebootstat.php");
|
|
|
|
|
// SerialPrint("i", "Stat", "url " + url);
|
|
|
|
|
if ((WiFi.status() == WL_CONNECTED)) {
|
|
|
|
|
WiFiClient client;
|
|
|
|
|
HTTPClient http;
|
|
|
|
|
http.begin(client, url);
|
2022-09-13 16:39:55 +02:00
|
|
|
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) {
|
2023-09-10 18:32:49 +03:00
|
|
|
ret = http.errorToString(httpResponseCode).c_str();
|
2022-09-13 16:39:55 +02:00
|
|
|
if (httpResponseCode == HTTP_CODE_OK) {
|
2022-09-13 00:56:34 +02:00
|
|
|
String payload = http.getString();
|
|
|
|
|
ret += " " + payload;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2022-09-13 16:39:55 +02:00
|
|
|
ret = http.errorToString(httpResponseCode).c_str();
|
2022-09-13 00:56:34 +02:00
|
|
|
}
|
|
|
|
|
http.end();
|
|
|
|
|
}
|
|
|
|
|
SerialPrint("i", "Stat", "Update device data: " + ret);
|
|
|
|
|
}
|