Saturday, November 23, 2013

Autostart Raspberry pi VNC and server

Last week i finally configured my Rpi, and had it setup as a server to get 24/7 access to all the gadgets in my apartment. I'm not very familiar with linux, and therefore it is probably a good ide to write down how i managed to do so, for future setups =)

First of all i wanted to get access to the Rpi from my main computer. I had two options, either just by a terminal (SSH), which is probably best for speed, or configure a remote desktop (VNC) to mirror the pi on my main computers screen. Since i'm not to familiar with the linux terminal, i figured i'd start off with the VNC like this...

Setting up remote desktop (VNC) on the Rpi using the program TightVNC according to this guide (skipped the SSH-part in the beginning):

Install the TightVNCServer on the Rpi like this:

Then try and start the server by entering: (change the resolution to the screen res where you are going to view the desktop)
The "1" is an ID, (you can start several different servers)
The program will now prompt for you to enter a password to get access to the remote desktop, set one!

There might be an permission issue, so to make sure that wont happen, do this:  (where "pi" is the username)

The VNC-server nr "1" can later be closed by typing:

Install TightVNC on Windows machine

Now that you have your VNC-server up and running, it is time to install the TightVNC-program on you main computer from there website:
When done, startup the TightVNC-Viewer (not the server), type in the IP-address and the ID that you specified on the pi and press "Connect". A good ide is to configure your router so that the ip of the Rpi never changes...

If the server is running, a prompt for the password will show up, enter it and a window with the Rpi-desktop will popup =)

If you make it full-screen, the way of getting out is by pressing alt+ctrl+shift+F.

Autostart VNC-server when Rpi boots

Next step is to get the server to start automatically when the Rpi starts up. There is no point of having a remote desktop if I every time the rpi starts have to have a keyboard, mouse and a screen attached to it to startup the server...

Create a file named tightvnc in the init.d folder, and open it in nano to edit its content:

Enter the following:
Press ctrl+x and y to exit and save.

Now we need to set permissions to the file to make it executable:

And the last thing we’re going to make is to update the rc.d file (which tracks which initilization scripts are in the /init.d/ folder):

Now it is time to test it: Reboot the Rpi:

And try connecting the ThightVNC-program on the main computer.

Autorun other scripts when Rpi boots

To autorun a script that doesn't need permissions when Rpi starts is a little easier. Take my nRF-server for instance:
Create (if not allready created) the folder

Then add a file with the ending ".desktop"  and edit it in nano:

Edit the file like this:
Where the importent stuff is the terminal=false (we want to start lxterminal), and the "Exec" that executes the script "sh /home/pi/" in the lxterminal, which is the script that starts the server...
Exit nano with ctrl+x and save (press y)

Now to make the .desktopfile executable:

Reboot the Rpi, and you can see that the lxterminal has started the NRF-server in an open terminal!