Raspberry Pi – VNC

Remote Deskop VNC on Raspberry Pi

This is where things start to take shape. You can now unplug the wired network and connect via the wifi though putty. Keep in mind that the wifi local IP and wired local IP may be different. Probably only in the last number. This complicates things because some routers/AP/etc don’t exactly assign the IP right away. Inevitably, I end up unplugging, restarting, and plugging in some repeated-random fashion until it’s connected.

There are several programs for VNC that are available. Some will not host the native :0 screen. Meaning the actual desktop on the monitor and the one you will view via vnc will be different. x11vnc does host :0 so install it

sudo apt-get install x11vnc

It’s a good idea to set a password for x11vnc

x11vnc -storepasswd

At this point the monitor should show on start-up. It may not be the correct resolution you can play with /boot/config.txt to get it right putting the comment in #hdmi_safe=1 may help. You might have to set the specific resolution of the monitor in the file.

So you’ve rebooted about a hundred times and still haven’t seen anything cool. Here is where it starts. When you have everything just like it should be run this command and don’t restart.

x11vnc -bg -nevershared -forever -tightfilexfer -usepw -display :0

Check if it’s really running

ps -ef | grep vnc

Now you want to run that ridiculous command every time before starting the vnc and connecting. We need to set it to run on start-up. It would be nice if this would run in the background and not bother you anymore.

cd ~
cd .config
mkdir autostart
cd autostart
sudo nano x11vnc.desktop

Paste this in:

[Desktop Entry]
Name=X11VNC Server
Comment=Share this desktop by VNC
Exec=x11vnc -bg -nevershared -forever -tightfilexfer -usepw -display :0
Icon=computer
Terminal=false
Type=Application
StrtupNotify=false
#StartupWMClass=x11vnc_port_prompt
Categories=Network;RemoteAccess;

Putty connects to the pi so that you can give it commands. We want to see the actual display, this takes a bit more. X11 forwarding has to be checked, and the tunneling needs to be set just right so that you can connect. Look through the putty options. Check the appropriate boxes, and set X11 forwarding so that it can be accessed from your local computer (via putty)

Source port: 5900
Destination: localhost:5900

Now save this session in the putty session box. Upon connecting the cli box will display, and the desktop display will be served up on your local computer. You can’t see it yet silly, to access it we need a viewer. Download and install tightvncviewer (not the server part just the viewer).

http://www.tightvnc.com/download.php

Launch ‘TightVNC Viewer’ and simply type localhost:5900 in and hit connect. Putty must be connected and working for this to work. Once you close putty the connection will close. As with everything here it’s not working quite yet. The pi needs to host a VNC server of the desktop on the pi. If it gives you a rejection, just try again a few times, do a few reboots, maybe shake some cords. For some reason this doesn’t always work right the first, second, or even third time.

BAM! Your mouse should now control the Raspberry Pi’s Monitor.

Stop the monitor from going to sleep 

If you plan on leaving this thing on for extended periods of time, the monitor will likely shut off. It’s a screen saver of sorts, but screen savers aren’t really necessary anymore. Besides we want this to stay on all the time so we can see it right! Edit the lightdm.conf file

sudo nano /etc/lightdm/lightdm.conf

This might make it stop going to sleep

# don’t sleep the screen
xserver-command=X -s 0 dpms

If that isn’t enough sometimes the bit above doesn’t work. You have to edit some other file

sudo nano /etc/kbd/config

Add these, to the end, or un-comment them.

BLANK_TIME=0
POWERDOWN_TIME=0

Oh, reboot to make that all go into effect

sudo reboot

If you’re like me then you can’t seem to figure out why it keeps going to sleep, and you have to take drastic measures. Maybe edit the rc.local file

sudo nano /etc/rc.local

Try addin this line to it before the ‘exit 0’ bit of code.

setterm -blank 0 -powerdown 0 -powersave off

The particular monitor I have has a built-in sleep function that cannot be easily overridden. A hack to move the mouse every so often worked for me. Install xdtool

sudo apt-get install xdotool

edit the cron jobs,

crontab -e

Add this to the end of the file:

*/9 * * * * export DISPLAY=:0; xdotool mousemove 120 100; xdotool mousemove 0 0

via:  http://askubuntu.com/questions/371240/is-there-a-terminal-command-that-will-click-the-mouse

The last bit is to possibly hide the inactive mouse with this program.

sudo apt-get install unclutter

This needs to be run on startup,

cd ~
cd .config
mkdir autostart
cd autostart
sudo nano unclutter.desktop

Paste this in:

[Desktop Entry]
Name=unclutter
Comment=hide inactive mouse
Exec=unclutter &
Icon=computer
Terminal=false
Type=Application
StrtupNotify=false

Reboot and test it all out

sudo reboot

Leave a Reply