RPz(W) wlan down detection - help

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

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

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.

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.

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?

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. :grinning:

1 Like

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.

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.

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

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

1 Like

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. :frowning:

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

Thanks again.

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. :grinning:

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.

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.

[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.

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.

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.

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

Check the results

Should look like this...

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

Additional resources:

I hope I did not forget anything... :nerd_face:

2 Likes

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:

#!/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:

#!/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 " "