diff --git a/packages/shared-state-node_info/Makefile b/packages/shared-state-node_info/Makefile index 5b894b674..b352a5e12 100644 --- a/packages/shared-state-node_info/Makefile +++ b/packages/shared-state-node_info/Makefile @@ -12,7 +12,7 @@ define Package/$(PKG_NAME) TITLE:=Node information module for shared-state MAINTAINER:= Javier DEPENDS:=+lua +luci-lib-jsonc +ubus-lime-utils \ - +lime-system +ubus-lime-location shared-state + +lime-system +ubus-lime-location shared-state-async PKGARCH:=all endef diff --git a/packages/shared-state-node_info/files/etc/shared-state/publishers/shared-state-publish_node_info b/packages/shared-state-node_info/files/etc/shared-state/publishers/shared-state-publish_node_info deleted file mode 120000 index bd21001b3..000000000 --- a/packages/shared-state-node_info/files/etc/shared-state/publishers/shared-state-publish_node_info +++ /dev/null @@ -1 +0,0 @@ -../../../usr/bin/shared-state-publish_node_info \ No newline at end of file diff --git a/packages/shared-state-node_info/files/etc/uci-defaults/shared-state_node_info_cron b/packages/shared-state-node_info/files/etc/uci-defaults/shared-state_node_info_cron index 27132a824..bd3777f25 100755 --- a/packages/shared-state-node_info/files/etc/uci-defaults/shared-state_node_info_cron +++ b/packages/shared-state-node_info/files/etc/uci-defaults/shared-state_node_info_cron @@ -1,9 +1,13 @@ #!/bin/sh + unique_append() { grep -qF "$1" "$2" || echo "$1" >> "$2" } -unique_append \ - '*/5 * * * * ((sleep $(($RANDOM % 120)); shared-state sync node_info &> /dev/null)&)'\ - /etc/crontabs/root +uci set shared-state.node_info=dataType +uci set shared-state.node_info.name='node_info' +uci set shared-state.node_info.scope='community' +uci set shared-state.node_info.ttl='2400' +uci set shared-state.node_info.update_interval='33' +uci commit shared-state diff --git a/packages/shared-state-node_info/files/usr/bin/shared-state-publish_node_info b/packages/shared-state-node_info/files/usr/share/shared-state/publishers/shared-state-publish_node_info similarity index 95% rename from packages/shared-state-node_info/files/usr/bin/shared-state-publish_node_info rename to packages/shared-state-node_info/files/usr/share/shared-state/publishers/shared-state-publish_node_info index 309037c6c..eb70a1a58 100755 --- a/packages/shared-state-node_info/files/usr/bin/shared-state-publish_node_info +++ b/packages/shared-state-node_info/files/usr/share/shared-state/publishers/shared-state-publish_node_info @@ -43,4 +43,4 @@ function get_node_info() end local result = { [hostname] = get_node_info() } -io.popen("shared-state insert node_info", "w"):write(JSON.stringify(result)) +io.popen("shared-state-async insert node_info", "w"):write(JSON.stringify(result)) diff --git a/packages/shared-state-node_info/tests/test_shared-state-node_info.lua b/packages/shared-state-node_info/tests/test_shared-state-node_info.lua index 498c419f6..78d12615d 100644 --- a/packages/shared-state-node_info/tests/test_shared-state-node_info.lua +++ b/packages/shared-state-node_info/tests/test_shared-state-node_info.lua @@ -4,7 +4,7 @@ local utils = require('lime.utils') local uci = nil -package.path = package.path .. ";packages/shared-state-node_info/files/usr/bin/?;;" +package.path = package.path .. ";packages/shared-state-node_info/files/usr/share/shared-state/publishers/?;;" require ("shared-state-publish_node_info") describe('Tests network_nodes #network_nodes', function () diff --git a/packages/shared-state-wifi_links_info/Makefile b/packages/shared-state-wifi_links_info/Makefile index 2a5328ff1..9309c276f 100644 --- a/packages/shared-state-wifi_links_info/Makefile +++ b/packages/shared-state-wifi_links_info/Makefile @@ -20,7 +20,7 @@ define Package/$(PKG_NAME) MAINTAINER:= URL:=http://libremesh.org DEPENDS:=+lua +luci-lib-jsonc +ubus-lime-utils \ - +lime-system +libiwinfo-lua shared-state + +lime-system +libiwinfo-lua shared-state-async PKGARCH:=all endef diff --git a/packages/shared-state-wifi_links_info/files/etc/shared-state/publishers/shared-state-publish_wifi_links_info b/packages/shared-state-wifi_links_info/files/etc/shared-state/publishers/shared-state-publish_wifi_links_info deleted file mode 120000 index 60d85cad4..000000000 --- a/packages/shared-state-wifi_links_info/files/etc/shared-state/publishers/shared-state-publish_wifi_links_info +++ /dev/null @@ -1 +0,0 @@ -../../../usr/bin/shared-state-publish_wifi_links_info \ No newline at end of file diff --git a/packages/shared-state-wifi_links_info/files/etc/uci-defaults/shared-state_wifi_links_info b/packages/shared-state-wifi_links_info/files/etc/uci-defaults/shared-state_wifi_links_info index 483e0ab4f..e2f0b4ada 100755 --- a/packages/shared-state-wifi_links_info/files/etc/uci-defaults/shared-state_wifi_links_info +++ b/packages/shared-state-wifi_links_info/files/etc/uci-defaults/shared-state_wifi_links_info @@ -1,9 +1,20 @@ #!/bin/sh + unique_append() { grep -qF "$1" "$2" || echo "$1" >> "$2" } -unique_append \ - '*/5 * * * * ((sleep $(($RANDOM % 120)); shared-state sync wifi_links_info &> /dev/null)&)'\ - /etc/crontabs/root +uci set shared-state.wifi_links_info=dataType +uci set shared-state.wifi_links_info.name='wifi_links_info' +uci set shared-state.wifi_links_info.scope='community' +uci set shared-state.wifi_links_info.ttl='2400' +uci set shared-state.wifi_links_info.update_interval='33' +uci commit shared-state + +## Refference state data type +uci set shared-state.wifi_links_info_ref=dataType +uci set shared-state.wifi_links_info_ref.name='wifi_links_info_ref' +uci set shared-state.wifi_links_info_ref.scope='community' +uci set shared-state.wifi_links_info_ref.ttl='2400' +uci set shared-state.wifi_links_info_ref.update_interval='50' \ No newline at end of file diff --git a/packages/shared-state-wifi_links_info/files/usr/bin/shared-state-publish_wifi_links_info b/packages/shared-state-wifi_links_info/files/usr/share/shared-state/publishers/shared-state-publish_wifi_links_info similarity index 73% rename from packages/shared-state-wifi_links_info/files/usr/bin/shared-state-publish_wifi_links_info rename to packages/shared-state-wifi_links_info/files/usr/share/shared-state/publishers/shared-state-publish_wifi_links_info index 48301e0b0..988c02e51 100755 --- a/packages/shared-state-wifi_links_info/files/usr/bin/shared-state-publish_wifi_links_info +++ b/packages/shared-state-wifi_links_info/files/usr/share/shared-state/publishers/shared-state-publish_wifi_links_info @@ -2,7 +2,7 @@ --! LibreMesh --! Copyright (C) 2019 Gioacchino Mazzurco ---! Copyright (C) 2019 Javier Jorge +--! Copyright (C) 2024 Javier Jorge --! --! This program is free software: you can redistribute it and/or modify --! it under the terms of the GNU Affero General Public License as @@ -28,17 +28,20 @@ function get_wifi_links_info() local links = {} for _, station in ipairs(stations) do macparts = network.get_mac(station.iface) - src_macaddr = table.concat(macparts,":") + src_macaddr = string.lower(table.concat(macparts,":")) local station_stats = node_status.get_station_stats(station) local freq = iwinfo.nl80211.frequency(station.iface) - table.insert(links, {src_mac=src_macaddr ,dst_mac=station.station_mac, + local chanenel = iwinfo.nl80211.channel(station.iface) + local key_table = {string.lower(string.gsub(src_macaddr,":","")),string.lower(string.gsub(station.station_mac,":",""))} + table.sort(key_table) + links[table.concat(key_table)]= {src_mac=src_macaddr ,dst_mac=string.lower(station.station_mac), signal=station_stats.signal,chains=station_stats.chains,iface=station.iface, - rx_rate=station_stats.rx_rate,tx_rate=station_stats.tx_rate,freq=freq } ) + rx_rate=station_stats.rx_rate,tx_rate=station_stats.tx_rate,freq=freq, channel = chanenel } end + utils.printJson(links) return links end local hostname = io.input("/proc/sys/kernel/hostname"):read("*line") local result = { [hostname] = get_wifi_links_info() } -io.popen("shared-state insert wifi_links_info", "w"):write(JSON.stringify(result)) - +io.popen("shared-state-async insert wifi_links_info", "w"):write(JSON.stringify(result)) diff --git a/packages/shared-state-wifi_links_info/tests/test_shared-state_wifi_links_info.lua b/packages/shared-state-wifi_links_info/tests/test_shared-state_wifi_links_info.lua index 98de1e7fb..4d59d425c 100644 --- a/packages/shared-state-wifi_links_info/tests/test_shared-state_wifi_links_info.lua +++ b/packages/shared-state-wifi_links_info/tests/test_shared-state_wifi_links_info.lua @@ -2,7 +2,7 @@ local utils = require "lime.utils" local node_status = require 'lime.node_status' local iwinfo = require('iwinfo') -package.path = package.path .. ";packages/shared-state-wifi_links_info/files/usr/bin/?;;" +package.path = package.path .. ";packages/shared-state-wifi_links_info/files/usr/share/shared-state/publishers/?;;" require ("shared-state-publish_wifi_links_info") it('a simple test to get links info and assert requiered fields are present', function() @@ -24,13 +24,13 @@ it('a simple test to get links info and assert requiered fields are present', fu local links_info = {} links_info = get_wifi_links_info() - assert.is.equal(26000, links_info[1].tx_rate) - assert.is.equal("C0:4A:00:BE:7B:09", links_info[1].dst_mac) - assert.is.same({-17,-18}, links_info[1].chains) - assert.is.equal(-14, links_info[1].signal) - assert.is.equal("wlan0-mesh", links_info[1].iface) - assert.is.equal(13000, links_info[1].rx_rate) - assert.is.equal(2400, links_info[1].freq) - assert.is.equal("C0:00:00:00:00:00", links_info[1].src_mac) + assert.is.equal(26000, links_info["c00000000000c04a00be7b09"].tx_rate) + assert.is.equal("c0:4a:00:be:7b:09", links_info["c00000000000c04a00be7b09"].dst_mac) + assert.is.same({-17,-18}, links_info["c00000000000c04a00be7b09"].chains) + assert.is.equal(-14, links_info["c00000000000c04a00be7b09"].signal) + assert.is.equal("wlan0-mesh", links_info["c00000000000c04a00be7b09"].iface) + assert.is.equal(13000, links_info["c00000000000c04a00be7b09"].rx_rate) + assert.is.equal(2400, links_info["c00000000000c04a00be7b09"].freq) + assert.is.equal("c0:00:00:00:00:00", links_info["c00000000000c04a00be7b09"].src_mac) end)