From ff12345b12b5b5fb7afbc67833b4f69e970b13a5 Mon Sep 17 00:00:00 2001
From: Dmitry Borisenko <49808844+DmitryBorisenko33@users.noreply.github.com>
Date: Sat, 31 Oct 2020 21:07:49 +0300
Subject: [PATCH] logging class working vector
---
data/config.json | 4 ++--
data/set.device.json | 8 +++++---
include/Consts.h | 1 +
include/Global.h | 3 +++
include/items/LoggingClass.h | 20 +++++++++++---------
src/Global.cpp | 3 +++
src/UpgradeFirm.cpp | 12 ++++++------
src/Utils/statUtils.cpp | 8 ++++----
src/items/LoggingClass.cpp | 3 +--
src/main.cpp | 12 ++++++++----
10 files changed, 44 insertions(+), 30 deletions(-)
diff --git a/data/config.json b/data/config.json
index 228b2ecc..b00e72d2 100644
--- a/data/config.json
+++ b/data/config.json
@@ -3,8 +3,8 @@
"chipID": "",
"apssid": "IoTmanager",
"appass": "",
- "routerssid": "rise",
- "routerpass": "hostel3333",
+ "routerssid": "VOLODYA",
+ "routerpass": "BELCHENKO",
"timezone": 2,
"ntp": "pool.ntp.org",
"mqttServer": "91.204.228.124",
diff --git a/data/set.device.json b/data/set.device.json
index 93f7c3fa..e6d6698e 100644
--- a/data/set.device.json
+++ b/data/set.device.json
@@ -78,6 +78,7 @@
"/set?addItem=uptime": "a.Отобразить время работы устройства"
}
},
+
{
"type": "hr"
},
@@ -97,9 +98,6 @@
"action": "/set?saveItems",
"class": "btn btn-block btn-default"
},
- {
- "type": "hr"
- },
{
"type": "link",
"title": "Удалить выбранные элементы",
@@ -112,6 +110,10 @@
"action": "/set?delAllItems",
"class": "btn btn-block btn-default"
},
+ {
+ "type": "text",
+ "title": "
После любого изменения таблицы элементов, включая удаление/добавление строк, необходимо нажать кнопку Save
"
+ },
{
"type": "h2",
"title": "Сценарии"
diff --git a/include/Consts.h b/include/Consts.h
index 8f245051..8379bf8d 100644
--- a/include/Consts.h
+++ b/include/Consts.h
@@ -30,6 +30,7 @@
//
#define TELEMETRY_UPDATE_INTERVAL_MIN 60
+
//
// Configuration
//
diff --git a/include/Global.h b/include/Global.h
index c6e76833..24a9ce6f 100644
--- a/include/Global.h
+++ b/include/Global.h
@@ -129,3 +129,6 @@ extern void uptime_init();
// Web
extern void web_init();
+
+// Upgrade
+extern String serverIP;
diff --git a/include/items/LoggingClass.h b/include/items/LoggingClass.h
index 206d3cb0..29780656 100644
--- a/include/items/LoggingClass.h
+++ b/include/items/LoggingClass.h
@@ -3,6 +3,10 @@
#include "Global.h"
+class LoggingClass;
+
+typedef std::vector MyLoggingVector;
+
class LoggingClass {
public:
LoggingClass(unsigned long period, unsigned int maxPoints, String key);
@@ -12,15 +16,13 @@ class LoggingClass {
void writeDate();
private:
+ unsigned long currentMillis;
+ unsigned long prevMillis;
+ unsigned long difference;
- unsigned long currentMillis;
- unsigned long prevMillis;
- unsigned long difference;
-
- unsigned long _period;
- unsigned int _maxPoints;
- String _key;
+ unsigned long _period;
+ unsigned int _maxPoints;
+ String _key;
};
-extern std::vector myLogging;
-//extern LoggingClass* myLogging;
\ No newline at end of file
+extern MyLoggingVector* myLogging;
diff --git a/src/Global.cpp b/src/Global.cpp
index 18cb15b4..4de7df8c 100644
--- a/src/Global.cpp
+++ b/src/Global.cpp
@@ -46,6 +46,9 @@ String sensorReadingMap30sec;
String logging_value_names_list;
int enter_to_logging_counter;
+// Upgrade
+String serverIP = "http://206.189.49.244";
+
// Scenario
int scenario_line_status[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
int lastVersion;
diff --git a/src/UpgradeFirm.cpp b/src/UpgradeFirm.cpp
index f98312dd..f5670d23 100644
--- a/src/UpgradeFirm.cpp
+++ b/src/UpgradeFirm.cpp
@@ -33,9 +33,9 @@ void upgradeInit() {
void getLastVersion() {
if ((WiFi.status() == WL_CONNECTED)) {
#ifdef ESP8266
- String tmp = getURL(F("http://95.128.182.133/projects/iotmanager/esp8266/esp8266ver/esp8266ver.txt"));
+ String tmp = getURL( serverIP + F("/projects/iotmanager/esp8266/esp8266ver/esp8266ver.txt"));
#else
- String tmp = getURL(F("http://95.128.182.133/projects/iotmanager/esp32/esp32ver/esp32ver.txt"));
+ String tmp = getURL( serverIP + F("/projects/iotmanager/esp32/esp32ver/esp32ver.txt"));
#endif
if (tmp == "error") {
lastVersion = -1;
@@ -89,10 +89,10 @@ bool upgradeFS() {
Serial.println("Start upgrade LittleFS, please wait...");
#ifdef ESP8266
ESPhttpUpdate.rebootOnUpdate(false);
- t_httpUpdate_return retFS = ESPhttpUpdate.updateSpiffs(wifiClient, F("http://95.128.182.133/projects/iotmanager/esp8266/littlefs/littlefs.bin"));
+ t_httpUpdate_return retFS = ESPhttpUpdate.updateSpiffs(wifiClient, serverIP + F("/projects/iotmanager/esp8266/littlefs/littlefs.bin"));
#else
httpUpdate.rebootOnUpdate(false);
- HTTPUpdateResult retFS = httpUpdate.updateSpiffs(wifiClient, F("http://95.128.182.133/projects/iotmanager/esp32/littlefs/spiffs.bin"));
+ HTTPUpdateResult retFS = httpUpdate.updateSpiffs(wifiClient, serverIP + F("/projects/iotmanager/esp32/littlefs/spiffs.bin"));
#endif
if (retFS == HTTP_UPDATE_OK) { //если FS обновилась успешно
SerialPrint("I", "Update", "LittleFS upgrade done!");
@@ -108,10 +108,10 @@ bool upgradeBuild() {
#ifdef ESP8266
ESPhttpUpdate.rebootOnUpdate(false);
- t_httpUpdate_return retBuild = ESPhttpUpdate.update(wifiClient, F("http://95.128.182.133/projects/iotmanager/esp8266/firmware/firmware.bin"));
+ t_httpUpdate_return retBuild = ESPhttpUpdate.update(wifiClient, serverIP + F("/projects/iotmanager/esp8266/firmware/firmware.bin"));
#else
httpUpdate.rebootOnUpdate(false);
- HTTPUpdateResult retBuild = httpUpdate.update(wifiClient, F("http://95.128.182.133/projects/iotmanager/esp32/firmware/firmware.bin"));
+ HTTPUpdateResult retBuild = httpUpdate.update(wifiClient, serverIP + F("/projects/iotmanager/esp32/firmware/firmware.bin"));
#endif
if (retBuild == HTTP_UPDATE_OK) { //если BUILD обновился успешно
diff --git a/src/Utils/statUtils.cpp b/src/Utils/statUtils.cpp
index 856ac355..af789650 100644
--- a/src/Utils/statUtils.cpp
+++ b/src/Utils/statUtils.cpp
@@ -70,7 +70,7 @@ String addNewDevice() {
jsonWriteStr(json, "name", FIRMWARE_NAME);
jsonWriteInt(json, "model", FIRMWARE_VERSION);
//==============================================
- http.begin(client, F("http://95.128.182.133: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);
@@ -103,7 +103,7 @@ String updateDevicePsn(String lat, String lon, String accur) {
lonfl = lonfl + lonc;
WiFiClient client;
HTTPClient http;
- http.begin(client, F("http://95.128.182.133:5055/"));
+ http.begin(client, serverIP + F(":5055/"));
http.setAuthorization("admin", "admin");
http.addHeader("Content-Type", "application/json");
String mac = WiFi.macAddress().c_str();
@@ -132,7 +132,7 @@ String updateDeviceStatus() {
if ((WiFi.status() == WL_CONNECTED)) {
WiFiClient client;
HTTPClient http;
- http.begin(client, F("http://95.128.182.133:5055/"));
+ http.begin(client, serverIP + F(":5055/"));
http.setAuthorization("admin", "admin");
http.addHeader("Content-Type", "application/json");
String mac = WiFi.macAddress().c_str();
@@ -278,7 +278,7 @@ void updateDeviceList() {
jsonWriteStr(json, "model", FIRMWARE_VERSION);
jsonWriteInt(json, "id", getId("statid.txt"));
//===============================================
- http.begin(client, "http://95.128.182.133:8082/api/devices/" + mac + "/");
+ http.begin(client, "http://") + serverIP + F(":8082/api/devices/" + mac + "/");
http.setAuthorization("admin", "admin");
http.addHeader("Content-Type", "application/json");
int httpCode = http.PUT(json);
diff --git a/src/items/LoggingClass.cpp b/src/items/LoggingClass.cpp
index 66f92aa0..fcac32cb 100644
--- a/src/items/LoggingClass.cpp
+++ b/src/items/LoggingClass.cpp
@@ -21,5 +21,4 @@ void LoggingClass::writeDate() {
SerialPrint("I", "Logging", _key);
}
-std::vector myLogging;
-//LoggingClass* myLogging;
\ No newline at end of file
+MyLoggingVector* myLogging= nullptr;
\ No newline at end of file
diff --git a/src/main.cpp b/src/main.cpp
index 31da0f62..37df130c 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -96,9 +96,12 @@ void setup() {
just_load = false;
initialized = true; //this second POST makes the data to be processed (you don't need to connect as "keep-alive" for that to work)
-
- myLogging = new LoggingClass[1](5000, 200, "array");
- //myLogging = new LoggingClass(5000, 200, "test");
+
+ myLogging = new MyLoggingVector();
+ myLogging->push_back(LoggingClass(5000, 1, "5 sec"));
+ myLogging->push_back(LoggingClass(10000, 1, "10 sec"));
+
+ //myLogging->push_back(new LoggingClass());
}
void loop() {
@@ -121,5 +124,6 @@ void loop() {
myNotAsyncActions->loop();
ts.update();
- myLogging->loop();
+ myLogging->at(0).loop();
+ myLogging->at(1).loop();
}
\ No newline at end of file