Sonntag, 28. Februar 2021

Raspberry Pi, test my internet connection

Since start of Corona times, I use my internet at home also for work. So its reliability and performance has become crucial. Performance seems to be stable, I test it using speedtest.net:

But regarding the reliability, I get outages almost every day. Very awkward during a video conference in your job. So, first step is to check whether the outage comes from the internet provider or from the WLAN. 

German video where I describe what I did.

It can be that your WLAN router needs to change channels which will be bad enough to cut you off a video conference although your internet connection from the router to the internet works perfectly fine.

So I got the idea to use my raspberry pi which is connected to the router via cable (not WLAN) to check if there are internet outages (not WLAN outages):

modern art: 
if WLAN is down, Raspberry Pi will still be connected to the internet

I use a screen session to monitor the network connection. A screen session will survive users closing the terminal window, network outages and it never times out. See below:

A screen session survives network outages and it does not time out.

To install screen, I ran on raspian:

apt-get update
apt-get install screen

To start a screen session, run 

screen

and follow the instructions (to type Enter ;).

To list all screen sessions, type

screen -ls

Once you re-login, you can re-attach to a screen session (if there is only one) using

screen -x

Inside the screen session, to detect network errors, I used the command

ping -O 8.8.8.8 2>&1| while read a; do echo $(date; echo $a); done | grep -v time

This command will only output a line in case of an issue, and it will also write a timestamp like this:

pi@raspberrypi:~ $ ping -O 8.8.8.8 2>&1| while read a; do echo $(date; echo $a); done | grep -v time 
Mon 01 Mar 2021 10:58:49 AM CET PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data. 
Mon 01 Mar 2021 10:59:01 AM CET ping: sendmsg: Network is unreachable

You can provoke an error situation by drawing the LAN cable from the Raspberry Pi.

Learnings

I found that by telling FritzBox to reconnect I can provoke a situation where ping does not get replies and packages are lost, however, no error message gets printed. You can detect the error by looking at the icmp_seq value that suddenly increases by more than one. Fixed by applying -O.

I found that FritzBox' DSL information does not really provide the information if the internet connection has been lost or not. Or if it does, I do not understand it. It talks about non-recoverable errors, but I am not sure if this means "DSL connection lost".

I still don't understand why, but 
ping 8.8.8.8 2>&1| while read a; do echo $(date; echo $a); done | grep -v time 
works and
ping 8.8.8.8 2>&1| grep -v time | while read a; do echo $(date; echo $a); done
does not

Raspberry Pi, test my internet connection

Since start of Corona times, I use my internet at home also for work. So its reliability and performance has become crucial. Performance see...