mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 14:12:16 +03:00
working version
This commit is contained in:
7
.vscode/extensions.json
vendored
Normal file
7
.vscode/extensions.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
||||
// for the documentation about the extensions.json format
|
||||
"recommendations": [
|
||||
"platformio.platformio-ide"
|
||||
]
|
||||
}
|
||||
@@ -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"
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
#pragma once
|
||||
//#include "/lib/WifiLocation.h"
|
||||
#include "WifiLocation.h"
|
||||
#include <Arduino.h>
|
||||
#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);
|
||||
|
||||
@@ -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