|
@@ -294,29 +294,13 @@ local function start_async_watchers()
|
|
|
|
|
|
|
|
log_info("Starting async watchers...")
|
|
log_info("Starting async watchers...")
|
|
|
|
|
|
|
|
- -- 1. DHCP: Watch lease file with fs_event (REACT IMMEDIATELY)
|
|
|
|
|
- local fs_event = luv.new_fs_event()
|
|
|
|
|
- local function watch_dhcp()
|
|
|
|
|
- log_info("DHCP lease file changed - checking...")
|
|
|
|
|
|
|
+ -- 1. DHCP: Timer-based but frequent (every 2s - reacts fast)
|
|
|
|
|
+ local dhcp_timer = luv.new_timer()
|
|
|
|
|
+ luv.timer_start(dhcp_timer, 2000, 2000, function()
|
|
|
|
|
+ log_info("DHCP check (timer)...")
|
|
|
check_and_report()
|
|
check_and_report()
|
|
|
- -- Re-watch
|
|
|
|
|
- luv.fs_event_start(fs_event, cfg.dhcp_lease_file, function(err)
|
|
|
|
|
- if err then
|
|
|
|
|
- log_info("DHCP fs_event error: " .. err)
|
|
|
|
|
- else
|
|
|
|
|
- watch_dhcp()
|
|
|
|
|
- end
|
|
|
|
|
- end)
|
|
|
|
|
- end
|
|
|
|
|
- -- Start watching
|
|
|
|
|
- luv.fs_event_start(fs_event, cfg.dhcp_lease_file, function(err)
|
|
|
|
|
- if err then
|
|
|
|
|
- log_info("DHCP watch error: " .. err)
|
|
|
|
|
- else
|
|
|
|
|
- log_info("Watching DHCP leases: " .. cfg.dhcp_lease_file)
|
|
|
|
|
- watch_dhcp()
|
|
|
|
|
- end
|
|
|
|
|
end)
|
|
end)
|
|
|
|
|
+ log_info("DHCP timer started (2s interval)")
|
|
|
|
|
|
|
|
-- 2. WiFi: Timer-based but frequent (every 5s)
|
|
-- 2. WiFi: Timer-based but frequent (every 5s)
|
|
|
local wifi_timer = luv.new_timer()
|
|
local wifi_timer = luv.new_timer()
|
|
@@ -324,6 +308,7 @@ local function start_async_watchers()
|
|
|
log_info("WiFi check (timer)...")
|
|
log_info("WiFi check (timer)...")
|
|
|
check_and_report()
|
|
check_and_report()
|
|
|
end)
|
|
end)
|
|
|
|
|
+ log_info("WiFi timer started (5s interval)")
|
|
|
|
|
|
|
|
-- 3. SSID: Less frequent (every 30s)
|
|
-- 3. SSID: Less frequent (every 30s)
|
|
|
local ssid_timer = luv.new_timer()
|
|
local ssid_timer = luv.new_timer()
|
|
@@ -331,6 +316,7 @@ local function start_async_watchers()
|
|
|
log_info("SSID check (timer)...")
|
|
log_info("SSID check (timer)...")
|
|
|
check_and_report()
|
|
check_and_report()
|
|
|
end)
|
|
end)
|
|
|
|
|
+ log_info("SSID timer started (30s interval)")
|
|
|
|
|
|
|
|
return true
|
|
return true
|
|
|
end
|
|
end
|