Sunday, November 29, 2015

Autostart a remote session with the Pi VNC

Having VNC means that I don't have to have a display connected to the Raspberry Pi and still experience what would be on a screen if one were connected.

On my Mac it looks like this. Sometimes it wouldn't be needed as you using the command line would be fine. This can be useful for

  • Scratch programming 
  • Programmes that display something like pictures, directions etc


I included how to set up VNC in this post on one of my other Blogs

What I wanted to achieve as well was for the VNC connection to be started at boot time so that I could immediately connect via VNC rather than having to go through a SSH command line to start it.

I adapted instructions from here having tried others that didn't work for me. I am including them below for my own record and any visitors

Run at boot

Create a file to host the information for start up
sudo nano /etc/init.d/vncboot
Paste the following into it 
#!/bin/sh
### BEGIN INIT INFO
# Provides: vncboot
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start VNC Server at boot time
# Description: Start VNC Server at boot time.
### END INIT INFO
 
USER=pi
HOME=/home/pi

export USER HOME

case "$1" in
 start)
   echo "Starting VNC Server"
   #Insert your favoured settings for a VNC session
   /usr/bin/vncserver :1 -geometry 1280x800 -depth 24
   ;;

 stop)
   echo "Stopping VNC Server"
   /usr/bin/vncserver -kill :1
   ;;

 *)
   echo "Usage: /etc/init.d/vncboot {start|stop}"
   exit 1
   ;;
esac

exit 0
Modify the file permissions so it can be executed
chmod 755 /etc/init.d/vncboot
Enable dependency based boot sequencing
update-rc.d vncboot defaults
Reboot your Raspberry PI and you should find a vncserver already started.




No comments:

Post a Comment