|
@@ -565,7 +565,9 @@ local function main()
|
|
|
|
|
|
|
|
if luv_ok then
|
|
if luv_ok then
|
|
|
-- Use luv event loop
|
|
-- Use luv event loop
|
|
|
- luv.run(function()
|
|
|
|
|
|
|
+ -- luv.run() starts the event loop. The callbacks we registered
|
|
|
|
|
+ -- (timers, fs_events) will run automatically.
|
|
|
|
|
+ local function start_monitors()
|
|
|
-- Start all monitors in parallel
|
|
-- Start all monitors in parallel
|
|
|
monitor_wifi_events()
|
|
monitor_wifi_events()
|
|
|
monitor_dhcp_leases()
|
|
monitor_dhcp_leases()
|
|
@@ -575,8 +577,22 @@ local function main()
|
|
|
-- Keep the event loop running
|
|
-- Keep the event loop running
|
|
|
local idle = luv.new_idle()
|
|
local idle = luv.new_idle()
|
|
|
luv.idle_start(idle, function()
|
|
luv.idle_start(idle, function()
|
|
|
- -- Idle work
|
|
|
|
|
|
|
+ -- Idle work - just keep loop alive
|
|
|
end)
|
|
end)
|
|
|
|
|
+ end
|
|
|
|
|
+
|
|
|
|
|
+ -- Start monitors first, then run the event loop
|
|
|
|
|
+ start_monitors()
|
|
|
|
|
+
|
|
|
|
|
+ -- luv.run() - start the event loop (no arguments)
|
|
|
|
|
+ local ok, err = pcall(luv.run)
|
|
|
|
|
+ if not ok then
|
|
|
|
|
+ log("err", "luv.run error: " .. tostring(err))
|
|
|
|
|
+ -- Fallback: sequential mode
|
|
|
|
|
+ while true do
|
|
|
|
|
+ os.execute("sleep 60")
|
|
|
|
|
+ end
|
|
|
|
|
+ end
|
|
|
|
|
|
|
|
-- WebSocket connection and keepalive
|
|
-- WebSocket connection and keepalive
|
|
|
while true do
|
|
while true do
|