Trou­bleshoot your Wi-Fi with a Rasp­berry Pi

Hold on to your hats, as we join Sean Con­way rid­ing the RF waves to gain the knowl­edge needed to un­der­stand the in­ner work­ings of wire­less.

APC Australia - - Contents -

All you wanted to do was stream that video, copy that file or try to view a few pho­tos, but the Wi-Fi chooses that ex­act mo­ment to play up. It’s a prob­lem we’ve all en­coun­tered. How do you trou­bleshoot a wire­less con­nec­tion? With some ba­sic ra­dio fre­quency (RF) trans­mis­sion the­ory knowl­edge, an un­der­stand­ing of the lo­cal en­vi­ron­men­tal con­di­tions and a few sim­ple Rasp­berry Pi Linux ap­pli­ca­tions, you’ll be bet­ter pre­pared to tackle Wi-Fi con­nec­tion is­sues in the fu­ture and be­daz­zle fel­low pub go­ers with your IEEE 802.11 knowl­edge, too!

This tu­to­rial make the as­sump­tion that you have some ba­sic ex­pe­ri­ence with a Rasp­berry Pi. What does that mean? It’s al­ways a strug­gle to de­ter­mine what to put into a tu­to­rial verses what to leave out. Here, the as­sump­tion per­mits the au­thor to min­imise de­tails on some com­mon Pi tasks, in favour of greater de­tails on tasks the tu­to­rial is designed to cover.

An ex­am­ple would be us­ing a com­pat­i­ble Pi Wi-Fi at­tach­ment. If you’re not con­fi­dent in your own Pi Wi-Fi at­tach­ment, we’ve as­sumed you’ve al­ready looked into the mat­ter, such as search around on Google search.

In this sce­nario, the Rasp­berry Pi will be the host try­ing to con­nect to a ven­dor’s mo­dem (the ac­cess point, or AP) that sup­ports wire­less. Here’s a bill of ma­te­ri­als for the setup used in this tu­to­rial: OS: 2017-01-11-rasp­bian-jessie.img Hard­ware: Rasp­berry Pi Model B (Rev 2.0, 512MB): re­vi­sion 000E Wi-Fi: Ralink Tech­nol­ogy, Corp. RT5370 Wire­less Adapter To in­stall the rasp­berry Pi OS con­sult the www.rasp­ber­ site. The URL is the first choice when look­ing for all things Pi. The link re­flects in­struc­tions that are rel­e­vant to the cur­rent OS (also see www.rasp­ber­rypi. org/doc­u­men­ta­tion/in­stal­la­tion/ in­stalling-im­ages).

With the OS in­stalled there are a few raspi-con­fig op­tions that are em­ployed to tai­lor the OS. You can ex­pand the file sys­tem to take ad­van­tage of the larger mem­ory cards be­ing used, and per­son­alise the de­vice by giv­ing it a host­name. In­ter­na­tion­al­i­sa­tion op­tions are tweaked to ac­com­mo­date what side of the At­lantic the Pi re­sides. Turn­ing on SSH and turn­ing off a GUI con­sole im­poses the com­mand line in­ter­face (CLI). A fi­nal touch is a pass­word change. To keep the bad guys out, never leave pass­word de­faults unat­tended. The ref­er­ence link www.rasp­ber­­u­men­ta­tion/ configuration/raspi-con­ can pro­vide the specifics we’ve just sum­marised here.

A quick re­boot of the de­vice to con­firm all the op­tions are in order. Then per­form a com­mand line up­date and up­grade as the fi­nal step be­fore we es­tab­lish the Pi setup for stag­ing this WiFi tu­to­rial.


To start the ex­er­cise, the Pi is con­nected to a wired net­work. This en­ables an SSH con­nec­tion to the ter­mi­nal com­mand line in­ter­face. In­stall the Wi-Fi don­gle. USB at­tach­ments can be in­stalled or re­moved with the Pi power on. Ex­am­ine the dmesg logs to gather in­for­ma­tion on the don­gle. If you’re us­ing a wire­less at­tach­ment that’s not com­pat­i­ble with the Pi, it may not be de­tected. dmesg| grep -i usb [ 2.317400] usb 1-1.2: Prod­uct: 802.11 n WLAN

[ 2.317409] usb 1-1.2: Man­u­fac­turer: Ralink

[ 2.317418] usb 1-1.2: Se­ri­alNum­ber: 1.0

[ 10.538936] usb 1-1.2: re­set high-speed USB de­vice num­ber 4 us­ing dwc_ otg

[ 10.890759] us­b­core: reg­is­tered new in­ter­face driver rt2800usb

[ 21.067053] rt2800usb 1-1.2:1.0 wlan0: dis­abling HT as WMM/QoS is not sup­ported by the AP

[ 21.067074] rt2800usb 1-1.2:1.0 wlan0: dis­abling VHT as WMM/QoS is not sup­ported by the AP

The op­er­at­ing sys­tem ap­pears to have found the Wi-Fi don­gle. An­other quick com­mand line list­ing of USB de­vices ob­tains the de­tails of the don­gle: $ lsusb Bus 001 De­vice 004: ID 148f:5370 Ralink Tech­nol­ogy, Corp. RT5370 Wire­less Adapter ….... It stands to rea­son that, if the Pi has de­tected the Wi-Fi don­gle, it should load the driver mod­ules so the OS can com­mu­ni­cate with the de­vice. An rt2800usb was de­tected by ex­am­in­ing the out­put of the dmesg com­mand. The parsed out­put of the list mod­ules com­mand dis­plays the rt2800, driv­ers and soft­ware li­braries. $ lsmod Mod­ule Size Used by …... rt2800usb 18973 0

rt2800lib 82219 1 rt2800usb

rt2x00usb 12964 1 rt2800usb

rt2x00lib 49062 3 rt2800lib,rt2800usb,rt2x00usb ….... Us­ing the in­struc­tions pro­vided at www.rasp­ber­­u­men­ta­tion/ configuration/wire­less/wire­ to con­fig­ure the Pi for wire­less. It’s rec­om­mend that ad­min­is­tra­tors em­ployee the wpa_ passphrase com­mand to build the configuration. Us­ing this op­tion pre­vents pass­words from be­ing trans­mit­ted in plain text.

Let’s leave the Pi world for a minute, to ex­am­ine a free app, called Wifi An­a­lyzer for An­droid that dis­plays wire­less net­works. The app presents par­a­bolic wave­forms in dif­fer­ent colours. Each colour rep­re­sents the sig­nal strength of the dif­fer­ent net­work AP that’s been de­tected.

Af­ter that short An­droid in­ter­lude, let’s get back to the Pi. If you didn’t do a re­boot af­ter con­fig­ur­ing the Wi-Fi, do it now. A dmesg check will con­firm if the de­vice is con­fig­ured cor­rectly with a wlan0 in­ter­face, and is ready for use: $ dmesg [ 21.227676] wlan0: au­then­ti­cate with 00:15:05:f8:f7:c8 ……. [ 21.345086] wlan0: as­so­ci­ated

‘wpa_­cli’ is a com­mand line front-end pro­gram for in­ter­act­ing with ‘wpa_ sup­pli­cant’. The com­mand en­ables the user to check the cur­rent sta­tus, change the configuration, trig­ger events and re­quest in­ter­ac­tive user in­put. The out­put of the wpa_­cli com­mand pro­vides nu­mer­ous de­tails re­lated to a wire­less de­vice and the sig­nal. Be­fore em­ploy­ing the com­mands, it would be handy if you had some ad­di­tional knowl­edge of ra­dio fre­quency (RF). This is a good point to take a de­tour from all stuff Pi-re­lated and ex­plore some RF the­ory.


A re­cent project re­quired a wire­less con­nec­tion from a Rasp­berry Pi to a home router AP. The net­work could use one of two dif­fer­ent res­i­den­tial gate­ways (RG) as APs. RGs are some­times re­ferred to as routers or mo­dem. To be clear, it’s the de­vice that’s re­spon­si­ble for con­nect­ing to the In­ter­net Ser­vice Provider (ISP), which is pro­vid­ing ac­cess to the in­ter­net.

One RG was built with an ex­ter­nal mov­able rub­ber duck an­tenna and the sec­ond RG had the an­tenna built into the de­vice. Built-in an­ten­nae may be wrapped around the in­side of the de­vice, such as early gen­er­a­tion Ap­ple iPhones, or the an­tenna can built into the moth­er­board, just like cur­rent ver­sion of the Rasp­berry Pi-Zero.

RF sig­nals are trans­mit­ted and re­ceived with an an­tenna. In the di­a­gram (right), there’s a ren­der­ing of a ver­ti­cal dipole an­tenna, with a sig­nal source at­tached, ra­di­at­ing an RF sig­nal en­ergy out from the an­tenna in a torus pat­tern. Ra­di­a­tion pat­tern A in the draw­ing shows the torus or dough­nut ra­di­a­tion pat­tern. The sig­nal en­ergy is equal in all di­rec­tions. De­vices that trans­mit and re­ceive ra­dio waves re­quire an­ten­nas with a RF sig­nal mod­u­lated (in other words, con­tain­ing) with data.

An­ten­nae are designed to radiate RF en­ergy. How the an­tenna is phys­i­cally con­structed will af­fect the ra­di­a­tion pat­tern. Some an­ten­nae are en­gi­neered to trans­mit a very direc­tional sig­nal pat­tern. The ra­di­a­tion pat­tern iden­ti­fied with the letter B in the di­a­gram fo­cuses the RF en­ergy out in one di­rec­tion with very lit­tle ra­di­a­tion from the back. This en­ables greater range in a spe­cific di­rec­tion, al­though there’s a loss of sig­nal in the op­po­site di­rec­tion.

When us­ing a hand-held trans­mit­ter like a walkie-talkie, best prac­tice is to hold the de­vice with the an­tenna ver­ti­cal. In Hol­ly­wood ac­tion films, the pro­tag­o­nist holds the walkie-talkie ra­dio trans­mit­ter hor­i­zon­tal for a bet­ter pro­file shot. With a hor­i­zon­tal an­tenna ori­en­ta­tion, the sig­nal will be at its weak­est when the tip of the an­tenna is point­ing in the di­rec­tion the res­cue air­craft is com­ing from. If the char­ac­ter is sur­rounded by tall, metal build­ings, the sig­nal strength ra­di­ated is re­duced to the point he may not be able to trans­mit a strong enough sig­nal for his res­cue ride to re­ceive.

Now that we have an un­der­stand­ing of an­tenna de­sign, their res­o­nant fre­quency, an­tenna ori­en­ta­tion and

an aware­ness that ob­struc­tions can block sig­nals and re­duce sig­nal strength, how is it ap­plied?

There are two as­pects that we need to un­der­stand us­ing a wire­less net­work: the abil­ity to con­nect to the AP, and the data through­put de­liv­ered. The stronger the RF sig­nal, the eas­ier it is for the re­mote de­vice and the AP to make a con­nec­tion. More sig­nal also means im­proved data through­put.

But wait — we also need to talk about noise. If you’ve ever lis­tened to AM ra­dio ( How old are we?! — Ed) dur­ing a thun­der storm, you may have heard crack­les and pops dur­ing the broad­cast. That’s noise gen­er­ated by the storm. Noise are er­rant sig­nals gen­er­ated by an­other sources that fall into the fre­quency range be­ing used by a de­vice. It af­fects the de­vice’s abil­ity to re­ceive or read a sig­nal.

What’s most im­por­tant is the ra­tio of sig­nal strength to noise strength. The noise strength needs to be lower than the sig­nal strength for op­ti­mal re­cep­tion. If the sig­nal-to-noise ra­tio is low, then it be­comes dif­fi­cult for the re­ceiver to pull the sig­nal out of the noise.

RF sig­nal strength is cal­cu­lated us­ing a for­mula that pro­vides a value in dB (deci­bels). 0db is the mid­dle of the scale. The more pos­i­tive the num­ber, the greater the sig­nal strength. The more neg­a­tive the num­ber, the weaker the sig­nal strength. The maths re­quired to de­velop an un­der­stand­ing of the con­cept de­pends on slide rules or log­a­rith­mic ta­bles. Ad­di­tional the­ory on top of the con­tent al­ready cov­ered would be a tad ex­ces­sive for a Rasp­berry Pi tu­to­rial. Much like cur­sive writ­ing ex­er­cises at school, the ben­e­fit of gain­ing the knowl­edge ver­sus just us­ing a tool to ar­rive at the so­lu­tion is al­ways cause for de­bate.

On many wire­less de­vices, a ba­sic sig­nal strength me­ter is pro­vided us­ing sig­nal strength bars. The more bars, the greater the sig­nal. The bar equiv­a­lent sig­nal strength isn’t nor­mally pro­vided. It’s as­sumed that the greater num­ber of bars on show, the bet­ter the re­cep­tion. The di­a­gram (be­low) pro­vides a trans­la­tion be­tween bars of sig­nal strength and dB.

-30dB is the max­i­mum sig­nal strength that a de­vice can ob­tain. Close prox­im­ity to the ac­cess point with no ob­struc­tion will achieve this. Be­tween -67dB and -70dB is needed for re­li­able packet de­liv­ery. -80dB is the min­i­mum to make a con­nec­tion. -90dB is so far down in the mud that it be­comes dif­fi­cult for a de­vice to sep­a­rate sig­nal from noise.

The au­thor’s spouse had some con­cerns when she came home from a week­end away and dis­cov­ered the back­yard Wi-Fi sig­nal lab en­croach­ing on the se­nior res­i­dence at the rear of our prop­erty. The red cones (see the photo far right) were mark­ers in in­cre­ments of 3 me­tres to mea­sure dis­tance.

An ex­ten­sion cord was needed to feed power to the Wi-Fi sup­ported Rasp­berry Pi that was sealed in a weath­er­proof box. Two modems (RGs) with dif­fer­ent an­tenna types were used for eval­u­a­tion. It rained part way through the test­ing so the sealed black box that housed the Pi came in par­tic­u­larly handy.


This de­tour was taken to gain some RF knowl­edge be­fore us­ing the com­mand line tool wpa_­cli. Armed with this knowl­edge, let’s now ex­am­ine some cri­te­ria that can be con­sid­ered when look­ing at im­prov­ing the re­sponse of the Wi-Fi net­work.

What wire­less in­ter­faces are avail­able? $ wpa_ cli in­ter­face_list Se­lected in­ter­face ‘wlan0’ What’s the sta­tus of a given wire­less in­ter­face? Re­sults of all in­ter­faces will be dis­played. The Pi for the tu­to­rial only had one in­ter­face (wlan0): $ wpa_ cli sta­tus Se­lected in­ter­face ‘wlan0’ bssid= 00:15:05:f8:f7:c8 freq=2432 ssid=net­work32k id= 0 mode=sta­tion pair­wise_ ci­pher=CCMP group_ ci­pher=TKIP key_ mgmt= WPA2-PSK wpa_ state=COM­PLETED ip_ ad­dress= ad­dress= 00:c1:41:39:00:83 uuid=944aa377-ebda-5ab2a510-68c81a5c4f16

How about sup­port­ing a ping com­mand? $ wpa_ cli ping Se­lected in­ter­face ‘wlan0’ PONG What net­works can the de­vice con­nect with? $ wpa_ cli list_ net­works Se­lected in­ter­face ‘wlan0’ net­work id / ssid / bssid / flags

0 net­work32k any [CUR­RENT]

[DIS­ABLED] 1 any

and What avail­able? other net­works One com­mand are in ini­ti­ates range the dis­plays scan while the re­sults. the sec­ond com­mand wpa_ Se­lected cli scan in­ter­face ‘wlan0’ OK And the sec­ond com­mand... $ wpa_ cli scan_ re­sults Se­lected in­ter­face ‘wlan0’ bssid / fre­quency / sig­nal level / flags / ssid

00:15:05:f8:f7:c8 2432 -67 [WPA-PSK-TKIP][WPA2-PSK-CCMP] [ESS]net­work32k

10:9f:a9:62:a2:d92462 -59 [WPA-PSK-CCMP+TKIP][WPA2-PSKCCMP+TKIP][ESS] snig­gle­fritz

00:1c:b3:af:cc:9a 2437 -63 [WPA-PSK-TKIP][WPA2PSK-CCMP+TKIP][ESS]net­work31k

10:9f:a9:61:77:f9 2452 -77 [WPA-PSK-CCMP+TKIP][WPA2-PSKCCMP+TKIP][ESS] MTSGT962

It looks like four net­works have been dis­cov­ered. The two scans pre­fixed with net­work are the APs used in this tu­to­rial. If you’re fa­mil­iar with ip­con­fig for wired net­works, then iw­con­fig pro­vides sim­i­lar re­sults for wire­less net­works. Like if­con­fig, in the wire­less en­vi­ron­ment, iw­con­fig can be also be used to ma­nip­u­late ba­sic wire­less pa­ram­e­ters: $ iw­con­fig wlan0 IEEE 802.11 ESSID:”net­work32k”

Mode:Man­aged Fre­quency:2.432 GHz Ac­cess Point: 00:15:05:F8:F7:C8

Bit Rate=24 Mb/s Tx-Power=20 dBm Retry short limit:7

RTS thr:off Frag­ment thr:off Power Man­age­ment:off

Link Quality=39/70 Sig­nal level=-71 dBm

Rx in­valid nwid:0 Rx in­valid crypt:0 Rx in­valid frag:0

Tx ex­ces­sive re­tries:6213 In­valid misc:38 Missed bea­con:0

The com­mand out­put shows what net­work the Pi is con­nected to and the sig­nal strength. The next two com­mands pro­vide sim­i­lar de­tails al­ready dis­played us­ing the other com­mands. ‘iwgetid’ pro­vides the net­work con­nec­tion, with ‘iwlist’ pro­vides scan­ning, list fre­quen­cies, bit-rates, en­cryp­tion keys and so on. Wi-Fi quality and power read­ings are also avail­able, by ex­am­in­ing the con­tents of the wire­less file in the / proc di­rec­tory. $ cat /proc/net/wire­less In­ter-| sta-| Quality

| Dis­carded pack­ets | Missed | WE

face | tus | link level noise | nwid crypt frag retry misc | bea­con | 22

wlan0: 0000 43. -67. -256 0 0 0 6213 38 0

Con­sid­er­ing we just in­stalled an OS, did a few tweaks, added new Wi-Fi hard­ware and a configuration change, then de­toured to take in some RF the­ory, you may be feel­ing a bit over­whelmed. All the com­mands pro­vided are sup­ported by man pages. Pre­fix the com­mand in ques­tion with man sep­a­rated by a space and you’ll soon gain some fur­ther in­sight into the com­mand op­er­a­tion.

How about look­ing at one more com­mand that con­sol­i­dates the out­put from a num­ber of com­mands which have been used so far. $ sudo wave­mon

The out­put from the com­mand is an ac­tive screen in real time dis­play­ing a num­ber of the Pi’s Wi-Fi pa­ram­e­ters. Re­mem­ber that noise can have an ef­fect on re­ceiv­ing a sig­nal. The ‘wave­mon’ out­put presents the link quality and sig­nal level to demon­strate the con­cept. TAKE IT OUT­SIDE Now that we have an un­der­stand­ing of some wire­less com­mands, how about a prac­ti­cal ap­pli­ca­tion? Use the com­mands to an­swer this ques­tion: what dif­fer­ences does it make us­ing an AP with an ex­ter­nal an­tenna vs an AP with an in­ter­nal an­tenna? To an­swer, con­nect the Pi to the wire­less net­work that has an ex­ter­nal an­tenna AP. Record sig­nal lev­els and the great­est dis­tance a con­nec­tion can be main­tained. Now com­plete the same ex­er­cise us­ing an AP with an ex­ter­nal an­tenna. In this sce­nario, the wave­mon and /proc di­rec­tory were used to show the read­ings as the Pi was moved. Re­visit the di­a­gram show­ing sig­nal strength (far left). The data for the two APs with dif­fer­ent an­ten­nae is in­cluded. The con­nec­tion range was greater for the de­vice with the ex­ter­nal an­tenna.

The col­lec­tion of pho­tos (above) shows the pro­fes­sional en­gi­neer­ing lab ( Ahem... — Ed) used to con­duct the test­ing sce­nar­ios. The two dif­fer­ent modems (the APs) were in­side the au­thor’s home above the elec­tri­cal panel. On the out­side, they’re lo­cated just be­low the at­tached gazebo. The red cones shown in one of the pic­tures were dis­tance mark­ers in in­cre­ments of 3 me­tres from the AP. An few ex­ten­sion cords were needed to feed AC power to a Wi-Fi sup­ported, Rasp­berry Pi sealed in a weather-proof box. If you look closely at one pic­ture you should no­tice that it’s rain­ing. ( All in a day’s work to bring you your issue of APC each month! — Ed)

There you have it: the com­mand line work­ings of Wi-Fi on a Rasp­berry Pi. We hope the de­tour into RF the­ory didn’t over­whelm you. To fully ap­pre­ci­ate the Wi-Fi com­mands, it’s im­por­tant to have some RF back­ground be­fore ex­plor­ing their use. The Wi-Fi com­mands are an ex­cel­lent box of tools to open up in help­ing to try to re­solve prob­lems.

This An­droid wire­less net­work anal­yser app iden­ti­fies a range of net­works.

Here’s a dough­nut­shaped sig­nal pat­tern, with­out sprin­kles or choco­late.

Low funds meant the au­thor had to make the best of the avail­able re­sources.

Newspapers in English

Newspapers from Australia

© PressReader. All rights reserved.