diff --git a/packages/shared-state-babel_links_info/Makefile b/packages/shared-state-babel_links_info/Makefile new file mode 100644 index 000000000..3fca60520 --- /dev/null +++ b/packages/shared-state-babel_links_info/Makefile @@ -0,0 +1,23 @@ +# +# Copyright (C) 2023 Javier Jorge +# Copyright (C) 2023 AsociaciĆ³n Civil Altermundi +# This is free software, licensed under the GNU Affero General Public License v3. +# + +include ../../libremesh.mk + +define Package/$(PKG_NAME) + SECTION:=lime + CATEGORY:=LibreMesh + TITLE:=Babel links information module for shared-state + MAINTAINER:= Javier + DEPENDS:=+lua +luci-lib-jsonc +ubus-lime-utils \ + +lime-system +ubus-lime-location shared-state + PKGARCH:=all +endef + +define Package/$(PKG_NAME)/description + Syncronize Babel links information beween nodes. +endef + +$(eval $(call BuildPackage,$(PKG_NAME))) \ No newline at end of file diff --git a/packages/shared-state-babel_links_info/files/usr/bin/shared-state-publish_babel_links_info b/packages/shared-state-babel_links_info/files/usr/bin/shared-state-publish_babel_links_info new file mode 100755 index 000000000..48301e0b0 --- /dev/null +++ b/packages/shared-state-babel_links_info/files/usr/bin/shared-state-publish_babel_links_info @@ -0,0 +1,44 @@ +#!/usr/bin/lua + +--! LibreMesh +--! Copyright (C) 2019 Gioacchino Mazzurco +--! Copyright (C) 2019 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 +--! published by the Free Software Foundation, either version 3 of the +--! License, or (at your option) any later version. +--! +--! This program is distributed in the hope that it will be useful, +--! but WITHOUT ANY WARRANTY; without even the implied warranty of +--! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +--! GNU Affero General Public License for more details. +--! +--! You should have received a copy of the GNU Affero General Public License +--! along with this program. If not, see . + +local JSON = require("luci.jsonc") +local node_status = require ("lime.node_status") +local network = require ("lime.network") +local iwinfo = require "iwinfo" + + +function get_wifi_links_info() + local stations = node_status.get_stations() + local links = {} + for _, station in ipairs(stations) do + macparts = network.get_mac(station.iface) + src_macaddr = 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, + 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 } ) + end + 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)) +