mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 22:22:16 +03:00
@@ -113,7 +113,7 @@ class Clock {
|
||||
* Локальное время "дд.ММ.гг"
|
||||
*/
|
||||
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);
|
||||
return String(buf);
|
||||
}
|
||||
@@ -122,16 +122,22 @@ class Clock {
|
||||
* Локальное время "чч:мм:cc"
|
||||
*/
|
||||
const String getTime() {
|
||||
char buf[16];
|
||||
char buf[32];
|
||||
sprintf(buf, "%02d:%02d:%02d", _time_local.hour, _time_local.minute, _time_local.second);
|
||||
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() {
|
||||
char buf[16];
|
||||
char buf[32];
|
||||
sprintf(buf, "%02d:%02d", _time_local.hour, _time_local.minute);
|
||||
return String(buf);
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ extern int sensors_reading_map[15];
|
||||
*/
|
||||
|
||||
// Cmd
|
||||
extern void CMD_init();
|
||||
extern void cmd_init();
|
||||
extern void button();
|
||||
extern void buttonSet();
|
||||
extern void buttonChange();
|
||||
@@ -161,12 +161,11 @@ extern void fileExecute(const String& filename);
|
||||
extern void stringExecute(String& cmdStr);
|
||||
// Init
|
||||
extern void loadConfig();
|
||||
extern void All_init();
|
||||
extern void all_init();
|
||||
extern void statistics_init();
|
||||
extern void loadScenario();
|
||||
extern void Device_init();
|
||||
extern void prsets_init();
|
||||
extern void up_time();
|
||||
|
||||
// Logging
|
||||
extern void logging();
|
||||
@@ -178,8 +177,10 @@ extern void choose_log_date_and_send();
|
||||
extern void setChipId();
|
||||
extern void saveConfig();
|
||||
extern String getURL(const String& urls);
|
||||
|
||||
extern void do_check_fs();
|
||||
extern void do_scan_bus();
|
||||
extern void servo_();
|
||||
extern void clock_init();
|
||||
|
||||
extern void setLedStatus(LedStatus_t);
|
||||
|
||||
@@ -251,7 +252,6 @@ extern void UDP_init();
|
||||
extern void do_udp_data_parse();
|
||||
extern void do_mqtt_send_settings_to_udp();
|
||||
|
||||
// iot_firmware
|
||||
extern void addCommandLoop(const String& cmdStr);
|
||||
extern void loopSerial();
|
||||
extern void loopCmd();
|
||||
@@ -266,5 +266,4 @@ extern void uptime_init();
|
||||
|
||||
// Web
|
||||
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);
|
||||
|
||||
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 CMD_init() {
|
||||
void cmd_init() {
|
||||
sCmd.addCommand("button", button);
|
||||
sCmd.addCommand("buttonSet", buttonSet);
|
||||
sCmd.addCommand("buttonChange", buttonChange);
|
||||
@@ -330,10 +330,8 @@ void timeSet() {
|
||||
void handle_time_init() {
|
||||
ts.add(
|
||||
TIME, 1000, [&](void *) {
|
||||
String tmp = timeNow->getTime();
|
||||
jsonWriteStr(configLiveJson, "time", tmp);
|
||||
tmp.replace(":", "-");
|
||||
jsonWriteStr(configLiveJson, "timenow", tmp);
|
||||
jsonWriteStr(configLiveJson, "time", timeNow->getTime());
|
||||
jsonWriteStr(configLiveJson, "timenow", timeNow->getTimeJson());
|
||||
eventGen("timenow", "");
|
||||
},
|
||||
nullptr, true);
|
||||
|
||||
@@ -17,7 +17,7 @@ void loadConfig() {
|
||||
Serial.println(configSetupJson);
|
||||
}
|
||||
|
||||
void All_init() {
|
||||
void all_init() {
|
||||
Device_init();
|
||||
loadScenario();
|
||||
Timer_countdown_init();
|
||||
|
||||
@@ -20,28 +20,28 @@ int jsonReadInt(String& json, String name) {
|
||||
return root[name];
|
||||
}
|
||||
|
||||
String jsonWriteStr(String& json, String name, String volume) {
|
||||
String jsonWriteStr(String& json, String name, String value) {
|
||||
DynamicJsonBuffer jsonBuffer;
|
||||
JsonObject& root = jsonBuffer.parseObject(json);
|
||||
root[name] = volume;
|
||||
root[name] = value;
|
||||
json = "";
|
||||
root.printTo(json);
|
||||
return json;
|
||||
}
|
||||
|
||||
String jsonWriteInt(String& json, String name, int volume) {
|
||||
String jsonWriteInt(String& json, String name, int value) {
|
||||
DynamicJsonBuffer jsonBuffer;
|
||||
JsonObject& root = jsonBuffer.parseObject(json);
|
||||
root[name] = volume;
|
||||
root[name] = value;
|
||||
json = "";
|
||||
root.printTo(json);
|
||||
return json;
|
||||
}
|
||||
|
||||
String jsonWriteFloat(String& json, String name, float volume) {
|
||||
String jsonWriteFloat(String& json, String name, float value) {
|
||||
DynamicJsonBuffer jsonBuffer;
|
||||
JsonObject& root = jsonBuffer.parseObject(json);
|
||||
root[name] = volume;
|
||||
root[name] = value;
|
||||
json = "";
|
||||
root.printTo(json);
|
||||
return json;
|
||||
|
||||
88
src/main.cpp
88
src/main.cpp
@@ -11,40 +11,6 @@ static const char* MODULE = "Main";
|
||||
Timings metric;
|
||||
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() {
|
||||
WiFi.setAutoConnect(false);
|
||||
WiFi.persistent(false);
|
||||
@@ -62,14 +28,17 @@ void setup() {
|
||||
pm.info("Config");
|
||||
loadConfig();
|
||||
|
||||
pm.info("Clock");
|
||||
clock_init();
|
||||
|
||||
pm.info("Commands");
|
||||
CMD_init();
|
||||
cmd_init();
|
||||
|
||||
pm.info("Sensors");
|
||||
sensors_init();
|
||||
|
||||
pm.info("Init");
|
||||
All_init();
|
||||
all_init();
|
||||
|
||||
pm.info("Network");
|
||||
startSTAMode();
|
||||
@@ -91,15 +60,12 @@ void setup() {
|
||||
pm.info("WebAdmin");
|
||||
web_init();
|
||||
|
||||
pm.info("Clock");
|
||||
clock_init();
|
||||
|
||||
#ifdef UDP_ENABLED
|
||||
pm.info("Broadcast UDP");
|
||||
UDP_init();
|
||||
#endif
|
||||
ts.add(
|
||||
TEST, 10000, [&](void*) {
|
||||
TEST, 1000 * 60, [&](void*) {
|
||||
pm.info(printMemoryStatus());
|
||||
},
|
||||
nullptr, true);
|
||||
@@ -121,10 +87,8 @@ void loop() {
|
||||
#ifdef WS_enable
|
||||
ws.cleanupClients();
|
||||
#endif
|
||||
// metric.add(MT_ONE);
|
||||
not_async_actions();
|
||||
|
||||
// metric.add(MT_TWO);
|
||||
MqttClient::loop();
|
||||
|
||||
loopCmd();
|
||||
@@ -140,12 +104,6 @@ void loop() {
|
||||
loopSerial();
|
||||
|
||||
ts.update();
|
||||
|
||||
if (metric._counter > 100000) {
|
||||
metric.print();
|
||||
} else {
|
||||
metric.count();
|
||||
}
|
||||
}
|
||||
|
||||
void not_async_actions() {
|
||||
@@ -241,3 +199,37 @@ void setLedStatus(LedStatus_t status) {
|
||||
}
|
||||
#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