neighbours-batadv 851 B

1234567891011121314151617181920212223242526272829303132
  1. #!/usr/bin/lua
  2. local json = require 'luci.jsonc'
  3. local nixio = require 'nixio'
  4. function neighbours()
  5. local neighbours = {}
  6. local list = io.lines("/sys/kernel/debug/batman_adv/bat0/originators")
  7. for line in list do
  8. local mac1, lastseen, tq, mac2, ifname =
  9. line:match("^([0-9a-f:]+) +(%d+%.%d+)s +%( *(%d+)%) +([0-9a-f:]+) +%[ *(.-)%]")
  10. if mac1 ~= nil and mac1 == mac2 then
  11. neighbours[mac1] = { tq = tonumber(tq)
  12. , lastseen = tonumber(lastseen)
  13. , ifname = ifname
  14. }
  15. end
  16. end
  17. return neighbours
  18. end
  19. io.write("Access-Control-Allow-Origin: *\n")
  20. io.write("Content-type: text/event-stream\n\n")
  21. while true do
  22. local neighbours = json.stringify(neighbours())
  23. io.write("data: " .. neighbours .. "\n\n")
  24. io.flush()
  25. nixio.nanosleep(1, 0)
  26. end