Pi Zero Wi-Fi Automatic Reconnect

WIFISometimes I wonder about the thinking processes involved in Debian setup.

Why for example would you NOT want the Wi-Fi to reconnect on failure? What is the point? Yet, that does seem to be the default scenario, particularly odd when it comes to the Pi Zero – which has no option BUT to use WIFI.

I generally attach Raspberry Pi devices to the Internet via a hardwired Ethernet as connectivity is very important to me – not much point in having a super-duper setup miles away only to discover you can no longer talk to it, right?

Yet that is EXACTLY the scenario people will no doubt stumble onto when getting their new spiffy Pi Zero – I’m not going to say low cost because by the time you realise you need a USB hub and WIFI adaptor the price suddenly shoots up towards the cost of competing devices.

However, having had my Pi Zero sitting on the shelf for some time and having now received more than one WIFI dongle (including one with a decent external aerial) I thought I’d give it a go. The little number you see here on the right was £2.59 from Hong Kong and is in keeping with the low cost of the Pi Zero. I also spent £5.59 in the UK on a cheap powered USB hub because article after article suggested that running the WIFI without a hub was not a good idea (since verified and further backs up my doubts about the benefit of having a Pi Zero in the first place).

USB HubSo I took an old-fashioned Pi B and set that up with Wi-Fi (without the hub) – copied the FLASH from its rather large original SD to a micro SD and plugged it into the Pi Zero. Plugged in the cheap USB powered adaptor  – plugged the WIFI dongle into that and applied power.

Worked a treat. Lovely. Tried without the hub, no joy. But of course this is when people normally stop only to discover often days or weeks later that this is NOT a good enough solution.  I did note that very occasionally the Pi Zero would reset – the cause of this was a very long, thin USB power lead – funny that this never had been a problem with the Pi2 – but shortening the lead very definitely solved the problem.

So with everything working, To test reliability, I simply pulled the Wi-Fi dongle out – and put it back in. The Wi-Fi was DEAD. After 5 minutes still no connection.  So I rebooted the Pi and back came the connection. The next test was to pull the power to the router (does anyone REALLY live in a place where none of this EVER goes wrong?). Router back on – waited 5 minutes and… sure enough – absolutely NO Wi-Fi.

I started to scour the web – BOY are there some convoluted solutions out there – one might suggest  some were written by sadists. Come on guys – this is a tool, not life itself – something SIMPLE is needed.

And so it was I stumbled onto this page.

http://raspberrypi.stackexchange.com/questions/4120/how-to-automatically-reconnect-wifi

Here’s the important bit – no new files.  I was talking to the Pi via winSCP and of course as Pi user you don’t have permission to wipe your nose so I made a slight mod to the Pi connection – in winSCP, under advanced, SFTP I put “sudo /usr/lib/sftp-server” into the SFTP SERVER panel – and reconnected – this gave me elevated control to actually let me edit files without needing a degree in Linux using one of the many awful command line editors therein.  

As per the link above..

In /etc/network/interfaces I put:

allow-hotplug wlan0

iface wlan0 inet manual

wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf

iface default inet dhcp

I saved that and rebooted – all was ok. I pulled the WIFI dongle out – winSCP griped. I plugged it back in, 1 minute later, winSCP reconnected automatically. I turned off the router – winSCP griped. I turn the router back on – just over a minute later, winSCP reconnected automatically.

Now why isn’t that the default setting?

For my next trick – in Debian Jessie and with the graphical interface set up, I tried swapping routers – I have 3 access points as my home has lots of thick walls.  I swapped from one to the other and was asked for a password. Ok, fair enough. But then when swapping back to the original, I was asked for the password again. WHAT?? I’d already given it the password, why would it want it again?

Well it turns out that all is ok as the graphical interface had actually saved both settings in /etc/wpa_supplicant/wpa_supplicant.conf

I’ve obviously altered my two SSIDs and passwords.  I guess you could put as many of these as you like in here manually.

network={
    ssid=”aaaaaaaa”
    psk=”xxxxxxxxxxxxxxxxxxxx”
    key_mgmt=WPA-PSK
}

network={
    ssid=”aaaaaaaa”
    psk=”xxxxxxxxxxxxxxxxxxx”
    key_mgmt=WPA-PSK
}

Lovely.  It really is worth asking however, is it really worth the saving of having a Zero when it needs a USB lead and hub for it to be of any use, not needed with a P2 which is also faster.. or one of the alternatives out there. There is also no 3.5mm jack for audio on the Pi Zero.

Still at least I can now use this for something…

IanChilton on Twitter just sent me this link – which I have to say on the surface of it is pretty damned interesting for the Pi Zero – any thoughts on this? The price is stunning and it would seem to be JUST what the Pi Zero needs? Does not seem to come with a power adaptor – but it does have a little hole for one in the back!

http://www.aliexpress.com/item/Hot-marking-Micro-USB-to-Network-LAN-Ethernet-RJ45-Adapter-with-3-Port-USB-2-0/32544477817.html?spm=2114.30010308.3.2.YZfEDZ&ws_ab_test=searchweb201556_3,searchweb201644_3_505_506_503_504_301_502_10001_10002_10016_10005_10006_10003_10004,searchweb201560_3,searchweb1451318400_-1,searchweb1451318411_6450&btsid=7667f665-95f8-487d-9525-af3aa4c3a948

So.. do we actually NEED to use WiFi in the ZERO or is this a viable and practical alternative?

By the way if you see that 4 port USB hub I photographed above on Ebay – avoid it  – we were sitting watching TV tonight when the little plug-in-the-wall power supply that came with it – blew up!!

14 thoughts on “Pi Zero Wi-Fi Automatic Reconnect

  1. I was running a WiFi dongle quite nicely on my Zero WITHOUT a USB hub. However, I was experiencing the same WiFi-won’t-reconnect issues as you and loads of other people. I tried the fix you described, Pete, and it didn’t work. Neither did it help if I used a script to detect if WiFi had gone and then reboot. And then before I could start digging and try to fix it, my WiFi dongle died.

    So rather than replace it I decided to get a USB to Ethernet adapter – and hence sidestep the WiFi disconnection issue at the same time.

    Be warned that some cheap adapters (like the one I bought to begin with) don’t work well/at all with the Pi. That one you’ve posted the link to might not either. In the end I went for this from Amazon which worked straight out of the box with no need for any drivers, config, etc:

    My Zero does a perfectly fine job of running Node Red and being the central hub of my home automation system. And because it came free with MagPi magazine all I have had to pay for is the Ethernet adapter and a couple of quid on a cheap PSU from AliExpress.

    1. Glad it is working for you David…

      But at £10….. it’s getting near the mark. Check out the Orange Pi update… this could well fall flat on it’s face, but right now I have WIFI + ETHERNET and soon I hope to add NGINX, Node-Red, Mosquitto and Webmin along with SQLITE. The difficult bit is – the version of Jessie that is working really well – has NGINX and I have ZERO experience of this – I’ve commented out Apache install and have used a modified PHP install but no idea at this point if it will actually work. If it DOES you have a complete kit for a tenner + £2.50 for WIFI adaptor. That is going to take some beating.

      Right now it’s still IF.

  2. Hi Pete

    I am running a Pi zero with edimax wifi plugged direct on short adaptor cable and no powered hub. Its been rock solid for days. Power is 12 volt DC plus DC to DC usb power supply:
    (http://www.ebay.co.uk/itm/111473997718?_trksid=p2057872.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT)

    Its operating a relay via MQTT (and Node Red of course).

    I tried an ESP8266 in the same situation and that was never reliable.

    I will add the automatic reconnect though. Thanks for the tip.

  3. Saved me some googling there Pete. I’ve been frustrated by the Wifi reconnect issue too, will add this to my Pi pronto.

  4. Pete, It looks like that USB/Ethernet adapter does have a DC input socket (on the side opposite to the USB ports). One of the reviewers mentions that it accepts a 5v input (but obviously the unit doesn’t come with an AC adapter… so more $’s added to the total cost of the Zero).

    1. Well yes but then you need a power supply for a normal Pi so I guess that’s ok. So all in we’re looking at a around £10 plus power supply and not in the most convenient form – on the other hand it is a Pi and therefore has Pi support in terms of stuff out there. I don’t think it would take the Chinese too much effort to beat this however. There is a new Orange Pi but given the lack of support for their last effort I won’t hold that up as competition. Thanks for the info I might just buy one of those adaptors to give it a go.

  5. I really like the PI Zero, though I think that if you are looking for embedded linux board that needs Internet access, the CHIP from next thing seems to be the best option. It runs debian and has Bluetooth and wifi built in, aso well as 4gb NAND flash, so you don’t need the SD card, and all for $9! Have you had the chance to use one yet?

    1. Hi Kyle – pre-orders not shipping until June – which means regular supply maybe October? Not sure I want to get onto that bandwagon yet… but yes, it does look promising – but so did so many others until operating system and library support or lack of it doomed them to oblivion. Time will tell.

      Pete

      1. Yea, I got one in December and have been poking around with it when I have time. I still use the Pi Zero as well. If you wanted a CHIP to do some playing and write up on your thoughts, I could ship you mine for a short time? I would be interested to see what your thoughts are!

  6. Are you using different SSIDs for each of your different wireless APs ? Makes life easier if you use the same one. I have to smile at your linux editor indignation.

Comments are closed.