How to add connection check to RPi3B+?

I’ve noticed that my wifi has sometimes connection issues and drops down, or I’m updating the firmware and have to reboot the router. If this happens, the RPi3B+ I use for running the ruuvicollector won’t reconnect unless I just power off and on.

Is there some script that could be added to the standard installation to detect if the network is down and force reconnection as needed?

Are you running “buster” or another version?

cat /etc/os-release|grep  PRETTY_NAME

Do you have daemon.info syslog enabled?

vi /etc/syslog.conf

Do you see log entries like:

dhcpcd[315]: wlan0: carrier lost
dhcpcd[315]: deleting default route via 192.168.1.1
dhcpcd[315]: wlan0: carrier acquired
dhcpcd[315]: wlan0: rebinding lease of 192.168.1.23

Yes, the version string is “Raspbian GNU/Linux 10 (buster)”.

I don’t seem to have that logging enabled, the file is not found.

You should edit /etc/syslog.conf and add lines like

daemon.info -/var/log/daemon.log
local0.* -/var/log/local0.log

More details at syslogd : system logging daemon

/etc/logrotate.conf defines how the files are archived and expired
for example:

/var/log/daemon.log
/var/log/daemon.info
/var/log/daemon.debug
{ rotate 9
maxsize 5M
notifempty compress delaycompress missingok create 0660 root staff
sharedscripts
postrotate
invoke-rc.d rsyslog rotate &>> /var/log/logrotate.rotate.log
endscript
}

More details at logrotate maintain/archive /var/log syslog file

After reviewing the documentation let me know if you need more help.

Are there any log messages from your router indicating. a problem?
Are you using a 2.4Ghz or 5Ghz
Use sudo iwconfig wlan0 to display information

Are you having any issues with any other devices near that same location?

The RPi seems to have lots of difficulties keeping the network connection open. Putty reports network closed error quite often and it’s a bit sluggish typing things on the terminal.

Could it be that the Wifi module is actually dying? Today I had one network disconnect in the RPi and it didn’t reconnect until I powered it off and on. I’m unable to do a sudo apt update to start updating packages, it seems to just timeout even if I’ve tried different servers in the config file.

All the other wireless device seem to work fine. It’s been connected to my 2.4GHz all the time I’ve used it. I actually thought it supported only that and not 5GHz. The router doesn’t show any errors in it’s logs.

pi@ruuvicollector:~ $ sudo apt update
Err:1 http://archive.raspberrypi.org/debian buster InRelease
  Connection failed [IP: 93.93.135.117 80]
Err:2 http://mirror.ox.ac.uk/sites/archive.raspbian.org/archive/raspbian buster InRelease
  Connection failed [IP: 163.1.221.67 80]
Reading package lists... Done
Building dependency tree
Reading state information... Done
All packages are up to date.
W: Failed to fetch http://mirror.ox.ac.uk/sites/archive.raspbian.org/archive/raspbian/dists/buster/InRelease  Connection failed [IP: 163.1.221.67 80]
W: Failed to fetch http://archive.raspberrypi.org/debian/dists/buster/InRelease  Connection failed [IP: 93.93.135.117 80]
W: Some index files failed to download. They have been ignored, or old ones used instead.

I was now able to switch to 5GHz with raspi-config, and everything seems to work much better. Maybe the box is a bit flaky or something, if my 2.4GHz network didn’t work properly, I would have noticed it as most of my gear is using that.

Good you get it working. Most likely at 2.4GHz there are lot of other APs and current version WLAN standard 5, will get congested and behave like you described. At WLAN standard 6 this issue has been corrected.