You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
3.0 KiB

  1. --- a/usr/lib/byobu/wifi_quality
  2. +++ b/usr/lib/byobu/wifi_quality
  3. @@ -19,32 +19,61 @@
  4. # You should have received a copy of the GNU General Public License
  5. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  6. +___get_dev_list() {
  7. + if [ -n "$MONITORED_NETWORK" ]; then
  8. + echo "$MONITORED_NETWORK"
  9. + else
  10. + iw dev | grep Interface | cut -f2 -d\
  11. + fi
  12. +}
  13. +
  14. __wifi_quality_detail() {
  15. - /sbin/iwconfig 2>/dev/null
  16. + if eval $BYOBU_TEST iw >/dev/null 2>&1; then
  17. + local dev
  18. + for dev in $(___get_dev_list); do
  19. + iw dev "$dev" info
  20. + iw dev "$dev" link
  21. + echo
  22. + done
  23. + elif eval $BYOBU_TEST iwconfig >/dev/null 2>&1; then
  24. + iwconfig 2>/dev/null
  25. + fi
  26. }
  27. __wifi_quality() {
  28. local out bitrate quality
  29. - # iwconfig is expected to output lines like:
  30. - # Bit Rate=54 Mb/s Tx-Power=15 dBm
  31. - # Link Quality=60/70 Signal level=-50 dBm
  32. - # the awk below tokenizes the output and prints shell evalable results
  33. - out=`iwconfig $MONITORED_NETWORK 2>/dev/null |
  34. - awk '$0 ~ /[ ]*Link Quality./ {
  35. - sub(/.*=/,"",$2); split($2,a,"/");
  36. - printf "quality=%.0f\n", 100*a[1]/a[2] };
  37. - $0 ~ /[ ]*Bit Rate/ { sub(/.*[:=]/,"",$2); printf("bitrate=%s\n", $2); }
  38. - '`
  39. - eval "$out"
  40. - [ -z "$bitrate" ] && bitrate="0"
  41. - if [ -z "$quality" ] || [ "$quality" = "0" ]; then
  42. - quality="0"
  43. + if eval $BYOBU_TEST iw >/dev/null 2>&1; then
  44. + local dev
  45. + for dev in $(___get_dev_list); do
  46. + # signal to quality: https://superuser.com/a/1360447
  47. + out=`iw dev "$dev" link 2>/dev/null |
  48. + awk '$0 ~ /^\s*signal:/ { a = 100 * ($2 + 110) / 70;
  49. + printf "quality=%.0f\n", (a > 100) ? 100 : ((a < 0) ? 0 : a); }
  50. + $0 ~ /^\s*tx bitrate:/ { printf "bitrate=%s\n", $3; }
  51. + '`
  52. + eval "$out"
  53. + [ -z "$bitrate" ] || [ -z "$quality" ] || break
  54. + done
  55. + elif eval $BYOBU_TEST iwconfig >/dev/null 2>&1; then
  56. + # iwconfig is expected to output lines like:
  57. + # Bit Rate=54 Mb/s Tx-Power=15 dBm
  58. + # Link Quality=60/70 Signal level=-50 dBm
  59. + # the awk below tokenizes the output and prints shell evalable results
  60. + out=`iwconfig $MONITORED_NETWORK 2>/dev/null |
  61. + awk '$0 ~ /[ ]*Link Quality./ {
  62. + sub(/.*=/,"",$2); split($2,a,"/");
  63. + printf "quality=%.0f\n", 100*a[1]/a[2] };
  64. + $0 ~ /[ ]*Bit Rate/ { sub(/.*[:=]/,"",$2); printf("bitrate=%s\n", $2); }
  65. + '`
  66. + eval "$out"
  67. fi
  68. - if [ "$bitrate" = "0" ] || [ "$quality" = "0" ] || [ -z "$bitrate" ] || [ -z "$quality"]; then
  69. + [ -n "$bitrate" ] || bitrate=0
  70. + [ -n "$quality" ] || quality=0
  71. + if [ "$bitrate" -gt 0 ] && [ "$quality" -gt 0 ]; then
  72. + printf "${ICON_WIFI}"; color b C k; printf "%s" "$bitrate"; color -; color C k; printf "%s" "$ICON_MBPS"; color -; color b C k; printf "%s" "$quality"; color -; color C k; printf "%s" "$PCT"; color --
  73. + else
  74. rm -f "$BYOBU_RUN_DIR/status.$BYOBU_BACKEND/wifi_quality"*
  75. - return
  76. fi
  77. - printf "${ICON_WIFI}"; color b C k; printf "%s" "$bitrate"; color -; color C k; printf "%s" "$ICON_MBPS"; color -; color b C k; printf "%s" "$quality"; color -; color C k; printf "%s" "$PCT"; color --
  78. }
  79. # vi: syntax=sh ts=4 noexpandtab