Get signal quality in % from iwconfig - awk

first post for help....
I am trying to get signal quality in % from the iwconfig command...
I began with this command but it returns the text 'signal value'
iwconfig wlan0 | grep Quality | awk -F '=|/|=[ ]' '{print $2,$3}'
70 70 Signal level
I'd like just want to have '100%' as a result
wlan0 IEEE 802.11 ESSID:"SKYNET"
Mode:Managed Frequency:2.412 GHz Access Point: AC:84:C9:CD:79:E0
Bit Rate=72.2 Mb/s Tx-Power=31 dBm
Retry short limit:7 RTS thr:off Fragment thr:off
Power Management:on
Link Quality=68/70 Signal level=-42 dBm
Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0
Tx excessive retries:51 Invalid misc:0 Missed beacon:0

Following is doing (68/70)*100. using split() 68 is stored in a[2] whereas 70 is stored in a[3]
iwconfig wlan0|awk '/Link Quality/{split($2,a,"=|/");print (a[2]/a[3])*100"%"}'
97.1429%
for integer result:
iwconfig wlan0|awk '/Link Quality/{split($2,a,"=|/");print int((a[2]/a[3])*100)"%"}'
97%
or just use printf:
iwconfig wlan0|awk '/Link Quality/{split($2,a,"=|/");printf "%d%s\n", (a[2]/a[3])*100, "%"}'
97%
PS: Tested with the output supplied by OP in question.

Related

Issues converting a small Hex value to a Binary value

I am trying to take the contents of a file that has a Hex number and convert that number to Binary and output to a file.
This is what I am trying but not getting the binary value:
xxd -r -p Hex.txt > Binary.txt
The contents of Hex.txt is: ff
I have also tried FF and 0xFF, but would like to just use ff since the device I am pulling the info from has it in that format.
Instead of 11111111 which it should be, I get a y with 2 dots above it.
If I change it to ee, I get an i with 2 dots. It seems to be reading it just fine but according to what I have read on the xxd -r -p command, it is not outputing it in the correct format.
The other ways I have found to convert Hex to Binary have either also not worked or is a pretty big Bash script that seems unnecessary to do what I thought would be a simple task.
This also gives me the y with 2 dots.
$ for i in $(cat Hex.txt) ; do printf "\x$i" ; done > Binary.txt
For some reason almost every solution I find gives me this format instead of a human readable Binary value with 1s and 0s.
Any help is appreciated. I am planning on using this in a script to pull the Relay values from Digital Loggers devices using curl and giving Home Assistant a readable file to record the Relay State. Digital Loggers curl cmd gives the state of all 8 relays at once using Hex instead of being able to pull the status of a specific relay.
If "file.txt" contains:
fe
0a
and you run this:
perl -ane 'printf("%08b\n",hex($_))' file.txt
You'll get this:
11111110
00001010
If you use it a lot, you might want to make a bash function of it in your login profile along these lines - being extremely respectful of spaces and semi-colons that might look unnecessary:
bin(){ perl -ane 'printf("%08b\n",hex($_))' $1 ; }
Then you'll be able to do:
bin file.txt
If you dislike Perl for some reason, you can achieve something similar without it as follows:
tr '[:lower:]' '[:upper:]' < file.txt |
while read h ; do
echo "obase=2; ibase=16; $h" | bc
done

iperf3 results in packets per second?

Can iperf3 report measurements also in terms of packets per second, when generating UDP traffic?
A typical output with the verbose mode is the following:
Test Complete. Summary Results:
[ ID] Interval Transfer Bandwidth Jitter Lost/Total Datagrams
[ 4] 0.00-10.00 sec 1.64 GBytes 1.41 Gbits/sec 0.010 ms 804029/1208925 (67%)
[ 4] Sent 1208925 datagrams
CPU Utilization: local/sender 99.6% (16.4%u/83.3%s), remote/receiver 0.1% (0.0%u/0.1%s)
iperf Done.
I see that in iperf2 one could specify the input rate in pps, but there is no mentioning of the measured received rate (I don't see this feature in iperf3 anyway)
I don't see an option for pps in iperf3, however the link below details a way to get what you are looking for.
https://discuss.aerospike.com/t/benchmarking-throughput-and-packet-count-with-iperf3/2791
Run your iperf3 test as you normally would. On the server create a script containing the following:
#!/bin/bash
INTERVAL="1" # update interval in seconds
if [ -z "$1" ]; then
echo
echo usage: $0 [network-interface]
echo
echo e.g. $0 eth0
echo
echo shows packets-per-second
exit
fi
IF=$1
while true
do
R1=`cat /sys/class/net/$1/statistics/rx_packets`
T1=`cat /sys/class/net/$1/statistics/tx_packets`
sleep $INTERVAL
R2=`cat /sys/class/net/$1/statistics/rx_packets`
T2=`cat /sys/class/net/$1/statistics/tx_packets`
TXPPS=`expr $T2 - $T1`
RXPPS=`expr $R2 - $R1`
echo "TX $1: $TXPPS pkts/s RX $1: $RXPPS pkts/s"
done
This will give you an output in terms of packets per second.

How can I get the disk IO trace with actual input values?

I want to generate some trace file from disk IO, but the problem is I need the actual input data along with timestamp, logical address and access block size, etc.
I've been trying to solve the problem by using the "blktrace | blkparse" with "iozone" on the ubuntu VirtualBox environment, but it seems not working.
There is an option in blkparse for setting the output format to show the packet data, -f "%P", but it dose not print anything.
below is the command that i use:
$> sudo blktrace -a issue -d /dev/sda -o - | blkparse -i - -o ./temp/blktrace.sda.iozone -f "%-12C\t\t%p\t%d\t%S:%n:%N\t\t%P\n"
$> iozone -w -e -s 16M -f ./mnt/iozone.dummy -i 0
In the printing format "%-12C\t\t%p\t%d\t%S:%n:%N\t\t%P\n", all other things are printed well, but the "%P" is not printed at all.
Is there anyone who knows why the packet data is not displayed?
OR anyone who knows other way to get the disk IO packet data with actual input value?
As far as I know blktrace does not capture the actual data. It just capture the metadata. One way to capture real data is to write your own kernel module. Some students at FIU.edu did that in this paper:
"I/O deduplication: Utilizing content similarity to ..."
I would ask this question in linux-btrace mailing list as well:
http://vger.kernel.org/majordomo-info.html

In Bluez A2DP: how can I modify the default audio sample rate

I am using Bluez4 to sink Audio from an iphone 5 to a Raspberry pi audio output.
The default settings for BLuez 4 A2DP appear to be S16_LE, 44,1kHz Stereo.
Similar to other posts about Bluez, I can't catch Select_Configuration DBus messages in order to change the sample rate dynamically. Instead I decided to try to find the default A2DP sample rate in the BLuez Stack.
Does anyone know where the default sample rate is set? My first thought was that it was in the BLuez/audio/ folder but nothing appears to change the default 44.1kHz sample rate.
Now I'm very curious to know where it is set.
Currently using this: sudo ./a2dp-alsa --sink | aplay -c 2 -r 44100 -f S16
would like to use this sudo ./a2dp-alsa --sink | aplay -c 2 -r 16000 -f S16
I came across these lines in a2dp-alsa.c
/* Initialise connection to ALSA */
g_handle = audio_init("hw:0,0", 48000);
maybe its hard coded in a2dp-alsa - not parameterizable

Setting DTR high, RTS low using Linux bash?

I have a serial device that has no flow control, but is powered from the RS232 port by holding the RTS high and DTR low
I was hoping to read from this device using a simple bash script, but can't find any way to set the handshaking lines, using stty or otherwise, to allow for the above configuration.
Any ideas if this is possible?
I don't have an answer about setting RTS without touching DTR, because I don't have any DTR pin on my dongle; but, trying to set RTS was already very tricky un pure shell.
You may need to play with stty crtscts and clocal flags.
I have published a detailed answer here:
https://forums.gentoo.org/viewtopic-p-8132756.html#8132756
Here is the short version:
#!/bin/bash
MySerialPort="/dev/ttyUSB0"
MyLatency="2"
echo "#include <fcntl.h>
#include <sys/ioctl.h>
main()
{ int fd; fd = open(\"${MySerialPort}\",O_RDWR | O_NOCTTY );
int RTS_flag; RTS_flag = TIOCM_RTS;
ioctl(fd,TIOCMBIS,&RTS_flag);
sleep (${MyLatency});
ioctl(fd,TIOCMBIC,&RTS_flag);
close(fd); } " | tcc -run -
Note that sending data on TX will probably mess RTS; see the Gentoo forum for details.
I've been trying something similar here.
I used the ioctls. Then measured with a multimeter.
this is what I found:
dsrv=TIOCM_DTR;//this sets RTS to -11.7?
dsrv=TIOCM_RTS;//sets DTR -11.7
ioctl(fd, TIOCMBIS, &dsrv);
dsrv=TIOCM_DTR;//this sets RTS to 11.7?
dsrv=TIOCM_RTS;//sets DTR 11.7
ioctl(fd, TIOCMBIC, &dsrv);
It is somewhat weird...
socat controls DTR when hucpcl=1
(Atmel EDBG USB Serial needs DTR high)
sleep 1; while true; do echo -en "\x01\x02"; sleep 0.1; done | socat -T1 -t1 - /dev/ttyUSB0,hupcl=1,raw,b1000000,cs8,echo=0
man socat - may be find more solutions for your serial problem.