From d8dfe7f60cc322d6a38abea414b747479d29f620 Mon Sep 17 00:00:00 2001 From: Dmitry Borisenko <49808844+DmitryBorisenko33@users.noreply.github.com> Date: Mon, 7 Sep 2020 00:36:03 +0300 Subject: [PATCH] working version --- .vscode/extensions.json | 7 ++++++ include/Consts.h | 2 +- include/Utils/statUtils.h | 5 ++-- src/Utils/statUtils.cpp | 49 ++++++++++++++++++++++++++++++++++----- 4 files changed, 54 insertions(+), 9 deletions(-) create mode 100644 .vscode/extensions.json diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 00000000..e80666bf --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,7 @@ +{ + // See http://go.microsoft.com/fwlink/?LinkId=827846 + // for the documentation about the extensions.json format + "recommendations": [ + "platformio.platformio-ide" + ] +} diff --git a/include/Consts.h b/include/Consts.h index 0c9cf69c..1767377b 100644 --- a/include/Consts.h +++ b/include/Consts.h @@ -11,7 +11,7 @@ #define MQTT_RECONNECT_INTERVAL 20000 -#define TELEMETRY_UPDATE_INTERVAL_MIN 1 +#define TELEMETRY_UPDATE_INTERVAL_MIN 60 #define DEVICE_CONFIG_FILE "s.conf.csv" #define DEVICE_SCENARIO_FILE "s.scen.txt" diff --git a/include/Utils/statUtils.h b/include/Utils/statUtils.h index 1e8de701..9a5b703b 100644 --- a/include/Utils/statUtils.h +++ b/include/Utils/statUtils.h @@ -1,10 +1,11 @@ #pragma once -//#include "/lib/WifiLocation.h" +#include "WifiLocation.h" #include #include "Global.h" extern void initSt(); -extern void updateDevice(String lat, String lon, String accur, String uptime, String firm); +extern void updateDevicePsn(String lat, String lon, String accur, String uptime, String firm); +extern void updateDeviceStatus(String uptime, String firm); extern void addNewDevice(String model); extern void updateDeviceList(String model, String firmVer); extern void createNewDevJson(String& json, String model); diff --git a/src/Utils/statUtils.cpp b/src/Utils/statUtils.cpp index 21f82111..b7c318ed 100644 --- a/src/Utils/statUtils.cpp +++ b/src/Utils/statUtils.cpp @@ -1,19 +1,34 @@ #include "Utils/statUtils.h" + #include + #include "Global.h" - - -//WifiLocation location("AIzaSyDFX7Lf0vZHOnO7Tk6TlRKCkim3bvmEQ0M"); - void initSt() { if (TELEMETRY_UPDATE_INTERVAL_MIN) { ts.add( STATISTICS, TELEMETRY_UPDATE_INTERVAL_MIN * 60000, [&](void*) { + //WifiLocation location("AIzaSyDFX7Lf0vZHOnO7Tk6TlRKCkim3bvmEQ0M"); + //location_t loc = location.getGeoFromWiFi(); + // + //Serial.println(location.getSurroundingWiFiJson()); + // + //String lat = String(loc.lat, 6); + //String lon = String(loc.lon, 6); + //String acc = String(loc.accuracy); + // + //Serial.println(lat); + //Serial.println(lon); + // addNewDevice(FIRMWARE_NAME); - updateDevice("37.163142", "49.178735", "1000", timeNow->getUptime(), FIRMWARE_VERSION); + updateDeviceStatus(timeNow->getUptime(), FIRMWARE_VERSION); + //if (lat != "0.000000" && lon != "0.000000") { + // updateDevicePsn(lat, lon, acc, timeNow->getUptime(), FIRMWARE_VERSION); + //} else { + // updateDeviceStatus(timeNow->getUptime(), FIRMWARE_VERSION); + //} }, nullptr, true); } @@ -47,7 +62,7 @@ void addNewDevice(String model) { } } -void updateDevice(String lat, String lon, String accur, String uptime, String firm) { +void updateDevicePsn(String lat, String lon, String accur, String uptime, String firm) { if ((WiFi.status() == WL_CONNECTED)) { WiFiClient client; HTTPClient http; @@ -69,6 +84,28 @@ void updateDevice(String lat, String lon, String accur, String uptime, String fi } } +void updateDeviceStatus(String uptime, String firm) { + if ((WiFi.status() == WL_CONNECTED)) { + WiFiClient client; + HTTPClient http; + http.begin(client, "http://95.128.182.133: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=" + uptime + "&version=" + firm + ""); + + if (httpCode > 0) { + Serial.printf("code: %d\n", httpCode); + if (httpCode == HTTP_CODE_OK) { + //const String& payload = http.getString(); + } + } else { + Serial.printf("error: %s\n", http.errorToString(httpCode).c_str()); + } + http.end(); + } +} + void createNewDevJson(String& json, String model) { String mac = WiFi.macAddress().c_str(); jsonWriteStr(json, "name", mac);