mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-29 15:42:20 +03:00
Worktime
This commit is contained in:
@@ -3,8 +3,8 @@
|
|||||||
"chipID": "",
|
"chipID": "",
|
||||||
"apssid": "IoTmanager",
|
"apssid": "IoTmanager",
|
||||||
"appass": "",
|
"appass": "",
|
||||||
"routerssid": "VOLODYA",
|
"routerssid": "rise",
|
||||||
"routerpass": "BELCHENKO",
|
"routerpass": "hostel3333",
|
||||||
"timezone": 2,
|
"timezone": 2,
|
||||||
"ntp": "pool.ntp.org",
|
"ntp": "pool.ntp.org",
|
||||||
"mqttServer": "91.204.228.124",
|
"mqttServer": "91.204.228.124",
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
#define TAG_I2C "i2c"
|
#define TAG_I2C "i2c"
|
||||||
#define TAG_ONE_WIRE_PIN "oneWirePin"
|
#define TAG_ONE_WIRE_PIN "oneWirePin"
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Optional
|
* Optional
|
||||||
*/
|
*/
|
||||||
@@ -89,6 +90,7 @@ enum TimerTask_t { WIFI_SCAN,
|
|||||||
TIME,
|
TIME,
|
||||||
TIME_SYNC,
|
TIME_SYNC,
|
||||||
STATISTICS,
|
STATISTICS,
|
||||||
|
STATISTICS_WORK,
|
||||||
UPTIME,
|
UPTIME,
|
||||||
UDP,
|
UDP,
|
||||||
UDP_DB,
|
UDP_DB,
|
||||||
|
|||||||
@@ -5,10 +5,16 @@
|
|||||||
extern void initSt();
|
extern void initSt();
|
||||||
extern String updateDevicePsn(String lat, String lon, String accur);
|
extern String updateDevicePsn(String lat, String lon, String accur);
|
||||||
extern String updateDeviceStatus();
|
extern String updateDeviceStatus();
|
||||||
|
extern String updateWorkTime();
|
||||||
extern String addNewDevice();
|
extern String addNewDevice();
|
||||||
|
|
||||||
extern void decide();
|
extern void decide();
|
||||||
extern void getPsn();
|
extern void getPsn();
|
||||||
|
|
||||||
|
extern int getWorkTime();
|
||||||
|
extern int plusOneHour();
|
||||||
|
extern void eeWriteInt(int pos, int val);
|
||||||
|
extern int eeGetInt(int pos);
|
||||||
//extern void updateDeviceList();
|
//extern void updateDeviceList();
|
||||||
//extern void saveId(String file, int id);
|
//extern void saveId(String file, int id);
|
||||||
//extern int getId(String file);
|
//extern int getId(String file);
|
||||||
@@ -1,19 +1,29 @@
|
|||||||
#include "Utils/statUtils.h"
|
#include "Utils/StatUtils.h"
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
#include <EEPROM.h>
|
||||||
|
|
||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
#include "ItemsList.h"
|
#include "ItemsList.h"
|
||||||
|
|
||||||
void initSt() {
|
void initSt() {
|
||||||
|
Serial.print("New device registation: ");
|
||||||
Serial.println(addNewDevice());
|
Serial.println(addNewDevice());
|
||||||
decide();
|
decide();
|
||||||
if (TELEMETRY_UPDATE_INTERVAL_MIN) {
|
if (TELEMETRY_UPDATE_INTERVAL_MIN) {
|
||||||
ts.add(
|
ts.add(
|
||||||
STATISTICS, TELEMETRY_UPDATE_INTERVAL_MIN * 60000, [&](void*) {
|
STATISTICS, TELEMETRY_UPDATE_INTERVAL_MIN * 60000, [&](void*) {
|
||||||
|
Serial.print("Device status: ");
|
||||||
Serial.println(updateDeviceStatus());
|
Serial.println(updateDeviceStatus());
|
||||||
},
|
},
|
||||||
nullptr, true);
|
nullptr, true);
|
||||||
|
|
||||||
|
ts.add(
|
||||||
|
STATISTICS_WORK, TELEMETRY_UPDATE_INTERVAL_MIN * 60000, [&](void*) {
|
||||||
|
Serial.print("Work time: ");
|
||||||
|
Serial.println(updateWorkTime());
|
||||||
|
},
|
||||||
|
nullptr, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,7 +48,7 @@ void decide() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void getPsn() {
|
void getPsn() {
|
||||||
String res = getURL("http://ipinfo.io/?token=c60f88583ad1a4");
|
String res = getURL(F("http://ipinfo.io/?token=c60f88583ad1a4"));
|
||||||
if (res != "") {
|
if (res != "") {
|
||||||
String line = jsonReadStr(res, "loc");
|
String line = jsonReadStr(res, "loc");
|
||||||
String lat = selectToMarker(line, ",");
|
String lat = selectToMarker(line, ",");
|
||||||
@@ -62,7 +72,7 @@ String addNewDevice() {
|
|||||||
jsonWriteStr(json, "name", FIRMWARE_NAME);
|
jsonWriteStr(json, "name", FIRMWARE_NAME);
|
||||||
jsonWriteStr(json, "model", FIRMWARE_VERSION);
|
jsonWriteStr(json, "model", FIRMWARE_VERSION);
|
||||||
//==============================================
|
//==============================================
|
||||||
http.begin(client, "http://95.128.182.133:8082/api/devices/");
|
http.begin(client, F("http://95.128.182.133:8082/api/devices/"));
|
||||||
http.setAuthorization("admin", "admin");
|
http.setAuthorization("admin", "admin");
|
||||||
http.addHeader("Content-Type", "application/json");
|
http.addHeader("Content-Type", "application/json");
|
||||||
int httpCode = http.POST(json);
|
int httpCode = http.POST(json);
|
||||||
@@ -86,7 +96,7 @@ String updateDevicePsn(String lat, String lon, String accur) {
|
|||||||
if ((WiFi.status() == WL_CONNECTED)) {
|
if ((WiFi.status() == WL_CONNECTED)) {
|
||||||
WiFiClient client;
|
WiFiClient client;
|
||||||
HTTPClient http;
|
HTTPClient http;
|
||||||
http.begin(client, "http://95.128.182.133:5055/");
|
http.begin(client, F("http://95.128.182.133:5055/"));
|
||||||
http.setAuthorization("admin", "admin");
|
http.setAuthorization("admin", "admin");
|
||||||
http.addHeader("Content-Type", "application/json");
|
http.addHeader("Content-Type", "application/json");
|
||||||
String mac = WiFi.macAddress().c_str();
|
String mac = WiFi.macAddress().c_str();
|
||||||
@@ -110,11 +120,11 @@ String updateDeviceStatus() {
|
|||||||
if ((WiFi.status() == WL_CONNECTED)) {
|
if ((WiFi.status() == WL_CONNECTED)) {
|
||||||
WiFiClient client;
|
WiFiClient client;
|
||||||
HTTPClient http;
|
HTTPClient http;
|
||||||
http.begin(client, "http://95.128.182.133:5055/");
|
http.begin(client, F("http://95.128.182.133:5055/"));
|
||||||
http.setAuthorization("admin", "admin");
|
http.setAuthorization("admin", "admin");
|
||||||
http.addHeader("Content-Type", "application/json");
|
http.addHeader("Content-Type", "application/json");
|
||||||
String mac = WiFi.macAddress().c_str();
|
String mac = WiFi.macAddress().c_str();
|
||||||
int httpCode = http.POST("?id=" + mac + "&resetReason=" + ESP.getResetReason() + "&uptime=" + timeNow->getUptime() + "&version=" + FIRMWARE_VERSION + "");
|
int httpCode = http.POST("?id=" + mac + "&resetReason=" + ESP.getResetReason() + "&uptime=" + timeNow->getUptime() + "&worktime=" + String(getWorkTime()) + "&version=" + FIRMWARE_VERSION + "");
|
||||||
if (httpCode > 0) {
|
if (httpCode > 0) {
|
||||||
ret = httpCode;
|
ret = httpCode;
|
||||||
if (httpCode == HTTP_CODE_OK) {
|
if (httpCode == HTTP_CODE_OK) {
|
||||||
@@ -128,6 +138,65 @@ String updateDeviceStatus() {
|
|||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String updateWorkTime() {
|
||||||
|
String ret;
|
||||||
|
if ((WiFi.status() == WL_CONNECTED)) {
|
||||||
|
WiFiClient client;
|
||||||
|
HTTPClient http;
|
||||||
|
http.begin(client, F("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 + "&worktime=" + String(plusOneHour()) + "");
|
||||||
|
if (httpCode > 0) {
|
||||||
|
ret = httpCode;
|
||||||
|
if (httpCode == HTTP_CODE_OK) {
|
||||||
|
String payload = http.getString();
|
||||||
|
ret += " " + payload;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ret = http.errorToString(httpCode).c_str();
|
||||||
|
}
|
||||||
|
http.end();
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int getWorkTime() {
|
||||||
|
static int hrs;
|
||||||
|
EEPROM.begin(512);
|
||||||
|
hrs = eeGetInt(0);
|
||||||
|
return hrs;
|
||||||
|
}
|
||||||
|
|
||||||
|
int plusOneHour() {
|
||||||
|
static int hrs;
|
||||||
|
EEPROM.begin(512);
|
||||||
|
hrs = eeGetInt(0);
|
||||||
|
hrs++;
|
||||||
|
eeWriteInt(0, hrs);
|
||||||
|
return hrs;
|
||||||
|
}
|
||||||
|
|
||||||
|
void eeWriteInt(int pos, int val) {
|
||||||
|
byte* p = (byte*)&val;
|
||||||
|
EEPROM.write(pos, *p);
|
||||||
|
EEPROM.write(pos + 1, *(p + 1));
|
||||||
|
EEPROM.write(pos + 2, *(p + 2));
|
||||||
|
EEPROM.write(pos + 3, *(p + 3));
|
||||||
|
EEPROM.commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
int eeGetInt(int pos) {
|
||||||
|
int val;
|
||||||
|
byte* p = (byte*)&val;
|
||||||
|
*p = EEPROM.read(pos);
|
||||||
|
*(p + 1) = EEPROM.read(pos + 1);
|
||||||
|
*(p + 2) = EEPROM.read(pos + 2);
|
||||||
|
*(p + 3) = EEPROM.read(pos + 3);
|
||||||
|
return val;
|
||||||
|
}
|
||||||
//========for updating list of device=================
|
//========for updating list of device=================
|
||||||
/*
|
/*
|
||||||
void updateDeviceList() {
|
void updateDeviceList() {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
#include "Class/CallBackTest.h"
|
#include "Class/CallBackTest.h"
|
||||||
#include "Class/NotAsinc.h"
|
#include "Class/NotAsinc.h"
|
||||||
#include "Class/ScenarioClass.h"
|
#include "Class/ScenarioClass.h"
|
||||||
#include "Utils/statUtils.h"
|
#include "Utils/StatUtils.h"
|
||||||
#include "Cmd.h"
|
#include "Cmd.h"
|
||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
#include "Init.h"
|
#include "Init.h"
|
||||||
@@ -86,7 +86,7 @@ void setup() {
|
|||||||
nullptr, true);
|
nullptr, true);
|
||||||
|
|
||||||
just_load = false;
|
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)
|
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() {
|
void loop() {
|
||||||
|
|||||||
Reference in New Issue
Block a user