Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Pi 0 W dropping wifi

1,125 views
Skip to first unread message

Adam Funk

unread,
Aug 20, 2021, 6:30:04 AM8/20/21
to
Hi,

I have a Pi Zero W stuck to the basement ceiling with a few simple
low-power cron jobs:

* read the Tilt hydrometer (bluetooth low-energy beacon about 2 away)
* read a DHT-22 sensor (attached to the GPIO pins)
* email me a summary with plots of the Tilt data (nullmailer is
installed and working)
* log the DHT-22 data to a REST API on another machine on the LAN

Every few days it disconnects from the wifi but keeps running (it
accumulates Tilt and DHT-22 data, and the emails stay in the
nullmailer queue). Because this Pi is headless, I have to cut the
power off and on (at the switched socket) to reconnect it.

Stuff I have tried:


(item 1)
sudo iwconfig wlan0 power off

(and that happens in crontab @reboot, and I've checked with iwconfig
that it is set every time)


(item 2)
cron this:

*/2 * * * * /bin/ping -c 2 -I wlan0 [routerIP] >/dev/null 2>>pinger.log

I thought it was working for a while but it disconnected last night.


(item 3)
I found a "wifi bump script" on the web that someone has used in
cron(it used ifdown -a and ifup -a but those don't affect wlan0 on Pi
OS now):

# Perform the network check and reset if necessary
/bin/ping -c 2 -I $wlan $pingip > /dev/null 2> /dev/null
if [ $? -ge 1 ] ; then
logger -t wifibump "network is down"
#/sbin/ifdown -a
/sbin/ip link set wlan0 down
sleep 5
#/sbin/ifup -a
/sbin/ip link set wlan0 up
else
logger -t wifibump "network is up"
fi

But I tested the commands with an at job as follows:

echo "down"
/sbin/ip link set wlan0 down
sleep 5
echo "up"
/sbin/ip link set wlan0 up

The "down" worked; the "up" didn't produce any error output but it
didn't work --- I had to reboot the Pi and the at output email came
through afterwards.


Any suggestions?

Thanks.

A. Dumas

unread,
Aug 20, 2021, 7:33:15 AM8/20/21
to
Adam Funk <a24...@ducksburg.com> wrote:
> Every few days it disconnects from the wifi but keeps running

Same here, I've always had this problem with my Zero based webcams. Tried
the same things you did. I have given up, reliable webcams are not possible
with Raspberry Pi on wifi, as far as I am concerned. I asked a few times on
the official forums but it always gets dismissed as "it works for me, i've
never seen that" etc.

mm0fmf

unread,
Aug 20, 2021, 8:11:01 AM8/20/21
to
On 20/08/2021 11:24, Adam Funk wrote:
> The "down" worked; the "up" didn't produce any error output but it
> didn't work --- I had to reboot the Pi and the at output email came
> through afterwards.
>
>
> Any suggestions?

I wrote about 6months back about minimising SDcard wear when leaving a
Pi Zero W running 24/7. The Pi provides SSH access to my network from
the internet.

I mount all the logs etc. on /tmp to reduce SDcard wear and then to stop
/tmp filling up I take the simple but drastic fix of rebooting every
24hrs. There are better ways but for what this is used for, a gateway,
it works fine.

In those 6 months with a reboot every day the Wifi stays working and
I've never had a problem with Wifi connections failing or failing to
come up. This may be a less than perfect solution but should keep you
from having to intervene manually as long as you can accept the time it
takes to reboot in your logging. You could adjust the reboot time to be
now plus 24h 1m so the reboot time is different each day.

Not a fix but something to reduce your hassle.



Adam Funk

unread,
Aug 20, 2021, 8:30:04 AM8/20/21
to
Funny enough, I just thought of something like that (posted a few
minutes ago). I'd probably set the reboot time to be the same every
day and while I'm asleep.

(I haven't had any problems with wired network connections on Pi 2B or
Pi 4 models, but I haven't tried wifi on either.)

Adam Funk

unread,
Aug 20, 2021, 8:30:04 AM8/20/21
to
I suppose I ought to wire up a "safe shutdown" button:

<https://core-electronics.com.au/tutorials/how-to-make-a-safe-shutdown-button-for-raspberry-pi.html>

Or (lazy option) I could just crontab a reboot every night or two.

John Aldridge

unread,
Aug 20, 2021, 8:47:39 AM8/20/21
to
In article <m3j4vhx...@news.ducksburg.com>, a24...@ducksburg.com
says...
>
> I suppose I ought to wire up a "safe shutdown" button:
>
> <https://core-electronics.com.au/tutorials/how-to-make-a-safe-shutdown-button-for-raspberry-pi.html>
>
> Or (lazy option) I could just crontab a reboot every night or two.

What I do is configure all my RPis to run a program which listens for
the insertion of a USB stick with disk or partition label SHUTDOWNPI.

No extra hardware needed!

John

Adam Funk

unread,
Aug 20, 2021, 1:15:04 PM8/20/21
to
That's clever!

The Natural Philosopher

unread,
Aug 20, 2021, 1:34:47 PM8/20/21
to
My Pi Zero W says on logging onto it via wifi that its been up 26 days
and so has the wifi

It may be actually a router or wifi point issue.

For sure the Pi is capable or maintaining a connection but I am not sure
it is capable or resetting one on loss of signal.

Im running mine about *3 feet* through a wall to a Netgear router
re-configured as an ethernet to wifi bridge. before that I did have
problems with the pi going off line and it might have needed a reboot

This is the iwconfig for what is now reliable

$ iwconfig wlan0
wlan0 IEEE 802.11 ESSID:"xxxxxxx"
Mode:Managed Frequency:2.457 GHz Access Point:
30:46:9A:A2:89:F6
Bit Rate=65 Mb/s Tx-Power=31 dBm
Retry short limit:7 RTS thr:off Fragment thr:off
Power Management:on
Link Quality=44/70 Signal level=-66 dBm
Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0
Tx excessive retries:5 Invalid misc:0 Missed beacon:0



--
Future generations will wonder in bemused amazement that the early
twenty-first century’s developed world went into hysterical panic over a
globally average temperature increase of a few tenths of a degree, and,
on the basis of gross exaggerations of highly uncertain computer
projections combined into implausible chains of inference, proceeded to
contemplate a rollback of the industrial age.

Richard Lindzen

Computer Nerd Kev

unread,
Aug 20, 2021, 6:44:04 PM8/20/21
to
If the Pi doesn't have a fixed IP address assigned to it, then I'd
try that in case it's a problem with DHCP.

Failing that, perhaps you could try unloading then reloading the
WiFi driver module occasionally, between toggling the interface
down/up.

--
__ __
#_ < |\| |< _#

Adam Funk

unread,
Aug 22, 2021, 8:45:05 AM8/22/21
to
On 2021-08-20, The Natural Philosopher wrote:

> On 20/08/2021 12:33, A. Dumas wrote:
>> Adam Funk <a24...@ducksburg.com> wrote:
>>> Every few days it disconnects from the wifi but keeps running
>>
>> Same here, I've always had this problem with my Zero based webcams. Tried
>> the same things you did. I have given up, reliable webcams are not possible
>> with Raspberry Pi on wifi, as far as I am concerned. I asked a few times on
>> the official forums but it always gets dismissed as "it works for me, i've
>> never seen that" etc.
>>
> My Pi Zero W says on logging onto it via wifi that its been up 26 days
> and so has the wifi
>
> It may be actually a router or wifi point issue.
>
> For sure the Pi is capable or maintaining a connection but I am not sure
> it is capable or resetting one on loss of signal.

Any idea why it can't? (Everything else does!)


> Im running mine about *3 feet* through a wall to a Netgear router
> re-configured as an ethernet to wifi bridge. before that I did have
> problems with the pi going off line and it might have needed a reboot
>
> This is the iwconfig for what is now reliable
>
> $ iwconfig wlan0
> wlan0 IEEE 802.11 ESSID:"xxxxxxx"
> Mode:Managed Frequency:2.457 GHz Access Point:
> 30:46:9A:A2:89:F6
> Bit Rate=65 Mb/s Tx-Power=31 dBm
> Retry short limit:7 RTS thr:off Fragment thr:off
> Power Management:on
> Link Quality=44/70 Signal level=-66 dBm
> Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0
> Tx excessive retries:5 Invalid misc:0 Missed beacon:0

That's curious, because one of the most common suggestions I found was
to disable power management (and it seemed to work for a few months).

druck

unread,
Aug 22, 2021, 9:23:33 AM8/22/21
to
On 20/08/2021 11:24, Adam Funk wrote:
> * read a DHT-22 sensor (attached to the GPIO pins)

Those are pretty inaccurate, I'd recommend using a HTU21DF instead. It's
I2C so plenty of libraries available and no timing issues.

> Every few days it disconnects from the wifi but keeps running (it
> accumulates Tilt and DHT-22 data, and the emails stay in the
> nullmailer queue). Because this Pi is headless, I have to cut the
> power off and on (at the switched socket) to reconnect it.

How old is the disc image? I had similar problems with a couple of my
first Pi Zero W's but not newer ones, despite having done regular
updates to all of them. I created new Raspbian lite images for them, and
they've worked perfectly since.

The only discernable difference was the ones which would drop WiFi
showed failures of if...@wlan0.service (systemctl --failed) even just
after booting, and the new images don't. I think there must have been
some configuration difference between them, but I couldn't find it in
any of the obvious places in /etc

---druck

Jack

unread,
Aug 25, 2021, 3:23:33 AM8/25/21
to
I would write a script that pings the router and reboot if no response.
And run the script every 5 minutes via crontab.

Bye Jack
--
Yoda of Borg am I! Assimilated shall you be! Futile resistance is, hmm?

Adam Funk

unread,
Aug 25, 2021, 10:00:04 AM8/25/21
to
On 2021-08-20, Computer Nerd Kev wrote:

> If the Pi doesn't have a fixed IP address assigned to it, then I'd
> try that in case it's a problem with DHCP.

Worth trying --- until recently I thought the DHCP by MAC on the
router was good enough! I'll have to remember how to remove that on
the router though.


> Failing that, perhaps you could try unloading then reloading the
> WiFi driver module occasionally, between toggling the interface
> down/up.

So something like this in the wifibump script?

/sbin/ip link set wlan0 down
modprobe -r brcmfmac
sleep 5
modprobe brcmfmac
/sbin/ip link set wlan0 up



--
There’s never enough time to do all the nothing you want.
---Calvin

Computer Nerd Kev

unread,
Aug 25, 2021, 6:24:06 PM8/25/21
to
Adam Funk <a24...@ducksburg.com> wrote:
> On 2021-08-20, Computer Nerd Kev wrote:
>
>> If the Pi doesn't have a fixed IP address assigned to it, then I'd
>> try that in case it's a problem with DHCP.
>
> Worth trying --- until recently I thought the DHCP by MAC on the
> router was good enough! I'll have to remember how to remove that on
> the router though.

I don't think you should need to actually, just don't run the DHCP
client on the Pi and set the IP address manually instead.

>> Failing that, perhaps you could try unloading then reloading the
>> WiFi driver module occasionally, between toggling the interface
>> down/up.
>
> So something like this in the wifibump script?
>
> /sbin/ip link set wlan0 down
> modprobe -r brcmfmac
> sleep 5
> modprobe brcmfmac
> /sbin/ip link set wlan0 up

Yes, though if this is the same problem that you're having then
apparantly reloading the driver module doesn't work every time:
http://web.archive.org/web/20201123161546/https://andreas.scherbaum.la/blog/archives/1001-Reboot-the-Raspberry-Pi-on-network-failures-brcmfmac-brcmf_cfg80211_scan-scan-error-110.html

Martin Gregorie

unread,
Aug 25, 2021, 7:06:40 PM8/25/21
to
On Wed, 25 Aug 2021 22:24:05 +0000, Computer Nerd Kev wrote:

>
> I don't think you should need to actually, just don't run the DHCP
> client on the Pi and set the IP address manually instead.
>
That works for me - I've done this on both RPi and my Fedora systems on
my house LAN, which all have fixed IP addresses and hostnames.

/etc/hostname contains one line holding the fully qualified hostname as
it will be used locally, e.g.: rpi.local.lan

/etc/hosts contains at least:
IP-address fully-qualified-hostname list of aliases, e.g

192.168.5.2 rpi.local.lan rpi

In addition you can add other lines containing the IP, fqn aliases etc.
of printers, ADSL gateway, etc which have fixed IPs on your LAN. If all
hosts on your LAN have fixed IPs and hostnames then you don't need to run
a name service (e.g. named/unbound or DHCP server), and you can still run
dhcp if sone devices on your LAN can't be configured to use a fixed IP
address and host name.


--
--
Martin | martin at
Gregorie | gregorie dot org

Nikolaj Lazic

unread,
Aug 25, 2021, 7:21:20 PM8/25/21
to
Dana Wed, 25 Aug 2021 23:06:38 -0000 (UTC), Martin Gregorie <mar...@mydomain.invalid> napis'o:
Or he could configure DHCP server to give "static" fixed IPs to fixed MAC.

A. Dumas

unread,
Aug 25, 2021, 10:15:22 PM8/25/21
to
Yeah. That's 1000x easier & more convenient & thus less error-prone.

Adam Funk

unread,
Aug 26, 2021, 4:00:04 AM8/26/21
to
Reading that I thought "ugh, a systemd timer, I'd put it in crontab"
... then spotted this dig which some here will appreciate:

Yes, with systemd you actually need two files where "cron" can do
this in a single line. Don't know why people keep pretending that
systemd is so much better.


--
I heard that Hans Christian Andersen lifted the title for "The Little
Mermaid" off a Red Lobster Menu. ---Bucky Katt

Adam Funk

unread,
Aug 26, 2021, 10:15:05 AM8/26/21
to
That's what I was doing (DHCP "reservation" on the router). I'm now
trying a static IP address in the /etc/dhcpcd.conf file on the Pi
Zero.


--
You're the last hope for vaudeville.
---Groucho Marx to Alice Cooper

The Natural Philosopher

unread,
Aug 26, 2021, 12:04:35 PM8/26/21
to
/etc/dhcpcd.conf
I have static address - it doesn't affect 'drop outs' though

/etc/dhcpcd.conf :

interface wlan0
static ip_address=192.168.0.200
static routers=192.168.0.254
static domain_name_servers=192.168.0.100


/etc/wpa_supplicant/wpa_supplicant.conf :

country=GB
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
ssid="LivingRoom"
psk="SECRET.SQUIRREL"
key_mgmt=WPA-PSK
}



--
To ban Christmas, simply give turkeys the vote.
0 new messages