# RPz(W) wlan down detection - help

**URL:** <https://discourse.nodered.org/t/rpz-w-wlan-down-detection-help/16460>\
**Category:** General\
**Created:** [8 October 2019 09:37 UTC](https://discourse.nodered.org/t/rpz-w-wlan-down-detection-help/16460 "2019-10-08T09:37:22Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [8 October 2019 09:37 UTC](https://discourse.nodered.org/t/rpz-w-wlan-down-detection-help/16460/1 "2019-10-08T09:37:22Z")

</div>

I have this problem where I have a RPz(W) and now and then the `wlan0` interface goes down.

I don't know if it is because the WAP goes down - which I hope it isn't happening - or something on the RPI is stopping the interface for a while.

What ever.

So, where I am at now is how to detect when `wlan0` goes down.

Sorry if this is a dumb question. I seem to be good at asking them.

---

<div class="post-metadata">

**Author:** ![kuema](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kuema/32/6542_2.png) [@kuema](https://discourse.nodered.org/u/kuema)\
**Post date:** [8 October 2019 09:44 UTC](https://discourse.nodered.org/t/rpz-w-wlan-down-detection-help/16460/2 "2019-10-08T09:44:15Z")

</div>

Not a dumb question in any way!

I have a similar issue with both of my Pi Zero W. Now and then, they drop out of my WiFi for about 70-72 minutes (every time). Very sporadically, sometimes after days/weeks without any issue. Nothing unusual in the log files.

As a crude and quick solution I was thinking about a small Node-RED flow that restarts the Wifi service after n failed pings. 🤔

The curious thing is the duration of ~72 minutes, but I haven't had the time to investigate any deeper, because the devices always reconnect after that period. 🙈

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [8 October 2019 09:50 UTC](https://discourse.nodered.org/t/rpz-w-wlan-down-detection-help/16460/3 "2019-10-08T09:50:56Z")

</div>

My problem isn't as _easy_ as yours.

Alas though I have seen WAP outages and restores the RPz usually comes back.

Now and then it doesn't and I know it is _M.I.A._ the LED on it is going nuts. (Crazy blinking)  
and it never reconnects.

I need to reboot it.

So I am wanting to find out how to detect if the `wlan0` is up or down.

Then, after _n_ attempts, it issues a command to try and get the interface back up.

BTW, what command do you use to get the `wlan0` interface back up?

---

<div class="post-metadata">

**Author:** ![kuema](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kuema/32/6542_2.png) [@kuema](https://discourse.nodered.org/u/kuema)\
**Post date:** [8 October 2019 10:00 UTC](https://discourse.nodered.org/t/rpz-w-wlan-down-detection-help/16460/4 "2019-10-08T10:00:22Z")

</div>

Did you configure it with systemd?

If so, you could use `networkctl status wlan0` and parse the output somehow.

If haven't built the flow yet (because it always comes back after 72min), but I would try `sudo systemctl restart wpa_supplicant@wlan0.service`.

You would need to add this to your sudoers file, of course.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [8 October 2019 10:05 UTC](https://discourse.nodered.org/t/rpz-w-wlan-down-detection-help/16460/5 "2019-10-08T10:05:33Z")

</div>

Thanks.

I have dug (and dug and dug) and I was told this command will work.

`ip link set wlan0 up`

But thanks for the `networkctl status wlan0` bit.

I will have to just add this as part of the existing flow.

I'll have to work out how to implement the _how_ part.

Oh, the output of the `networkctl status wlan0`. . . . what indicates that it is down?

---

<div class="post-metadata">

**Author:** ![kuema](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kuema/32/6542_2.png) [@kuema](https://discourse.nodered.org/u/kuema)\
**Post date:** [8 October 2019 10:08 UTC](https://discourse.nodered.org/t/rpz-w-wlan-down-detection-help/16460/6 "2019-10-08T10:08:29Z")

</div>

If think `ip link set wlan0 up` is just for the interface part.

Regardless of how you manage wlan0, I think restarting the `wpa_supplicant` could be necessary.

`ifup wlan0` and `ifdown wlan0` should take care of that, if you use the standard Debian network scripts.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [8 October 2019 10:10 UTC](https://discourse.nodered.org/t/rpz-w-wlan-down-detection-help/16460/7 "2019-10-08T10:10:39Z")

</div>

> [@kuema](#):
>
> `ifup wlan0` and `ifdown wlan0` should take care of that, if you use the standard Debian network scripts.

I have read to **NOT** use those commands as they are depricated.

What I posted is more up to date.

---

<div class="post-metadata">

**Author:** ![afelix](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afelix/32/9743_2.png) [@afelix](https://discourse.nodered.org/u/afelix)\
**Post date:** [8 October 2019 10:11 UTC](https://discourse.nodered.org/t/rpz-w-wlan-down-detection-help/16460/8 "2019-10-08T10:11:20Z")

</div>

> [@Trying\_to\_learn](#):
>
> Now and then it doesn't and I know it is _M.I.A._ the LED on it is going nuts. (Crazy blinking)  
> and it never reconnects.
> 
> I need to reboot it.

LEDs crazy blinking reminds me of the kernel panics... might be worth looking into what happens at that moment, but if you can’t access the machine at all when it happens that gets harder.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [8 October 2019 10:12 UTC](https://discourse.nodered.org/t/rpz-w-wlan-down-detection-help/16460/9 "2019-10-08T10:12:56Z")

</div>

> [@afelix](#):
>
> LEDs crazy blinking reminds me of the kernel panics... might be worth looking into what happens at that moment, but if you can’t access the machine at all when it happens that gets harder.

Correct.

Being a headless machine it is rather difficult to see.

`sudo dmesg` doesn't give me much.  
I've checked other logs and they too don't show much.

I can `ping` the machine, but can't `ssh` to it.

So I can only unplug the power supply and plug it in again.

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [8 October 2019 10:15 UTC](https://discourse.nodered.org/t/rpz-w-wlan-down-detection-help/16460/10 "2019-10-08T10:15:21Z")

</div>

If you can’t ssh to it, you can’t do a sudo dmesg.

It might be that it is checking the filesystem, which could take a while, after that it starts sshd.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [8 October 2019 10:16 UTC](https://discourse.nodered.org/t/rpz-w-wlan-down-detection-help/16460/11 "2019-10-08T10:16:02Z")

</div>

Just as a bit more, this is the block of text I found:

> What you want is the modern way of configuring network interfaces, which is event-driven: when an interface is brought up, an event is fired and dhcpcd configures networking (see /etc/dhcpcd.conf). When an interface disappears, an event is fired and dhcpcd deconfigures networking.  
> In a sense, it is all "hotplug" by default now.

> Forget the old commands "ifup wlan0" / "ifdown wlan0".  
> Instead get in the habit of using "ifconfig wlan0 up" / "ifconfig wlan0 down". Or, to be entirely up-to-date, "ip link set wlan0 up" / "ip link set wlan0 down". These commands will make dhcpcd do something.

---

<div class="post-metadata">

**Author:** ![kuema](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kuema/32/6542_2.png) [@kuema](https://discourse.nodered.org/u/kuema)\
**Post date:** [8 October 2019 10:16 UTC](https://discourse.nodered.org/t/rpz-w-wlan-down-detection-help/16460/12 "2019-10-08T10:16:31Z")

</div>

`ifup` and `ifdown` are not deprecated, these scripts are the standard Debian configuration scripts for network interfaces.

I believe you mean `ifconfig`... that one is getting superseded by the newer `ip` tool.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [8 October 2019 10:18 UTC](https://discourse.nodered.org/t/rpz-w-wlan-down-detection-help/16460/13 "2019-10-08T10:18:02Z")

</div>

Yeah, ok. Sorry. Tripped on the terms.

But that block is what I found while digging.

Hope that helps you a bit too.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [8 October 2019 10:20 UTC](https://discourse.nodered.org/t/rpz-w-wlan-down-detection-help/16460/14 "2019-10-08T10:20:30Z")

</div>

True. But can't `sudo dmesg` see back a couple of boots?

I reboot it, let it settle down, SSH to it and do the command.

I don't see anything worrying or indicative of a kernel panic.

(Though I have had fun with kernel panics not being recorded on another machine. LUCKILY the _message_ had some _junk_ in it which then led to finding the kernel panic. This one doesn't have anything like that.)

---

<div class="post-metadata">

**Author:** ![afelix](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afelix/32/9743_2.png) [@afelix](https://discourse.nodered.org/u/afelix)\
**Post date:** [8 October 2019 10:21 UTC](https://discourse.nodered.org/t/rpz-w-wlan-down-detection-help/16460/15 "2019-10-08T10:21:26Z")

</div>

No, dmesg like that only shows for the current boot, from the moment you turned it on.

---

<div class="post-metadata">

**Author:** ![kuema](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kuema/32/6542_2.png) [@kuema](https://discourse.nodered.org/u/kuema)\
**Post date:** [8 October 2019 10:23 UTC](https://discourse.nodered.org/t/rpz-w-wlan-down-detection-help/16460/16 "2019-10-08T10:23:26Z")

</div>

If it really panics, then the logs may be lost anyway. ☹ These Pi Zeros are hell to debug once they are deployed without a display connected to it.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [8 October 2019 10:23 UTC](https://discourse.nodered.org/t/rpz-w-wlan-down-detection-help/16460/17 "2019-10-08T10:23:46Z")

</div>

> [@afelix](#):
>
> No, dmesg like that only shows for the current boot, from the moment you turned it on.

Well, that's interesting.

On the other machine when the `dmesg` was done the dates were dating back days and it was only at the end when we saw the recent events. (and the corruption of the file) which led to working out it was a kernel panic.  
But that's on another machine.

Ok. So if it happens, I unplug it, move it to a **good place** plug in monitor/keyboard and see what dmesg says then?

But that will show that boot, not the previous session which hung.

Confused.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [8 October 2019 10:26 UTC](https://discourse.nodered.org/t/rpz-w-wlan-down-detection-help/16460/18 "2019-10-08T10:26:07Z")

</div>

Ah. Thanks. That's good to know. Kinda.

I'm hoping that it is just _upset_ and if I reset the wlan0 with the command it will be happy.

Alas it is a catch 22.  
I can't really prove it and will have to wait for it to happen again.

Thing is: How do I detect it?

The command you said.... Yeah. Nice, but when the interface is down, what does it given?  
I'm guessing I am going to have to parse it looking for something specific which indicates it is down.

---

<div class="post-metadata">

**Author:** ![kuema](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kuema/32/6542_2.png) [@kuema](https://discourse.nodered.org/u/kuema)\
**Post date:** [8 October 2019 10:30 UTC](https://discourse.nodered.org/t/rpz-w-wlan-down-detection-help/16460/19 "2019-10-08T10:30:47Z")

</div>

> [@Trying\_to\_learn](#):
>
> The command you said.... Yeah. Nice, but when the interface is down, what does it given?  
> I'm guessing I am going to have to parse it looking for something specific which indicates it is down.

On my Pi3 (via ethernet) it says for the `wlan0` state: `State: off (unmanaged)`

The PiZ (via Wifi): `State: routable (configured)`

BTW: If anyone has a better idea how to get the connection status using Node-RED... please shoot. 😀

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [8 October 2019 10:32 UTC](https://discourse.nodered.org/t/rpz-w-wlan-down-detection-help/16460/20 "2019-10-08T10:32:12Z")

</div>

Again: Thanks.

ITMT, I double looked at what happened when I did the command you said:

```auto
pi@TelePi:~ $ networkctl status wlan0
WARNING: systemd-networkd is not running, output will be incomplete.

● 2: wlan0
       Link File: n/a
    Network File: n/a
            Type: wlan
           State: n/a (unmanaged)
            Path: platform-20300000.mmc
          Driver: brcmfmac
      HW Address: b8:27:eb:2f:8f:57 (Raspberry Pi Foundation)
         Address: 192.168.0.93
         Gateway: 192.168.0.254
pi@TelePi:~ $ 

```

First line.  
That's not good - yeah?  
BTW, I use FIXED IP addresses.

[Next page](https://discourse.nodered.org/t/rpz-w-wlan-down-detection-help/16460.md?page=2)
