No meu Pi eu tenho um script que verifica se eu tenho um endereço IP antes de fazer qualquer outra coisa:
IP.py
import socket
from time import sleep
def checknetwork():
ip = False
try:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(('google.com', 0))
ip = s.getsockname()[0]
s.close()
except socket.error:
return False
else:
return ip
def main():
x = checknetwork()
while x == False:
print "Checking network ..."
x = checknetwork()
sleep(1)
Isso apenas tenta abrir um soquete para algum endereço conhecido e falha até que ele possa realmente obter uma conexão. Torne-o executável com:
chmod +x ip.py
Você precisa adicionar isso ao boot, adicionando-o ao /etc/rc.local:
#!/bin/sh -e # # rc.local # # This script is executed at the end of each multiuser runlevel. # Make sure that the script will "exit 0" on success or any other # value on error. # # In order to enable or disable this script just change the execution # bits. # # By default this script does nothing. /usr/bin/python /directory/where/you/put/ip.py exit 0
Espero que ajude