I'm upgrading from buster to bullseye on a raspberry pi 4B. Several jobs that start up at boot via crontab start fine....but later fail when they try to access the network (eg, for a mariadb insert or connect to mqtt broker):
OSError: [Errno 101] Network is unreachable
Problem does not occur when programs are run from the command line. Below is some context of the error in case useful. All help appreciated (I don't post much--guidance there welcome as well.)
In crontab:
@reboot python -u /home/pi/bin/mqttSRV_ControlLightsFR.py >> /home/pi/ControlLightsFROut.txt 2>&1
Error text
setSwitch-1: 2022-08-13 13:49:22 sending offtext to CLT, local time
Traceback (most recent call last):
File "/home/pi/bin/mqttSRV_ControlLightsFR.py", line 124, in <module>
setSwitch (0) # Lights off
File "/home/pi/bin/mqttSRV_ControlLightsFR.py", line 55, in setSwitch
MQTTpub(topic, '0', 0, False)
File "/home/pi/bin/mqtt_pub.py", line 37, in MQTTpub
client.connect(broker_address, broker_port)
File "/home/pi/.local/lib/python3.9/site-packages/paho/mqtt/client.py", line 914, in connect
return self.reconnect()
File "/home/pi/.local/lib/python3.9/site-packages/paho/mqtt/client.py", line 1044, in reconnect
sock = self._create_socket_connection()
File "/home/pi/.local/lib/python3.9/site-packages/paho/mqtt/client.py", line 3685, in _create_socket_connection
return socket.create_connection(addr, timeout=self._connect_timeout, source_address=source)
File "/usr/lib/python3.9/socket.py", line 843, in create_connection
raise err
File "/usr/lib/python3.9/socket.py", line 831, in create_connection
sock.connect(sa)
OSError: [Errno 101] Network is unreachable