Trying to open a browser on startup on my Raspberry Pi
On my Pi I have a script that checks if I have an IP address before it does anything else:
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)
This just tries to open a socket to some known address and fails until it can actually get a connection. Make it executable with:
chmod +x ip.py
You then need to add this to bootup by adding it to /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
Hope that helps
Related videos on Youtube
Andrew Briz
Updated on September 18, 2022Comments
-
Andrew Briz over 1 year
I have Raspbian running on my Raspberry Pi, and I want to have a browser appear when it starts up. I am able to open a Midori window to the right page on start up, but my problem is that I receive a "cannot resolve host name" error, such like I would get if I was not connected to the internet. I followed the instructions listed on http://www.niteoweb.com/blog/raspberry-pi-boot-to-browser which were to enter in the command line:
$ sudo nano /etc/xdg/lxsession/LXDE/autostart
Comment everything and add the following lines:
@xset s off @xset -dpms @xset s noblank @midori -e Fullscreen -a http://google.com
This process does open a Midori window on startup, but with the error mentioned above. If the page is refreshed then it works, but I want to be able to bring up a url without having a mouse or keyboard. I read that at the beginning of startup, internet may not be connected yet, so I created a bash script that delayed the process by twenty seconds before opening the Midori window. This did no work either, the same error persisted. I have also tried the process with chromium, to no avail as well.
-
jasonwryan over 10 yearsHow does this relate to the OP's question?