mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-27 06:32:19 +03:00
changes
This commit is contained in:
60
src/Init.cpp
60
src/Init.cpp
@@ -83,42 +83,34 @@ void uptime_init() {
|
||||
nullptr, true);
|
||||
}
|
||||
|
||||
void telemetry_init() {
|
||||
if (TELEMETRY_UPDATE_INTERVAL) {
|
||||
ts.add(
|
||||
STATISTICS, TELEMETRY_UPDATE_INTERVAL, [&](void*) {
|
||||
handle_statistics();
|
||||
},
|
||||
nullptr, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void handle_uptime() {
|
||||
jsonWriteStr(configSetupJson, "uptime", timeNow->getUptime());
|
||||
}
|
||||
|
||||
void handle_statistics() {
|
||||
if (isNetworkActive()) {
|
||||
String urls = "http://backup.privet.lv/visitors/?";
|
||||
//-----------------------------------------------------------------
|
||||
urls += WiFi.macAddress().c_str();
|
||||
urls += "&";
|
||||
//-----------------------------------------------------------------
|
||||
#ifdef ESP8266
|
||||
urls += "iot-manager_esp8266";
|
||||
#endif
|
||||
#ifdef ESP32
|
||||
urls += "iot-manager_esp32";
|
||||
#endif
|
||||
urls += "&";
|
||||
#ifdef ESP8266
|
||||
urls += ESP.getResetReason();
|
||||
#endif
|
||||
#ifdef ESP32
|
||||
urls += "Power on";
|
||||
#endif
|
||||
urls += "&";
|
||||
urls += String(FIRMWARE_VERSION);
|
||||
String stat = getURL(urls);
|
||||
}
|
||||
}
|
||||
//void handle_statistics() {
|
||||
// if (isNetworkActive()) {
|
||||
// String urls = "http://backup.privet.lv/visitors/?";
|
||||
// //-----------------------------------------------------------------
|
||||
// urls += WiFi.macAddress().c_str();
|
||||
// urls += "&";
|
||||
// //-----------------------------------------------------------------
|
||||
//#ifdef ESP8266
|
||||
// urls += "iot-manager_esp8266";
|
||||
//#endif
|
||||
//#ifdef ESP32
|
||||
// urls += "iot-manager_esp32";
|
||||
//#endif
|
||||
// urls += "&";
|
||||
//#ifdef ESP8266
|
||||
// urls += ESP.getResetReason();
|
||||
//#endif
|
||||
//#ifdef ESP32
|
||||
// urls += "Power on";
|
||||
//#endif
|
||||
// urls += "&";
|
||||
// urls += String(FIRMWARE_VERSION);
|
||||
// String stat = getURL(urls);
|
||||
// }
|
||||
//}
|
||||
@@ -17,6 +17,8 @@ String getURL(const String& urls) {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
const String getMethodName(AsyncWebServerRequest* request) {
|
||||
String res = F("UNKNOWN");
|
||||
if (request->method() == HTTP_GET)
|
||||
|
||||
121
src/Utils/statUtils.cpp
Normal file
121
src/Utils/statUtils.cpp
Normal file
@@ -0,0 +1,121 @@
|
||||
#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*) {
|
||||
|
||||
addNewDevice(FIRMWARE_NAME);
|
||||
updateDevice("37.163142", "49.178735", "1000", timeNow->getUptime(), FIRMWARE_VERSION);
|
||||
|
||||
},
|
||||
nullptr, true);
|
||||
}
|
||||
}
|
||||
|
||||
void addNewDevice(String model) {
|
||||
if ((WiFi.status() == WL_CONNECTED)) {
|
||||
WiFiClient client;
|
||||
HTTPClient http;
|
||||
String json = "{}";
|
||||
String mac = WiFi.macAddress().c_str();
|
||||
createNewDevJson(json, model);
|
||||
//Serial.println(json);
|
||||
http.begin(client, "http://95.128.182.133:8082/api/devices/");
|
||||
http.setAuthorization("admin", "admin");
|
||||
http.addHeader("Content-Type", "application/json");
|
||||
int httpCode = http.POST(json);
|
||||
if (httpCode > 0) {
|
||||
Serial.printf("code: %d\n", httpCode);
|
||||
if (httpCode == HTTP_CODE_OK) {
|
||||
//String payload = http.getString();
|
||||
//Serial.println("received payload:\n<<");
|
||||
//Serial.println(payload);
|
||||
//saveId("statid.txt", jsonReadInt(payload, "id"));
|
||||
//Serial.println(">>");
|
||||
}
|
||||
} else {
|
||||
Serial.printf("error: %s\n", http.errorToString(httpCode).c_str());
|
||||
}
|
||||
http.end();
|
||||
}
|
||||
}
|
||||
|
||||
void updateDevice(String lat, String lon, String accur, 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() + "&lat=" + lat + "&lon=" + lon + "&accuracy=" + accur + "&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);
|
||||
jsonWriteStr(json, "uniqueId", mac);
|
||||
jsonWriteStr(json, "model", model);
|
||||
}
|
||||
|
||||
//void updateDeviceList(String model, String firmVer) {
|
||||
// if ((WiFi.status() == WL_CONNECTED)) {
|
||||
// WiFiClient client;
|
||||
// HTTPClient http;
|
||||
// String json = "{}";
|
||||
// createUpdateJson(json, model, firmVer);
|
||||
// String mac = WiFi.macAddress().c_str();
|
||||
// http.begin(client, "http://95.128.182.133:8082/api/devices/" + mac + "/");
|
||||
// http.setAuthorization("admin", "admin");
|
||||
// http.addHeader("Content-Type", "application/json");
|
||||
// int httpCode = http.PUT(json);
|
||||
// if (httpCode > 0) {
|
||||
// Serial.printf("update Device List... code: %d\n", httpCode);
|
||||
// if (httpCode == HTTP_CODE_OK) {
|
||||
// const String& payload = http.getString();
|
||||
// Serial.println("received payload:\n<<");
|
||||
// Serial.println(payload);
|
||||
// Serial.println(">>");
|
||||
// }
|
||||
// } else {
|
||||
// Serial.printf("[HTTP] POST... failed, error: %s\n", http.errorToString(httpCode).c_str());
|
||||
// }
|
||||
// http.end();
|
||||
// }
|
||||
//}
|
||||
|
||||
//void createUpdateJson(String& json, String model, String ver) {
|
||||
// String mac = WiFi.macAddress().c_str();
|
||||
// jsonWriteInt(json, "id", getId("statid.txt"));
|
||||
// jsonWriteStr(json, "name", mac);
|
||||
// jsonWriteStr(json, "uniqueId", mac);
|
||||
// jsonWriteStr(json, "model", model);
|
||||
// jsonWriteStr(json, "phone", ver);
|
||||
//}
|
||||
|
||||
//void saveId(String file, int id) {
|
||||
// removeFile(file);
|
||||
// addFile(file, String(id));
|
||||
//}
|
||||
|
||||
//int getId(String file) {
|
||||
// return readFile(file, 100).toInt();
|
||||
//}
|
||||
20
src/items/SensorBme280Class.cpp
Normal file
20
src/items/SensorBme280Class.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
//#include "ItemsCmd.h"
|
||||
//#include "items/SensorBme280Class.h"
|
||||
////#ifdef SensorBme280Enabled
|
||||
////=========================================Модуль ультрозвукового дальномера==================================================================
|
||||
////Bme280-temp;id;anydata;Сенсоры;Температура;order;pin;c[1]
|
||||
////=========================================================================================================================================
|
||||
//SensorBme280Class mySensorBme280;
|
||||
//void bme280Temp() {
|
||||
// mySensorBme280.update();
|
||||
// String key = mySensorBme280.gkey();
|
||||
// sCmd.addCommand(key.c_str(), bme280Reading);
|
||||
// mySensorBme280.SensorBme280Init();
|
||||
// mySensorBme280.clear();
|
||||
//}
|
||||
//
|
||||
//void bme280Reading() {
|
||||
// String key = sCmd.order();
|
||||
// mySensorBme280.SensorBme280Read(key);
|
||||
//}
|
||||
////#endif
|
||||
@@ -1,9 +1,11 @@
|
||||
|
||||
#include <SSDP.h>
|
||||
|
||||
#include "BufferExecute.h"
|
||||
#include "Class/CallBackTest.h"
|
||||
#include "Class/NotAsinc.h"
|
||||
#include "Class/ScenarioClass.h"
|
||||
#include "Utils/statUtils.h"
|
||||
#include "Cmd.h"
|
||||
#include "Global.h"
|
||||
#include "Init.h"
|
||||
@@ -57,9 +59,6 @@ void setup() {
|
||||
pm.info("Uptime");
|
||||
uptime_init();
|
||||
|
||||
pm.info("telemetry");
|
||||
telemetry_init();
|
||||
|
||||
pm.info("Updater");
|
||||
upgradeInit();
|
||||
|
||||
@@ -69,6 +68,8 @@ void setup() {
|
||||
pm.info("WebAdmin");
|
||||
web_init();
|
||||
|
||||
initSt();
|
||||
|
||||
#ifdef UDP_ENABLED
|
||||
pm.info("Broadcast UDP");
|
||||
udpInit();
|
||||
@@ -85,7 +86,7 @@ void setup() {
|
||||
nullptr, true);
|
||||
|
||||
just_load = false;
|
||||
initialized = true;
|
||||
initialized = true; //this second POST makes the data to be processed (you don't need to connect as "keep-alive" for that to work)
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
Reference in New Issue
Block a user