mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-29 07:32:18 +03:00
clock fix
This commit is contained in:
@@ -113,7 +113,7 @@ class Clock {
|
|||||||
* Локальное время "дд.ММ.гг"
|
* Локальное время "дд.ММ.гг"
|
||||||
*/
|
*/
|
||||||
const String getDateDigitalFormated() {
|
const String getDateDigitalFormated() {
|
||||||
char buf[16];
|
char buf[32];
|
||||||
sprintf(buf, "%02d.%02d.%02d", _time_local.day_of_month, _time_local.month, _time_local.year);
|
sprintf(buf, "%02d.%02d.%02d", _time_local.day_of_month, _time_local.month, _time_local.year);
|
||||||
return String(buf);
|
return String(buf);
|
||||||
}
|
}
|
||||||
@@ -122,16 +122,22 @@ class Clock {
|
|||||||
* Локальное время "чч:мм:cc"
|
* Локальное время "чч:мм:cc"
|
||||||
*/
|
*/
|
||||||
const String getTime() {
|
const String getTime() {
|
||||||
char buf[16];
|
char buf[32];
|
||||||
sprintf(buf, "%02d:%02d:%02d", _time_local.hour, _time_local.minute, _time_local.second);
|
sprintf(buf, "%02d:%02d:%02d", _time_local.hour, _time_local.minute, _time_local.second);
|
||||||
return String(buf);
|
return String(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const String getTimeJson() {
|
||||||
|
char buf[32];
|
||||||
|
sprintf(buf, "%02d-%02d-%02d", _time_local.hour, _time_local.minute, _time_local.second);
|
||||||
|
return String(buf);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Локальное время "чч:мм"
|
* Локальное время "чч:мм"
|
||||||
*/
|
*/
|
||||||
const String getTimeWOsec() {
|
const String getTimeWOsec() {
|
||||||
char buf[16];
|
char buf[32];
|
||||||
sprintf(buf, "%02d:%02d", _time_local.hour, _time_local.minute);
|
sprintf(buf, "%02d:%02d", _time_local.hour, _time_local.minute);
|
||||||
return String(buf);
|
return String(buf);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ extern int sensors_reading_map[15];
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// Cmd
|
// Cmd
|
||||||
extern void CMD_init();
|
extern void cmd_init();
|
||||||
extern void button();
|
extern void button();
|
||||||
extern void buttonSet();
|
extern void buttonSet();
|
||||||
extern void buttonChange();
|
extern void buttonChange();
|
||||||
@@ -161,12 +161,11 @@ extern void fileExecute(const String& filename);
|
|||||||
extern void stringExecute(String& cmdStr);
|
extern void stringExecute(String& cmdStr);
|
||||||
// Init
|
// Init
|
||||||
extern void loadConfig();
|
extern void loadConfig();
|
||||||
extern void All_init();
|
extern void all_init();
|
||||||
extern void statistics_init();
|
extern void statistics_init();
|
||||||
extern void loadScenario();
|
extern void loadScenario();
|
||||||
extern void Device_init();
|
extern void Device_init();
|
||||||
extern void prsets_init();
|
extern void prsets_init();
|
||||||
extern void up_time();
|
|
||||||
|
|
||||||
// Logging
|
// Logging
|
||||||
extern void logging();
|
extern void logging();
|
||||||
@@ -178,8 +177,10 @@ extern void choose_log_date_and_send();
|
|||||||
extern void setChipId();
|
extern void setChipId();
|
||||||
extern void saveConfig();
|
extern void saveConfig();
|
||||||
extern String getURL(const String& urls);
|
extern String getURL(const String& urls);
|
||||||
|
extern void do_check_fs();
|
||||||
|
extern void do_scan_bus();
|
||||||
extern void servo_();
|
extern void servo_();
|
||||||
|
extern void clock_init();
|
||||||
|
|
||||||
extern void setLedStatus(LedStatus_t);
|
extern void setLedStatus(LedStatus_t);
|
||||||
|
|
||||||
@@ -251,7 +252,6 @@ extern void UDP_init();
|
|||||||
extern void do_udp_data_parse();
|
extern void do_udp_data_parse();
|
||||||
extern void do_mqtt_send_settings_to_udp();
|
extern void do_mqtt_send_settings_to_udp();
|
||||||
|
|
||||||
// iot_firmware
|
|
||||||
extern void addCommandLoop(const String& cmdStr);
|
extern void addCommandLoop(const String& cmdStr);
|
||||||
extern void loopSerial();
|
extern void loopSerial();
|
||||||
extern void loopCmd();
|
extern void loopCmd();
|
||||||
@@ -266,5 +266,4 @@ extern void uptime_init();
|
|||||||
|
|
||||||
// Web
|
// Web
|
||||||
extern void web_init();
|
extern void web_init();
|
||||||
|
extern void telemetry_init();
|
||||||
extern void telemetry_init();
|
|
||||||
|
|||||||
@@ -6,10 +6,10 @@ String jsonReadStr(String& json, String name);
|
|||||||
|
|
||||||
int jsonReadInt(String& json, String name);
|
int jsonReadInt(String& json, String name);
|
||||||
|
|
||||||
String jsonWriteStr(String& json, String name, String volume);
|
boolean jsonReadBool(String& json, String name);
|
||||||
|
|
||||||
String jsonWriteInt(String& json, String name, int volume);
|
String jsonWriteStr(String& json, String name, String value);
|
||||||
|
|
||||||
String jsonWriteFloat(String& json, String name, float volume);
|
String jsonWriteInt(String& json, String name, int value);
|
||||||
|
|
||||||
boolean jsonReadBool(String& json, String name);
|
String jsonWriteFloat(String& json, String name, float value);
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ SoftwareSerial *mySerial = nullptr;
|
|||||||
|
|
||||||
void getData();
|
void getData();
|
||||||
|
|
||||||
void CMD_init() {
|
void cmd_init() {
|
||||||
sCmd.addCommand("button", button);
|
sCmd.addCommand("button", button);
|
||||||
sCmd.addCommand("buttonSet", buttonSet);
|
sCmd.addCommand("buttonSet", buttonSet);
|
||||||
sCmd.addCommand("buttonChange", buttonChange);
|
sCmd.addCommand("buttonChange", buttonChange);
|
||||||
@@ -330,10 +330,8 @@ void timeSet() {
|
|||||||
void handle_time_init() {
|
void handle_time_init() {
|
||||||
ts.add(
|
ts.add(
|
||||||
TIME, 1000, [&](void *) {
|
TIME, 1000, [&](void *) {
|
||||||
String tmp = timeNow->getTime();
|
jsonWriteStr(configLiveJson, "time", timeNow->getTime());
|
||||||
jsonWriteStr(configLiveJson, "time", tmp);
|
jsonWriteStr(configLiveJson, "timenow", timeNow->getTimeJson());
|
||||||
tmp.replace(":", "-");
|
|
||||||
jsonWriteStr(configLiveJson, "timenow", tmp);
|
|
||||||
eventGen("timenow", "");
|
eventGen("timenow", "");
|
||||||
},
|
},
|
||||||
nullptr, true);
|
nullptr, true);
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ void loadConfig() {
|
|||||||
Serial.println(configSetupJson);
|
Serial.println(configSetupJson);
|
||||||
}
|
}
|
||||||
|
|
||||||
void All_init() {
|
void all_init() {
|
||||||
Device_init();
|
Device_init();
|
||||||
loadScenario();
|
loadScenario();
|
||||||
Timer_countdown_init();
|
Timer_countdown_init();
|
||||||
|
|||||||
@@ -20,28 +20,28 @@ int jsonReadInt(String& json, String name) {
|
|||||||
return root[name];
|
return root[name];
|
||||||
}
|
}
|
||||||
|
|
||||||
String jsonWriteStr(String& json, String name, String volume) {
|
String jsonWriteStr(String& json, String name, String value) {
|
||||||
DynamicJsonBuffer jsonBuffer;
|
DynamicJsonBuffer jsonBuffer;
|
||||||
JsonObject& root = jsonBuffer.parseObject(json);
|
JsonObject& root = jsonBuffer.parseObject(json);
|
||||||
root[name] = volume;
|
root[name] = value;
|
||||||
json = "";
|
json = "";
|
||||||
root.printTo(json);
|
root.printTo(json);
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
String jsonWriteInt(String& json, String name, int volume) {
|
String jsonWriteInt(String& json, String name, int value) {
|
||||||
DynamicJsonBuffer jsonBuffer;
|
DynamicJsonBuffer jsonBuffer;
|
||||||
JsonObject& root = jsonBuffer.parseObject(json);
|
JsonObject& root = jsonBuffer.parseObject(json);
|
||||||
root[name] = volume;
|
root[name] = value;
|
||||||
json = "";
|
json = "";
|
||||||
root.printTo(json);
|
root.printTo(json);
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
String jsonWriteFloat(String& json, String name, float volume) {
|
String jsonWriteFloat(String& json, String name, float value) {
|
||||||
DynamicJsonBuffer jsonBuffer;
|
DynamicJsonBuffer jsonBuffer;
|
||||||
JsonObject& root = jsonBuffer.parseObject(json);
|
JsonObject& root = jsonBuffer.parseObject(json);
|
||||||
root[name] = volume;
|
root[name] = value;
|
||||||
json = "";
|
json = "";
|
||||||
root.printTo(json);
|
root.printTo(json);
|
||||||
return json;
|
return json;
|
||||||
|
|||||||
88
src/main.cpp
88
src/main.cpp
@@ -11,40 +11,6 @@ static const char* MODULE = "Main";
|
|||||||
Timings metric;
|
Timings metric;
|
||||||
boolean initialized = false;
|
boolean initialized = false;
|
||||||
|
|
||||||
void do_fscheck(String& results) {
|
|
||||||
// TODO Проверка наличие важных файлов, возможно версии ФС
|
|
||||||
}
|
|
||||||
|
|
||||||
void clock_init() {
|
|
||||||
timeNow = new Clock();
|
|
||||||
timeNow->setNtpPool(jsonReadStr(configSetupJson, "ntp"));
|
|
||||||
timeNow->setTimezone(jsonReadStr(configSetupJson, "timezone").toInt());
|
|
||||||
|
|
||||||
ts.add(
|
|
||||||
TIME_SYNC, 30000, [&](void*) {
|
|
||||||
timeNow->hasSync();
|
|
||||||
},
|
|
||||||
nullptr, true);
|
|
||||||
}
|
|
||||||
void do_scan_bus() {
|
|
||||||
if (busScanFlag) {
|
|
||||||
String res = "";
|
|
||||||
BusScanner* scanner = BusScannerFactory::get(res, busToScan);
|
|
||||||
scanner->scan();
|
|
||||||
jsonWriteStr(configLiveJson, BusScannerFactory::label(busToScan), res);
|
|
||||||
busScanFlag = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void do_check_fs() {
|
|
||||||
if (fsCheckFlag) {
|
|
||||||
String buf;
|
|
||||||
do_fscheck(buf);
|
|
||||||
jsonWriteStr(configLiveJson, "fscheck", buf);
|
|
||||||
fsCheckFlag = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
WiFi.setAutoConnect(false);
|
WiFi.setAutoConnect(false);
|
||||||
WiFi.persistent(false);
|
WiFi.persistent(false);
|
||||||
@@ -62,14 +28,17 @@ void setup() {
|
|||||||
pm.info("Config");
|
pm.info("Config");
|
||||||
loadConfig();
|
loadConfig();
|
||||||
|
|
||||||
|
pm.info("Clock");
|
||||||
|
clock_init();
|
||||||
|
|
||||||
pm.info("Commands");
|
pm.info("Commands");
|
||||||
CMD_init();
|
cmd_init();
|
||||||
|
|
||||||
pm.info("Sensors");
|
pm.info("Sensors");
|
||||||
sensors_init();
|
sensors_init();
|
||||||
|
|
||||||
pm.info("Init");
|
pm.info("Init");
|
||||||
All_init();
|
all_init();
|
||||||
|
|
||||||
pm.info("Network");
|
pm.info("Network");
|
||||||
startSTAMode();
|
startSTAMode();
|
||||||
@@ -91,15 +60,12 @@ void setup() {
|
|||||||
pm.info("WebAdmin");
|
pm.info("WebAdmin");
|
||||||
web_init();
|
web_init();
|
||||||
|
|
||||||
pm.info("Clock");
|
|
||||||
clock_init();
|
|
||||||
|
|
||||||
#ifdef UDP_ENABLED
|
#ifdef UDP_ENABLED
|
||||||
pm.info("Broadcast UDP");
|
pm.info("Broadcast UDP");
|
||||||
UDP_init();
|
UDP_init();
|
||||||
#endif
|
#endif
|
||||||
ts.add(
|
ts.add(
|
||||||
TEST, 10000, [&](void*) {
|
TEST, 1000 * 60, [&](void*) {
|
||||||
pm.info(printMemoryStatus());
|
pm.info(printMemoryStatus());
|
||||||
},
|
},
|
||||||
nullptr, true);
|
nullptr, true);
|
||||||
@@ -121,10 +87,8 @@ void loop() {
|
|||||||
#ifdef WS_enable
|
#ifdef WS_enable
|
||||||
ws.cleanupClients();
|
ws.cleanupClients();
|
||||||
#endif
|
#endif
|
||||||
// metric.add(MT_ONE);
|
|
||||||
not_async_actions();
|
not_async_actions();
|
||||||
|
|
||||||
// metric.add(MT_TWO);
|
|
||||||
MqttClient::loop();
|
MqttClient::loop();
|
||||||
|
|
||||||
loopCmd();
|
loopCmd();
|
||||||
@@ -140,12 +104,6 @@ void loop() {
|
|||||||
loopSerial();
|
loopSerial();
|
||||||
|
|
||||||
ts.update();
|
ts.update();
|
||||||
|
|
||||||
if (metric._counter > 100000) {
|
|
||||||
metric.print();
|
|
||||||
} else {
|
|
||||||
metric.count();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void not_async_actions() {
|
void not_async_actions() {
|
||||||
@@ -241,3 +199,37 @@ void setLedStatus(LedStatus_t status) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
void do_fscheck(String& results) {
|
||||||
|
// TODO Проверка наличие важных файлов, возможно версии ФС
|
||||||
|
}
|
||||||
|
|
||||||
|
void clock_init() {
|
||||||
|
timeNow = new Clock();
|
||||||
|
timeNow->setNtpPool(jsonReadStr(configSetupJson, "ntp"));
|
||||||
|
timeNow->setTimezone(jsonReadStr(configSetupJson, "timezone").toInt());
|
||||||
|
|
||||||
|
ts.add(
|
||||||
|
TIME_SYNC, 30000, [&](void*) {
|
||||||
|
timeNow->hasSync();
|
||||||
|
},
|
||||||
|
nullptr, true);
|
||||||
|
}
|
||||||
|
void do_scan_bus() {
|
||||||
|
if (busScanFlag) {
|
||||||
|
String res = "";
|
||||||
|
BusScanner* scanner = BusScannerFactory::get(res, busToScan);
|
||||||
|
scanner->scan();
|
||||||
|
jsonWriteStr(configLiveJson, BusScannerFactory::label(busToScan), res);
|
||||||
|
busScanFlag = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void do_check_fs() {
|
||||||
|
if (fsCheckFlag) {
|
||||||
|
String buf;
|
||||||
|
do_fscheck(buf);
|
||||||
|
jsonWriteStr(configLiveJson, "fscheck", buf);
|
||||||
|
fsCheckFlag = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user