# 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:** 11\
**Page:** 2

<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:35 UTC](https://discourse.nodered.org/t/rpz-w-wlan-down-detection-help/16460/21 "2019-10-08T10:35:38Z")

</div>

That's correct. You have to use systemd for the interface configuration.

It's a bit tricky to set up if you are unfamiliar with it, but works quite well after that.

I used this Arch wiki entry for hints: [https://wiki.archlinux.org/index.php/Systemd-networkd](https://wiki.archlinux.org/index.php/Systemd-networkd)

---

<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:36 UTC](https://discourse.nodered.org/t/rpz-w-wlan-down-detection-help/16460/22 "2019-10-08T10:36:19Z")

</div>

In basics, using `dmesg` as command reads directly from the kernel ring buffer, so that includes only the current session. However, this output is logged to file too, just in a less readable format. You can access those log files too, but it's probably easier if I just link you to a thread that shows someone else trying to do that: [https://unix.stackexchange.com/questions/181067/how-to-read-dmesg-from-previous-session-dmesg-0](https://unix.stackexchange.com/questions/181067/how-to-read-dmesg-from-previous-session-dmesg-0)

---

<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:39 UTC](https://discourse.nodered.org/t/rpz-w-wlan-down-detection-help/16460/23 "2019-10-08T10:39:06Z")

</div>

Though it is headless, it boots to the GUI. That's how I set it up to connect to my WAP.

I clicked on the WiFI icon, selected my WAP name, typed in the password when asked and all was sweet there after.

So, what am I missing?

(oh, just on a tangent: I have been told to NOT use `beef stew` as a password!)  
I can tell you why if you are interested later.

---

<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:43 UTC](https://discourse.nodered.org/t/rpz-w-wlan-down-detection-help/16460/24 "2019-10-08T10:43:47Z")

</div>

Oh, so I guess it is using Networkmanager or something like that.

I prefer a GUI-less setup for these devices. It is easier at first with a GUI, but you don't need that to get Wifi working. It can all be done using the console. Either via standard Debian script or by using systemd-networkd.

---

<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:48 UTC](https://discourse.nodered.org/t/rpz-w-wlan-down-detection-help/16460/25 "2019-10-08T10:48:31Z")

</div>

The only reason I am doing it that way is that when I first started off _breeding_ RPI's I would flash the image to the SD card, plug it in and go through all the config.

Then it would boot to the GUI.

On the older models, I would configure the CAT-5 (ethernet) port. When I got to WiFi ones, I just changed setting the Ethernet to changing the WiFi ones.

That way it wasn't too much different to how it was with the Cat-5 ones.

And yes, I know it is costing a bit more running them with the GUI headless: now and then if I need to do some things I can VNC into them and do things locally without needing to keep the main machine connected.

Anyway, so..... What you are saying implies - to me - that the GUI WiFi setup is systemically broken, or doesn't really work correctly.

(Shudder)

I can't be right - can I?

---

<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:57 UTC](https://discourse.nodered.org/t/rpz-w-wlan-down-detection-help/16460/26 "2019-10-08T10:57:05Z")

</div>

> [@Trying\_to\_learn](#):
>
> Anyway, so..... What you are saying implies - to me - that the GUI WiFi setup is systemically broken, or doesn't really work correctly.

_Could_ be, or it crashes due to resource limits... (it's a Pi Zero after all). Who knows.

In your case I would invest the time in setting these things up without starting a UI. A lot more robust, less error prone and easier to reproduce than relying on some nice user interface. 😀

---

<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 11:01 UTC](https://discourse.nodered.org/t/rpz-w-wlan-down-detection-help/16460/27 "2019-10-08T11:01:17Z")

</div>

I'm trying to get my head around the link you posted. It is written in _Greek_ to me.  
_(Martian?)_

So how do I get the systemd to start it?

My _knowledge_ (or lack there of) is something like:  
`sudo systemctl enable *name*`  
as with Node-Red.

```auto
Basic usage

The systemd package is part of the default Arch installation and contains all needed files to operate a wired network. Wireless adapters, covered later in this article, can be set up by services, such as wpa_supplicant or iwd.
Required services and setup

To use systemd-networkd, start/enable systemd-networkd.service.

It is optional to also start/enable systemd-resolved.service, which is a network name resolution service to local applications, considering the following points:

    The systemd-resolved service is required if DNS entries are specified in .network files,
    It can be used to automatically obtain DNS addresses from the network DHCP client,
    It is important to understand how resolv.conf and systemd-resolved interact to properly configure the DNS that will be used, some explanations are provided in systemd-resolved.
    Note that systemd-resolved can also be used without systemd-networkd.

```

Yeah, ok. Kinda got it.  
But I can not resolve it to the complete command.

I'm reading it as something like:  
`sudo systemd-networkd enable systemd-networkd.service`

But I am not confident enough to believe that.

---

<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 11:06 UTC](https://discourse.nodered.org/t/rpz-w-wlan-down-detection-help/16460/28 "2019-10-08T11:06:36Z")

</div>

> [@Trying\_to\_learn](#):
>
> But I am not confident enough to believe that.

No, there are multiple steps involved, including disabling the old network configuration. So don't do this over SSH! 🙈

If you are patient, I can try to gather some more info for you later.

---

<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 11:14 UTC](https://discourse.nodered.org/t/rpz-w-wlan-down-detection-help/16460/29 "2019-10-08T11:14:32Z")

</div>

Reading that link further it is confusing because it is saying/implying (well actauly it is written) that I have to make a file for the connection in the `/etc/systemd/network/` directory.  
I thought all interfaces were in `/etc/network/interfaces` file. So the branch to `etc/systemd/network` is a bit unknown to me.

I thought Wifi connections were done via the `/etc/wpa-supplicant/wap-supplicant.conf` file.

Which is totally against what I have learnt to now. Though I did start at a bad part of the time line when they decided to stop doing things one way and do them another way.  
Typically just after I wrote down the wrong ways.

I sort of get what the link is saying but as I just said: it is against the grain of what I was told/shown/read how to do it.

Just curious: Why couldn't I do it over SSH? I get that if it goes _south_ I can't just reconnect.  
No big. Just that if I am doing it on that machine directly, I am kind of therefore NOT connected to the web in that I can't use the browser to come and ask for help.  
(Well, I think so. I tried it earlier and the poor RPI just p00ps itself when I load FF)  
So if I run into any problems it is going to be painful.  
I have only 1 monitor. ☹

I think it is nearly bed time for me too. 15 hours uptime for today may be enough.

Thanks again.

---

<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 15:53 UTC](https://discourse.nodered.org/t/rpz-w-wlan-down-detection-help/16460/30 "2019-10-08T15:53:11Z")

</div>

Alright Andrew, as promised.

These are steps I took to let networkd manage the Wi-Fi interface on my Pi Zeros. I'll keep this for my own documentation... two birds, one stone. 😀

All steps are described for the interface `wlan0`. Note that the filenames and commands are containing `wlan0`, this is important.

### Initial steps

I would do this in a local session, because the network connection **will** be disrupted.

First of all, you need to disable your GUI boot.  
Then stop and disable your existing network management service. (I don't know which one you are using, probably NetworkManager).

### Configure wpa-supplicant for ''wlan0''

Filename: `/etc/wpa_supplicant/wpa_supplicant-wlan0.conf`  
The content is configured as usual, nothing specific to networkd here. Configure as needed.

```auto
country=DE
network={
  ssid="my-wifi-ssid"
  psk="encoded-password"
}

```

### Create the networkd config file for ''wlan0''

Filename: `/etc/systemd/network/wlan0.network`

An example file, change IP addresses as needed.

```auto
[Match]
Name=wlan0

[Network]
Description=Wifi wlan0 static
Address=10.23.45.67/24
Gateway=10.23.45.1
DNS=10.23.45.2
DNS=10.23.45.3

```

And now the interesting parts to get everything up and running.  
Everything needs to be run as **root**. (you can type `sudo -i` to get a root shell)

### Stop and disable the default networking scripts

This will disable the default Debian network scripts that use `/etc/network/interfaces`. This config will no longer be used.

```bash
systemctl stop networking.service
systemctl disable networking.service

```

### Enable and start the wpa\_supplicant for ''wlan0''

This starts a wpa\_supplicant instance for wlan0 using the config file you created earlier.

```bash
systemctl enable wpa_supplicant@wlan0.service
systemctl start wpa_supplicant@wlan0.service

```

### Enable and start the Networkd service

This starts the systemd network service itself.

```bash
systemctl enable systemd-networkd.service
systemctl start systemd-networkd.service

```

### Check the results

Should look like this...

```bash
root@pizero:~# networkctl 
IDX LINK TYPE OPERATIONAL SETUP     
  1 lo loopback carrier unmanaged 
  2 wlan0 wlan routable configured

```

Additional resources:

- [https://wiki.archlinux.org/index.php/systemd-networkd](https://wiki.archlinux.org/index.php/systemd-networkd)
- [https://remy.grunblatt.org/using-systemd-networkd-with-wpa\_supplicant-to-manage-wireless-network-configuration.html](https://remy.grunblatt.org/using-systemd-networkd-with-wpa_supplicant-to-manage-wireless-network-configuration.html)
- [https://forum.manjaro.org/t/how-to-use-systemd-networkd-to-manage-your-wifi/1557](https://forum.manjaro.org/t/how-to-use-systemd-networkd-to-manage-your-wifi/1557)

I hope I did not forget anything... 🤓

---

<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 19:47 UTC](https://discourse.nodered.org/t/rpz-w-wlan-down-detection-help/16460/31 "2019-10-08T19:47:29Z")

</div>

Thanks.

I shall apply this as soon as I can.

Oh, just as a kind of thanks, this is stuff I found about how to detect WLAN0 state and ways to re-set it.

One way:

```auto
#!/bin/bash

# keep wifi alive
# change IP address as needed to your router/WAP.
ping -c2 192.168.1.1 
 
if [$? != 0] 
then 

  sudo ifconfig wlan0 down
  sleep 30
  sudo ifconfig wlan0 up
  
fi

```

and another way which is a bit more informative:

```auto
#!/bin/bash

# keep wifi alive
echo "................................................"
date "+%Y.%m.%d %H:%M:%S"
echo " "
# again: change to suit
ping -c2 192.168.1.1 
 
if [$? != 0] 
then 
  echo " "
  echo "No network connection, restarting wlan0"
  
  sudo ifconfig wlan0 down
  sleep 30
  sudo ifconfig wlan0 up
  
else
    echo " "
    cat /proc/net/wireless
fi
echo "................................................"
echo " "

```

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