I am very new to this stuff. Trying to see if anyone has accomplished what I am looking to do.
I would like to have a ping to my android phone running on my Raspberry Pi. When it gets a response I want the Pi to run a command (turn on lights etc). My goal is to have the lights turn on as soon as I get home and my android phone is ping-able. Then eventually I want to create something that does the same after ping is lost for an hour.
I have seen people do similar things for external URLs with code below. Any ideas?
import socket from urllib2 import urlopen, URLError, HTTPError socket.setdefaulttimeout( 23 ) # timeout in seconds url = 'http://google.com/' try : response = urlopen( url ) except HTTPError, e: print 'The server couldn\'t fulfill the request. Reason:', str(e.code) except URLError, e: print 'We failed to reach a server. Reason:', str(e.reason) else : html = response.read() print 'got response!' # do something, turn the light on/off or whatever