I have a device (e.g. raspberry) running a minimal version of linux built with YOCTO and with not network manager available. At a given time a network configuration may be present in the file /home/root/wpa.conf, but it is not guaranteed that the corresponding wifi network can be detected when the configuration is present (the device can move). I want to write a service that constantly tries to connect to the wifi and, retries when it fails. The problem is that wpa_supplicant does not exit when the SSID is not found.

This is my service:


Restart=always # this would be useful if wpa_supplicant exited on fail


This is the script:

ifconfig wlan0 up
udhcpc -i wlan0 -b
wpa_supplicant -i wlan0  -c /home/root/wpa.conf

I omitted the -B in wpa_supplicant because the service would exit after running the command, killing wpa_supplicant. I tried to set type=forking in the service but it didn't work. However, I don't think this is the problem in this case.

How can i modify my service and script in order to continuously attempt to connect?

1 Answer 1


wpa supplicant is not supposed to exit; you got a misconception how an SSID "is found": you need to wait for a beacon to appear if you want to look for SSIDs. If you know the SSID and BSSID of the AP, you can just try to send a registration packet to the AP, but that will have to be done in multiple attempts, too, because a single failure to respond might be totally normal – this is a shared medium after all, and you don't know the RF environment of the access point.

So, what you want to implement is actually the default observable behaviour for practically all managers of network connections I'm aware of, that only being systemd's NetworkManager and wicd, the Android connection manager, the windows connection manager and the thing that iOs has.

So, really, I don't think you're actually solving anything that's not already solved; "connect to this network when available" is what everyone already offers.

So, the right solution would be to configure the network configuration manager (on the raspberry pi, chances are that's the NetworkManager) to look for that network - and that's it.

  • Thanks for the clarification. The problem is that I am working on a very minimal version of Linux built with YOCTO and I don't have any network manager available, so I am trying to do it by myself.
    – firion
    Jul 15, 2021 at 12:47
  • 1
    but your question is tagged systemd, so I have serious doubts you get anything better than NetworkManager for this use case. Also, when you have constraints, you should state them in the question, so that people can know them when answering! Jul 15, 2021 at 12:49
  • You are right, I modified the question.
    – firion
    Jul 15, 2021 at 12:57
  • so, yes, the answer remains the same: you want the features of a network manager, so use a network manager. NetworkManager really really really suggests itself as well-integrated with your platform (building your own distro with Yocto doesn't change that, on the contrary!), but wicd or any other existing manager would be right. You need a stateful demon, not just a shell script with a loop. Jul 15, 2021 at 13:11
  • Would connman be a good option?
    – firion
    Jul 15, 2021 at 13:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .