ok what do you recommend; here is my issue:
I have a rpi connected to my router via a powerline adapter. The rpi runs 2 python scripts that I need to run constantly. So Ive added this to my rc.local:
Code: Select all
# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
printf "My IP address is %s\n" "$_IP"
fi
#added2rebootRunTmuxReconnectSchedule
echo > /tmp/test1.txt
sleep 10
tmux new -d -s mqttListen 'python /home/pi/Documents/python/mqttReceive.py' \; set -t m$
tmux new -d -s tsrbrclocal 'python /home/pi/Documents/python/tsrb430v3.py'
#sudo -u pi bash /home/pi/tmux_start.sh &
exit 0
Whenever the rpi goes down due to power outs, it reboots fine of course, and apparently those 2 scripts are launched just fine as well, because whenever i log into it via ssh, both tmux sessions are always running fine. But mqttReceive.py tmux session has this network unreachable error:
Code: Select all
Traceback (most recent call last):
File "/home/pi/Documents/python/mqttReceive.py", line 49, in <module>
client.connect(MQTT_SERVER, 1883, 60)
File "/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py", line 839, in connect
return self.reconnect()
File "/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py", line 962, in reconnect
sock = socket.create_connection((self._host, self._port), source_address=(self._bind_address, 0))
File "/usr/lib/python2.7/socket.py", line 571, in create_connection
raise err
socket.error: [Errno 101] Network is unreachable
Ive noticed that sometimes after a pwoerout, the rpi is unpingable and I confirm with the router when I find the reserved IP address for that rpi is not on the dhcp list. So it must be that although the router comes back and the rpi comes back after a powerout, rpi seems to not be able to reconnect to the router for some reason.
So Ive been asking about how to make sure the network adapter is always up and working. It was suggested that I create a check for a connection by creating a checkwifi.sh file and making it executable. I know its called checkwifi.sh but it should also work for the lan connection since there is nothing specific in it about just the wlan0 or even the eth0 for that matter:
Code: Select all
#!/bin/bash
#ping the router to check the wifi connection
ping -c4 192.168.1.1 > /dev/null
# if exit code ($?) of the ping command is failed (not 0) then reconnect
if [ $? != 0 ]
then
systemctl restart dhcpcd
fi
and here is /etc/network/interfaces:
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
Code: Select all
auto lo
iface lo inet loopback
#auto eth0
iface eth0 inet manual
#allow-hotplug wlan0
iface wlan0 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
allow-hotplug wlan1
iface wlan1 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
But it keeps happening, after a powerout comeback, the router is up and fine, the rpi is up and running but that python script has the network unreachable error and it is confirmed that the rpi is not on the network.
I had switched over to wifi to see if it was the powerline adapter, but it happens on wifi as well. It has to be something with the configurations I have which are not enough to make the rpi get back on the router.
How do I FORCE my rpi to get back on the router's dhcp?