Add new "quality" tag to "network" module

This commit is contained in:
Delgan 2024-01-03 16:21:49 +01:00 committed by Daniel Eklöf
parent 26bf62a899
commit e1f78a16ab
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
3 changed files with 17 additions and 2 deletions

View file

@ -17,6 +17,7 @@
* battery: current smoothing, for improved discharge estimates. * battery: current smoothing, for improved discharge estimates.
* battery: scale option, for batteries that report 'charge' at a * battery: scale option, for batteries that report 'charge' at a
different scale than 'current'. different scale than 'current'.
* network: new `quality` tag (Wi-Fi only).
### Changed ### Changed

View file

@ -45,6 +45,9 @@ address.
| signal | signal
: int : int
: Signal strength, in dBm (Wi-Fi only) : Signal strength, in dBm (Wi-Fi only)
| quality
: range
: Quality of the signal, in percent (Wi-Fi only)
| rx-bitrate | rx-bitrate
: int : int
: RX bitrate, in bits/s : RX bitrate, in bits/s
@ -72,7 +75,7 @@ address.
| poll-interval | poll-interval
: int : int
: no : no
: Periodically (in milliseconds) update the signal, rx+tx bitrate, and : Periodically (in milliseconds) update the signal, quality, rx+tx bitrate, and
ul+dl speed tags (default=0). Setting it to 0 disables updates. Cannot be less ul+dl speed tags (default=0). Setting it to 0 disables updates. Cannot be less
than 250ms. than 250ms.

View file

@ -154,6 +154,16 @@ content(struct module *mod)
inet_ntop(AF_INET6, &it->item.addr.ipv6, ipv6_str, sizeof(ipv6_str)); inet_ntop(AF_INET6, &it->item.addr.ipv6, ipv6_str, sizeof(ipv6_str));
} }
int quality = 0;
if (m->signal_strength_dbm != 0) {
if (m->signal_strength_dbm <= -100)
quality = 0;
else if (m->signal_strength_dbm >= -50)
quality = 100;
else
quality = 2 * (m->signal_strength_dbm + 100);
}
struct tag_set tags = { struct tag_set tags = {
.tags = (struct tag *[]){ .tags = (struct tag *[]){
tag_new_string(mod, "name", m->iface), tag_new_string(mod, "name", m->iface),
@ -165,12 +175,13 @@ content(struct module *mod)
tag_new_string(mod, "ipv6", ipv6_str), tag_new_string(mod, "ipv6", ipv6_str),
tag_new_string(mod, "ssid", m->ssid), tag_new_string(mod, "ssid", m->ssid),
tag_new_int(mod, "signal", m->signal_strength_dbm), tag_new_int(mod, "signal", m->signal_strength_dbm),
tag_new_int_range(mod, "quality", quality, 0, 100),
tag_new_int(mod, "rx-bitrate", m->rx_bitrate), tag_new_int(mod, "rx-bitrate", m->rx_bitrate),
tag_new_int(mod, "tx-bitrate", m->tx_bitrate), tag_new_int(mod, "tx-bitrate", m->tx_bitrate),
tag_new_float(mod, "dl-speed", m->dl_speed), tag_new_float(mod, "dl-speed", m->dl_speed),
tag_new_float(mod, "ul-speed", m->ul_speed), tag_new_float(mod, "ul-speed", m->ul_speed),
}, },
.count = 13, .count = 14,
}; };
mtx_unlock(&mod->lock); mtx_unlock(&mod->lock);