mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-27 14:42:18 +03:00
working version
This commit is contained in:
@@ -1,19 +1,34 @@
|
||||
#include "Utils/statUtils.h"
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
#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);
|
||||
|
||||
Reference in New Issue
Block a user