0

We switch off WiFi an a raspberry over night. In the morning both is switched on together. Unfortunately the pi starts faster than the access point and therefore the pi could not connect to a wifi. When the pi is started manually later, when the AP is up and running, it connects to the given wifi. Is there a way that the pi checks if there is a wifi available when he is not connected?

Thanks for your help.

Regards Martin

1
  • Martin - have you tried the answer below? Did it work? Feedback would be appreciated.
    – Seamus
    Commented Dec 12, 2021 at 22:37

1 Answer 1

1

I suspect your problem is that your DHCP client (dhcpcd) has "given up" before your WiFi network begins responding. I think there are two possible solutions:

  1. Postpone the dhcpcd startup, or
  2. Tell dhcpcd to try longer.

1. Postpone dhcpcd startup:

You might try this... I've tried it on my system; it didn't break anything, and did seem to delay the boot process:

Edit the file /lib/systemd/system/dhcpcd.service - for example:

sudo nano /lib/systemd/system/dhcpcd.service

Add the following line in the [Service] section: ExecStartPre=/bin/sleep 60. Insert it just before the ExecStart= line as shown below:

[Service]
Type=forking
PIDFile=/run/dhcpcd.pid
ExecStartPre=/bin/sleep 60
ExecStart=/usr/lib/dhcpcd5/dhcpcd -q -b
ExecStop=/sbin/dhcpcd -x

I'm not well-versed in systemd, but this one-line addition to /lib/systemd/system/dhcpcd.service may give your WiFi enough of a head start to resolve your issue. I'm sure there's a more elegant solution - I'll post an edit if I find it, but try this in the meantime & let us know how it worked.

2. Tell dhcpcd to try longer (EDIT):

Here's an option that should work - I like this one better than the original answer because:

a. it seems less kludge-y than the systemd service file modification above, and

b. Roy Marples (the dhcpcd author) is on record confirming the timeout option causes dhcpcd to persist in its quest for an IP address indefinitely.

Here's how:

  1. Open /etc/dhcpcd.conf with your favorite editor - for example:
sudo nano /etc/dhcpcd.conf
  1. Insert the following line somewhere near the end of the file:
timeout 0  
  1. reboot or re-start dhcpcd:
sudo reboot 

## OR ##

sudo systemctl restart dhcpcd

As before, your feedback is requested.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.