Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add wireless infos #41

Merged
merged 7 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 54 additions & 1 deletion unifi_respondd/respondd_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,25 @@ class ClientInfo:
wifi5: int


@dataclasses.dataclass
class WirelessInfo:
"""This class contains the Wireless information of an AP.
Attributes:
frequency:
noise:
active:
busy:
rx:
tx:"""

frequency: int
# noise: int
# active: int
# busy: int
rx: int
tx: int


@dataclasses.dataclass
class MemoryInfo:
"""This class contains the memory information of an AP.
Expand Down Expand Up @@ -178,7 +197,11 @@ class StatisticsInfo:
node_id: The node id of the AP. This is the same as the MAC address (without :).
loadavg: The load average of the AP.
memory: The memory information of the AP.
traffic: The traffic information of the AP."""
traffic: The traffic information of the AP.
gateway: The MAC of the IPv4 Gateway
gateway6: The MAC of the IPv6 Gateway
gateway_nexthop: The MAC of the nexthop Gateway
wireless: The WirelessInfos of the AP"""

clients: ClientInfo
uptime: int
Expand All @@ -189,6 +212,7 @@ class StatisticsInfo:
gateway: str
gateway6: str
gateway_nexthop: str
wireless: List[WirelessInfo]


@dataclasses.dataclass
Expand Down Expand Up @@ -268,11 +292,39 @@ def getNodeInfos(self):
)
return nodes

@staticmethod
def frequency_from_channel(channel):
if channel >= 36:
return 5000 + (channel - 36) * 5
else:
if channel == 14:
return 2484
elif channel < 14:
return 2407 + (channel - 1) * 5

Copy link
Member Author

@T0biii T0biii May 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fyi: from chatgpt
maybe need some more work

https://de.mathworks.com/help/wlan/ref/wlanchannelfrequency.html

def getStatistics(self):
"""This method returns the statistics information of all APs."""
aps = self._aps
statistics = []
for ap in aps.accesspoints:
wirelessinfos = []
frequency5 = self.frequency_from_channel(ap.channel5)
wirelessinfos.append(
WirelessInfo(
frequency=frequency5,
rx=ap.rx_bytes5,
tx=ap.tx_bytes5,
)
)
frequency24 = self.frequency_from_channel(ap.channel24)
wirelessinfos.append(
WirelessInfo(
frequency=frequency24,
rx=ap.rx_bytes5,
tx=ap.tx_bytes5,
)
)

statistics.append(
StatisticsInfo(
clients=ClientInfo(
Expand All @@ -296,6 +348,7 @@ def getStatistics(self):
gateway=ap.gateway,
gateway6=ap.gateway6,
gateway_nexthop=ap.gateway_nexthop,
wireless=wirelessinfos,
)
)
return statistics
Expand Down
41 changes: 41 additions & 0 deletions unifi_respondd/unifi_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ class Accesspoint:
client_count: int
client_count24: int
client_count5: int
channel5: int
rx_bytes5: bytes
tx_bytes5: bytes
channel24: int
rx_bytes24: bytes
tx_bytes24: bytes
latitude: float
longitude: float
model: str
Expand Down Expand Up @@ -86,6 +92,25 @@ def get_client_count_for_ap(ap_mac, clients, cfg):
return client24_count + client5_count, client24_count, client5_count


def get_ap_channel_usage(ssids, cfg):
"""This function returns the channels used for the Freifunk SSIDs"""
for ssid in ssids:
if re.search(cfg.ssid_regex, ssid.get("essid", "")):
channel = ssid.get("channel", 0)
rx_bytes = ssid.get("rx_bytes", 0)
tx_bytes = ssid.get("tx_bytes", 0)
if channel > 14:
channel5 = channel
rx_bytes5 = rx_bytes
tx_bytes5 = tx_bytes
else:
channel24 = channel
rx_bytes24 = tx_bytes
tx_bytes24 = tx_bytes

return channel5, rx_bytes5, tx_bytes5, channel24, rx_bytes24, tx_bytes24


def get_location_by_address(address, app):
"""This function returns latitude and longitude of a given address."""
time.sleep(1)
Expand Down Expand Up @@ -162,6 +187,16 @@ def get_infos():
client_count24,
client_count5,
) = get_client_count_for_ap(ap.get("mac", None), clients, cfg)

(
channel5,
rx_bytes5,
tx_bytes5,
channel24,
rx_bytes24,
tx_bytes24,
) = get_ap_channel_usage(ssids, cfg)

lat, lon = 0, 0
neighbour_macs = []
if ap.get("snmp_location", None) is not None:
Expand Down Expand Up @@ -203,6 +238,12 @@ def get_infos():
client_count=client_count,
client_count24=client_count24,
client_count5=client_count5,
channel5=channel5,
rx_bytes5=rx_bytes5,
tx_bytes5=tx_bytes5,
channel24=channel24,
rx_bytes24=rx_bytes24,
tx_bytes24=tx_bytes24,
latitude=float(lat),
longitude=float(lon),
model=ap.get("model", None),
Expand Down
Loading