Trick #21: My Raspberry Pi becomes unreachable (wireless connection lost)

Some of you have experimented this annoying behavior: your OctoPrint server could not be reached anymore using Printoid, nor from the web interface. Here is a tutorial to try to fix it.

Please note that the following informations are based on my own observations, and the observation of some users affected by the issue.

This is not a general tutorial to fix the problem definitively at all, and it only depends on your local network + Raspberry Pi + OctoPrint + Printoid usage context.

 

1. DESCRIPTION OF THE PROBLEM

The conditions are the following:

  • OctoPrint is installed on a Raspberry Pi (1, 2 or 3)
  • You have installed the OctoPi environment or the couple Raspbian + OctoPrint
  • Your Raspberry Pi is connected to your network by WiFi
  • You are using both of Printoid and the OctoPrint web interface on your phone

The ways to reproduce the issue are the following (this list is non-exhaustive):

  • Opening the OctoPrint web interface from your phone (frequent)
  • Showing your webcam from Printoid (frequent)
  • Sending SSH commands from Printoid (pretty rare)
  • Simply opening Printoid (very rare)

Symptoms are the following:

  • You can’t access to the OctoPrint web interface anymore
  • You can’t connect with Printoid anymore
  • Your current printing job is still running fine

 

2. EXPLANATIONS

I don’t have great explanations to provide because I’m not a Linux expert, but:

  • It seems that your Raspberry Pi does not support to much network traffic and the network manager of Raspbian simply crashes.
  • This also seems to occurs only with a wireless connection to the network, and (most of time) when the WiFi signal is not so good.
  • You can observe a very high Tx excessive retries on the wlan0 interface of your Raspberry Pi

 

3. SOLUTIONS

Again, I haven’t a definitive fix for this problem right now, but according my observations, the three following solutions seem to work well and solve the issue (in 95% of cases)

 

Solution 1: turn off WiFi power management

Jacques Thieck sent me an email to explain me how does he fix the issue. It seems to be a WiFi power management issue. Here are his explanations:

pi@octopi:~ $ iwconfig
lo no wireless extensions.wlan0 IEEE 802.11 ESSID:”Livebox-19B0″
Mode:Managed Frequency:2.412 GHz Access Point: 90:4D:4A:F7:50:50
Bit Rate=5.5 Mb/s Tx-Power=31 dBm
Retry short limit:7 RTS thr:off Fragment thr:off
Power Management:on
Link Quality=59/70 Signal level=-51 dBm
Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0
Tx excessive retries:45366 Invalid misc:0 Missed beacon:0

And only 1 minute after:

pi@octopi:~ $ iwconfig
lo no wireless extensions.wlan0 IEEE 802.11 ESSID:”Livebox-19B0″
Mode:Managed Frequency:2.412 GHz Access Point: 90:4D:4A:F7:50:50
Bit Rate=96.1 Mb/s Tx-Power=31 dBm
Retry short limit:7 RTS thr:off Fragment thr:off
Power Management:off
Link Quality=60/70 Signal level=-50 dBm
Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0
Tx excessive retries:59256 Invalid misc:0 Missed beacon:0

As you can see, his WiFi interface has a very high Tx excessive retries (14k in one minute). That should explain the problem: may be thin changes in the API charge more the network and when he updated OctoPrint, it overflows the wifi and causes the issue.

Jacques Thieck advices that users who experienced (under OctoPi distribution) the same problem to perform as follow:

SSH OctoPi and type:

sudo iwconfig wlan0 power off

Test if the issue does not occur anymore. If it is okay right now, you can edit /etc/network/interface:

sudo nano /etc/network/interfaces

And, on the wan part of the file, add the following line:

wireless-power off

Don’t forget to save the changes. Reboot your Raspberry Pi to take the changes into account.
To verify, iwconfig should not show more Tx excessive retries.

You can find more information here:

http://www.foreverlarz.com/raspberry-pi-becomes-unresponsive-over-wifi/

 

Solution 2: change the WiFi channel

Your rooter is emitting your WiFi access point through a specific frequency (in a standard range of frequencies). This emitting frequency is called “channel”.

There are up to 14 channels in the 2.4GHz WiFi bandwidth (13 in Europa, 12 in the USA). The different channels are here to prevent interferences between the different equipments in your environment (can be other WiFi networks, microwaves oven, amateur radios…)

So you need to analyze the frequency spectrum at your home our your apartment, were you Raspberry Pi is located. That’s way, you will be able to know which are the channels the most and the less used.

A good way to analyze your WiFi is to use this Android application: Wifi Analyzer (by F01arproc)

As you can see in the previous screenshot of Wifi Analyzer :

  • The “home” network is emitted on the channel 11. That’s really good because it does not disrupt at all with the other access points.
  • The “TBC-LINK_5F476C” network is emitted on the channel 1. That’s not so good, but it superimpose a bit with “Tenda_597638
  • The “TBC_LINK_44C950” network is emitted on the channel 6, same as “Netcore1” and “wacweozhensben7“. That’s really bad because there are 3 networks on the same channel, and its signal strength is not good at all. This network will be probably difficult to reach and a lot of data packets will be lost during the network communications.

The idea is to configure your rooter to emit your WiFi access point on the less used channel. Simply check in your rooter configuration page / documentation for how to.

Learn more informations about the WiFi channels here.

Solution 3 : use an extra WiFi USB dongle

The Raspberry Pi does not support yet the WiFi 5GHz.

Today, the 5GHz access points are not used a lot. That’s a good thing to know because the 5GHz bandwidth allows you to use up to 25 other channels, with a better download/upload rate.

Check if your rooter is able to emit a 5GHz access point and enable it (some rooters are already emitting a 5GHz access point by default, with the same SSID than the 2.4GHz one – you can also choose to emit it with a different SSID in order to distinguish them).

By using a 5GHz-complient WiFi USB dongle, you will be able to connect to this 5GHz access point with your Raspberry Pi.

You can find small WiFi dongles in Amazon for example, at a reasonable price.

 

Solution 4 : wired connections rule the world!

If ever the solution 1 nor 2 do not work in your case, or if ever you can’t manage how to change the WiFi channel of your rooter – or won’t buy an extra dongle for your RPi…

You can simply connect your Raspberry to Internet over an ethernet cable. As I’ve explained in the solution 1, the WiFi networks can be easily disrupted by other devices such as neighborhood’s access points, microwaves ovens, amateur radios… but also concrete walls, mirrors, etc…

The wired connections rule the world! None of these disruptions affect an Ethernet cable. Unless you have a hamster or a rabbit at home…

 

4. TO GO FURTHER

If ever you reproduce this issue by another way, or if you have a better solution to fix it, I’ll be happy to hear & share your experience here 😉

Feel free to contact me at printoid.for.octoprint@gmail.com


2 thoughts on “Trick #21: My Raspberry Pi becomes unreachable (wireless connection lost)

  1. Hi Anthony,

    Could the reason that Raspberry does not support channel 12 and 13 for countries where it should be supported? Some routers hop to these, it could have something to do with the problems you describe? I fixed my channel for that reason rather then have it select an available one (in my Fritz Box) and choose channel 12 or 13.

    I would not be able to connect reliably with Octoprint otherwise…

    Cheers Ruud

    2017-09-27 12:51 GMT+02:00 Printoid for OctoPrint :

    > Anthony posted: “Some of you have experimented this annoying behavior. > Here is a tutorial to try to fix it. Please note that the following > informations are based on my own observations, and the observation of some > users affected by the issue. This is not a general t” >

    Like

Leave a comment