editor changed

This commit is contained in:
Dmitry Borisenko
2020-11-13 02:58:45 +03:00
parent 8bfba7ab4a
commit 96f160fc88
8 changed files with 70 additions and 722 deletions

View File

@@ -34,10 +34,12 @@ void decide() {
if (cnt <= 3) {
Serial.println("(get)");
getPsn();
} else {
}
else {
if (cnt % 5) {
Serial.println("(skip)");
} else {
}
else {
Serial.println("(get)");
getPsn();
}
@@ -51,10 +53,8 @@ void getPsn() {
String line = jsonReadStr(res, "loc");
String lat = selectToMarker(line, ",");
String lon = deleteBeforeDelimiter(line, ",");
//String city = jsonReadStr(res, "city");
//String country = jsonReadStr(res, "country");
//String region = jsonReadStr(res, "region");
updateDevicePsn(lat, lon, "0");
String geo = jsonReadStr(res, "city") + ", " + jsonReadStr(res, "country") + ", " + jsonReadStr(res, "region");
updateDevicePsn(lat, lon, "0", geo);
}
}
@@ -70,7 +70,7 @@ String addNewDevice() {
jsonWriteStr(json, "name", FIRMWARE_NAME);
jsonWriteStr(json, "model", getChipId());
//==============================================
http.begin(client, serverIP + F(":8082/api/devices/"));
http.begin(client, serverIP + F(":8082/api/devices/"));
http.setAuthorization("admin", "admin");
http.addHeader("Content-Type", "application/json");
int httpCode = http.POST(json);
@@ -81,7 +81,8 @@ String addNewDevice() {
ret += " " + payload;
//saveId("statid.txt", jsonReadInt(payload, "id"));
}
} else {
}
else {
ret = http.errorToString(httpCode).c_str();
}
http.end();
@@ -90,35 +91,39 @@ String addNewDevice() {
return ret;
}
String updateDevicePsn(String lat, String lon, String accur) {
String updateDevicePsn(String lat, String lon, String accur, String geo) {
String ret;
if ((WiFi.status() == WL_CONNECTED)) {
float latfl = lat.toFloat();
float lonfl = lon.toFloat();
randomSeed(micros());
float latc = random(1, 9)/100;
randomSeed(micros());
float lonc = random(1, 9)/100;
latfl = latfl + latc;
lonfl = lonfl + lonc;
float c = random(2, 9);
if (c > 5) {
latfl = latfl + (c / 100);
lonfl = lonfl + (c / 100);
}
else {
latfl = latfl - (c / 100);
lonfl = lonfl - (c / 100);
}
WiFiClient client;
HTTPClient http;
http.begin(client, serverIP + F(":5055/"));
http.begin(client, serverIP + F(":5055/"));
http.setAuthorization("admin", "admin");
http.addHeader("Content-Type", "application/json");
String mac = WiFi.macAddress().c_str();
int httpCode = http.POST("?id=" + mac +
"&resetReason=" + ESP_getResetReason() +
"&lat=" + String(latfl) +
"&lon=" + String(lonfl) +
"&accuracy=" + accur + "");
"&lat=" + String(latfl) +
"&lon=" + String(lonfl) +
"&accuracy=" + accur + "");
if (httpCode > 0) {
ret = httpCode;
if (httpCode == HTTP_CODE_OK) {
String payload = http.getString();
ret += " " + payload;
}
} else {
}
else {
ret = http.errorToString(httpCode).c_str();
}
http.end();
@@ -132,24 +137,25 @@ String updateDeviceStatus() {
if ((WiFi.status() == WL_CONNECTED)) {
WiFiClient client;
HTTPClient http;
http.begin(client, serverIP + F(":5055/"));
http.begin(client, serverIP + F(":5055/"));
http.setAuthorization("admin", "admin");
http.addHeader("Content-Type", "application/json");
String mac = WiFi.macAddress().c_str();
int httpCode = http.POST("?id=" + mac +
"&resetReason=" + ESP_getResetReason() +
"&uptime=" + timeNow->getUptime() +
"&uptimeTotal=" + getUptimeTotal() +
"&version=" + FIRMWARE_VERSION +
"&resetsTotal=" + String(getCurrentNumber("stat.txt")) +
"&heap=" + String(ESP.getFreeHeap()) + "");
"&resetReason=" + ESP_getResetReason() +
"&uptime=" + timeNow->getUptime() +
"&uptimeTotal=" + getUptimeTotal() +
"&version=" + FIRMWARE_VERSION +
"&resetsTotal=" + String(getCurrentNumber("stat.txt")) +
"&heap=" + String(ESP.getFreeHeap()) + "");
if (httpCode > 0) {
ret = httpCode;
if (httpCode == HTTP_CODE_OK) {
String payload = http.getString();
ret += " " + payload;
}
} else {
}
else {
ret = http.errorToString(httpCode).c_str();
}
http.end();
@@ -186,38 +192,38 @@ String ESP_getResetReason(void) {
String ESP32GetResetReason(uint32_t cpu_no) {
// tools\sdk\include\esp32\rom\rtc.h
switch (rtc_get_reset_reason((RESET_REASON)cpu_no)) {
case POWERON_RESET:
return F("Vbat power on reset"); // 1
case SW_RESET:
return F("Software reset digital core"); // 3
case OWDT_RESET:
return F("Legacy watch dog reset digital core"); // 4
case DEEPSLEEP_RESET:
return F("Deep Sleep reset digital core"); // 5
case SDIO_RESET:
return F("Reset by SLC module, reset digital core"); // 6
case TG0WDT_SYS_RESET:
return F("Timer Group0 Watch dog reset digital core"); // 7
case TG1WDT_SYS_RESET:
return F("Timer Group1 Watch dog reset digital core"); // 8
case RTCWDT_SYS_RESET:
return F("RTC Watch dog Reset digital core"); // 9
case INTRUSION_RESET:
return F("Instrusion tested to reset CPU"); // 10
case TGWDT_CPU_RESET:
return F("Time Group reset CPU"); // 11
case SW_CPU_RESET:
return F("Software reset CPU"); // 12
case RTCWDT_CPU_RESET:
return F("RTC Watch dog Reset CPU"); // 13
case EXT_CPU_RESET:
return F("or APP CPU, reseted by PRO CPU"); // 14
case RTCWDT_BROWN_OUT_RESET:
return F("Reset when the vdd voltage is not stable"); // 15
case RTCWDT_RTC_RESET:
return F("RTC Watch dog reset digital core and rtc module"); // 16
default:
return F("NO_MEAN"); // 0
case POWERON_RESET:
return F("Vbat power on reset"); // 1
case SW_RESET:
return F("Software reset digital core"); // 3
case OWDT_RESET:
return F("Legacy watch dog reset digital core"); // 4
case DEEPSLEEP_RESET:
return F("Deep Sleep reset digital core"); // 5
case SDIO_RESET:
return F("Reset by SLC module, reset digital core"); // 6
case TG0WDT_SYS_RESET:
return F("Timer Group0 Watch dog reset digital core"); // 7
case TG1WDT_SYS_RESET:
return F("Timer Group1 Watch dog reset digital core"); // 8
case RTCWDT_SYS_RESET:
return F("RTC Watch dog Reset digital core"); // 9
case INTRUSION_RESET:
return F("Instrusion tested to reset CPU"); // 10
case TGWDT_CPU_RESET:
return F("Time Group reset CPU"); // 11
case SW_CPU_RESET:
return F("Software reset CPU"); // 12
case RTCWDT_CPU_RESET:
return F("RTC Watch dog Reset CPU"); // 13
case EXT_CPU_RESET:
return F("or APP CPU, reseted by PRO CPU"); // 14
case RTCWDT_BROWN_OUT_RESET:
return F("Reset when the vdd voltage is not stable"); // 15
case RTCWDT_RTC_RESET:
return F("RTC Watch dog reset digital core and rtc module"); // 16
default:
return F("NO_MEAN"); // 0
}
}

View File

@@ -25,6 +25,7 @@ void init() {
server.serveStatic("/js/", LittleFS, "/js/").setCacheControl("max-age=600");
server.serveStatic("/favicon.ico", LittleFS, "/favicon.ico").setCacheControl("max-age=600");
server.serveStatic("/icon.jpeg", LittleFS, "/icon.jpeg").setCacheControl("max-age=600");
server.serveStatic("/edit", LittleFS, "/edit").setCacheControl("max-age=600");
server.serveStatic("/", LittleFS, "/").setDefaultFile("index.htm").setAuthentication(login.c_str(), pass.c_str());