ucentral-state: skip state messages when the AP is offline

Fixes: WIFI-13643
Signed-off-by: John Crispin <john@phrozen.org>
This commit is contained in:
John Crispin
2024-04-30 16:52:53 +02:00
parent fc32096ddf
commit f4254b1611

View File

@@ -19,6 +19,7 @@ let uci = libuci.cursor();
let config;
let offline_timer;
let current_state;
let online = false;
function self_healing() {
@@ -62,6 +63,10 @@ state = {
},
spawn: function() {
if (!online) {
ulog(LOG_INFO, 'offline - skipping state execution\n');
return;
}
ulog(LOG_INFO, 'state execute\n');
state.pid = uloop.process('/usr/share/ucentral/state.uc', [], {}, state.complete);
},
@@ -99,9 +104,10 @@ function config_load() {
state.run(config?.stats?.interval * 1000);
let status = ubus.call('ucentral', 'status');
if (status?.connected)
if (status?.connected) {
online_handler();
else if (config.ui.offline_trigger)
online = true;
} else if (config.ui.offline_trigger)
offline_timer = uloop.timer(config.ui.offline_trigger * 1000, offline_handler);
}
@@ -141,10 +147,10 @@ function blink_timeout() {
let state_handler = {
offline: function() {
online = false;
let led = led_find('led-running');
if (!led)
return ubus.STATUS_INVALID_ARGUMENT;
led_write(led, 'trigger', 'heartbeat');
if (led)
led_write(led, 'trigger', 'heartbeat');
if (config.ui.offline_trigger) {
if (offline_timer)
offline_timer.cancel();
@@ -154,10 +160,10 @@ let state_handler = {
},
online: function() {
online = true;
let led = led_find('led-running');
if (!led)
return ubus.STATUS_INVALID_ARGUMENT;
led_write(led, 'trigger', 'default-on');
if (led)
led_write(led, 'trigger', 'default-on');
online_handler();
return 0;
},