Переглянути джерело

Fix fs_event API, use timers for all watchers

- fs_event_start takes 2 args (handle, path), not 3
- Use timer-based polling instead (more compatible)
- DHCP: 2s interval
- WiFi: 5s interval
- SSID: 30s interval
Gogs 2 місяців тому
батько
коміт
776b9bc77a
1 змінених файлів з 7 додано та 21 видалено
  1. 7 21
      usr/sbin/client2server-luv.lua

+ 7 - 21
usr/sbin/client2server-luv.lua

@@ -294,29 +294,13 @@ local function start_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()
-        -- 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)
+    log_info("DHCP timer started (2s interval)")
     
     -- 2. WiFi: Timer-based but frequent (every 5s)
     local wifi_timer = luv.new_timer()
@@ -324,6 +308,7 @@ local function start_async_watchers()
         log_info("WiFi check (timer)...")
         check_and_report()
     end)
+    log_info("WiFi timer started (5s interval)")
     
     -- 3. SSID: Less frequent (every 30s)
     local ssid_timer = luv.new_timer()
@@ -331,6 +316,7 @@ local function start_async_watchers()
         log_info("SSID check (timer)...")
         check_and_report()
     end)
+    log_info("SSID timer started (30s interval)")
     
     return true
 end