Add kontrol command for auto status interval
This commit is contained in:
29
src/main.cpp
29
src/main.cpp
@@ -48,6 +48,8 @@ static unsigned long g_last_motion_alert = 0;
|
||||
static const unsigned long ALERT_COOLDOWN_MS = 600000;
|
||||
static unsigned long g_boot_time = 0;
|
||||
static bool g_startup_msg_sent = false;
|
||||
static unsigned long g_auto_status_interval = 0;
|
||||
static unsigned long g_last_auto_status = 0;
|
||||
|
||||
struct SecurityConfig { uint32_t magic; uint8_t armed; uint8_t relay2; };
|
||||
static const uint32_t CFG_MAGIC = 0x53454355;
|
||||
@@ -148,7 +150,7 @@ public:
|
||||
while (*cmd == ' ') cmd++;
|
||||
|
||||
if (strcmp(cmd, "help") == 0) {
|
||||
defer_response("help:ohrana on,ohrana off,relay1 on,relay1 off,relay2 on,relay2 off,relay,status,ver,scan,uptime,reboot");
|
||||
defer_response("help:ohrana on,ohrana off,relay1 on,relay1 off,relay2 on,relay2 off,relay,status,ver,scan,uptime,kontrol,reboot");
|
||||
} else if (strcmp(cmd, "ohrana on") == 0) {
|
||||
g_armed = true; digitalWrite(PIN_RELAY_1, LOW); saveSecurityConfig(); defer_response("ohrana on ok");
|
||||
} else if (strcmp(cmd, "ohrana off") == 0) {
|
||||
@@ -190,6 +192,20 @@ public:
|
||||
else if (h > 0) snprintf(r, sizeof(r), "uptime:%dh %dm", h, m);
|
||||
else snprintf(r, sizeof(r), "uptime:%dm", m);
|
||||
defer_response(r);
|
||||
} else if (strcmp(cmd, "kontrol") == 0 || strncmp(cmd, "kontrol ", 8) == 0) {
|
||||
const char* arg = cmd + 7; while (*arg == ' ') arg++;
|
||||
if (strcmp(arg, "off") == 0) {
|
||||
g_auto_status_interval = 0;
|
||||
defer_response("kontrol off");
|
||||
} else {
|
||||
int val = atoi(arg);
|
||||
if (val >= 1 && val <= 1440) {
|
||||
g_auto_status_interval = (unsigned long)val * 60000;
|
||||
g_last_auto_status = millis();
|
||||
char r[48]; snprintf(r, sizeof(r), "kontrol %d min ok", val);
|
||||
defer_response(r);
|
||||
} else defer_response("kontrol 1-1440 or off");
|
||||
}
|
||||
} else if (strcmp(cmd, "reboot") == 0) {
|
||||
send_text("rebooting");
|
||||
delay(100);
|
||||
@@ -275,6 +291,17 @@ void loop() {
|
||||
if (!g_temp_requested) { ds18b20.requestTemperatures(); g_temp_requested = true; g_temp_last_request = now; }
|
||||
else if (now - g_temp_last_request > 750) { g_last_temperature = ds18b20.getTempCByIndex(0); g_temp_requested = false; }
|
||||
|
||||
if (g_auto_status_interval > 0 && now - g_last_auto_status >= g_auto_status_interval) {
|
||||
g_last_auto_status = now;
|
||||
char r[128]; char tb[16]; char vb[16]; float t = g_last_temperature;
|
||||
if (t == -127.0f) strcpy(tb, "N/A"); else snprintf(tb, sizeof(tb), "%+.1fC", t);
|
||||
uint16_t mv = board.getBattMilliVolts();
|
||||
if (mv < 100) strcpy(vb, "USB"); else snprintf(vb, sizeof(vb), "%.2fV", mv / 1000.0f);
|
||||
snprintf(r, sizeof(r), "status:%s temp:%s hall:%s motion:%s bat:%s",
|
||||
g_armed ? "armed" : "off", tb, g_hall_alert ? "trig" : "ok", g_motion_alert ? "trig" : "ok", vb);
|
||||
the_mesh.send_text(r);
|
||||
}
|
||||
|
||||
if (g_armed) {
|
||||
static unsigned long lt = 0; static bool ls = false;
|
||||
if (now - lt > 1000) { lt = now; ls = !ls; digitalWrite(PIN_LED_STATUS, ls); }
|
||||
|
||||
Reference in New Issue
Block a user