User avatar
Davespice
Raspberry Pi Foundation Employee & Forum Moderator
Raspberry Pi Foundation Employee & Forum Moderator
Posts: 1618
Joined: Fri Oct 14, 2011 8:06 pm
Location: London, United Kingdom
Contact: Website Twitter

VNC remote desktop via web browser

Sun Jul 06, 2014 4:52 pm

Hi folks;
This is a slight variant on an earlier set of instructions I posted a while ago here.

The basic premise is to use another computer as the input console for the Raspberry Pi without needing to get a separate screen, keyboard and mouse on the Pi. Ideal if you've got a room full of laptops, chrome books or iMacs for example.

This way differs from the previous in that you don't need to install any software on the host computer/laptop. You can set the Raspberry Pi up so that it provides everything the host computer needs through the web browser. It makes it as easy as typing an address in :)

Here is an example of the end product on Windows / IE:
Image

What will it work on?
Any HTML5 compliant web browser. But basically these and above:
  • Chrome 8
  • Firefox 4
  • Safari 5
  • iOS Safari 4.2
  • Opera 11
  • IE 9
Instructions
Best to start with a fresh install of Raspbian and follow these instructions while logged in as the default pi user.
So the aim here is to install the VNC server software as well as a web based HTML5 client onto the Raspberry Pi.
We're first going to need to install a few packages (TightVNC server and screen). Run these commands from the terminal.

Code: Select all

sudo apt-get update
sudo apt-get install tightvncserver screen -y
Next run TightVNC server which will prompt you to enter a password and an optional view-only password.

Code: Select all

tightvncserver
Now let's get the HTML5 VNC client. Enter the following commands.

Code: Select all

cd /usr/local/share/
sudo git clone git://github.com/kanaka/noVNC
We just need to make a small adjustment to some of the files here. The folder we've just downloaded will be served out as a http root for the Pi so we just need to ensure there is an index page. This will allow the host computer to access the VNC client software.

Code: Select all

cd noVNC
sudo cp vnc_auto.html index.html
Then run these commands:

Code: Select all

cd utils
sudo ./launch.sh
You should see the message:

Code: Select all

No installed websockify, attempting to clone websockify...
After a few moments you'll then see this message:

Code: Select all

Navigate to this URL:

    http://blablabla

Press Ctrl-C to exit


WebSocket server settings:
  - Listen on :6080
  - Flash security policy server
  - Web server. Web root: /usr/local/share/noVNC
  - No SSL/TLS support (no cert file)
  - proxying from :6080 to localhost:5900
Press Ctrl - C to stop it, and then press Enter a couple of times to get the command prompt back.

Next we need to set everything to start automatically since you're probably going to want to use the Raspberry Pi in headless mode.
To do this we just need to create a few scripts inside init.d, enter the following commands.

Code: Select all

cd /etc/init.d/
sudo wget https://dl.dropboxusercontent.com/u/14125489/RaspberryPi/vncboot --no-check-certificate
sudo nano vncboot
Note the line that says -geometry 1280x800. This sets the screen resolution for the remote desktop, so you may wish to alter this to suit the screen size of the PC or Mac that you want to control from. Ideally this should be set slightly lower to avoid having scroll bars.
Press Ctrl - O followed by Enter to save, then Ctrl - X to quit from editing.
The script we've just created basically makes VNC part of the background services that Linux is controlling.
We next need to register the script, enter the following commands:

Code: Select all

sudo chmod 755 vncboot
sudo update-rc.d vncboot defaults
Ignore any messages about missing LSB tags and overrides.
That's the server part done. Next we need to setup a similar script for the HTML5 client.

Code: Select all

sudo wget https://dl.dropboxusercontent.com/u/14125489/RaspberryPi/vncproxy --no-check-certificate
sudo chmod 755 vncproxy 
sudo update-rc.d vncproxy defaults 98
Ignore any messages about missing LSB tags and overrides.
Now you should be able to reboot and both services will start up automatically.

Code: Select all

sudo reboot
When the Pi has rebooted you should now be able to enter the IP address of the Raspberry Pi into the web browser of the host computer.
You will be prompted for the password that you specified when setting up the VNC server.

I have occasionally observed an error on the first time that you try to connect, I think this is being caused by the proxy getting started before the VNC server socket is open.
If you see this the top bar goes red. Just hit refresh (F5), enter the password again and it should work.

Master and slave mode
There is another trick you can do here if you want to really have things sown up. I also describe this in the previous post but there are a few differences here.

Using the following instructions each Raspberry Pi will be directly connecting to the host computer using a single Ethernet cable, thus making a completely isolated point to point network between the two and therefore your network administrators shouldn't have any cause to complain. Note: you don't need a cross over cable for this, a standard cable will work because the Pi Ethernet port auto-switches the transmit and receive pins.

Firstly we'll need to install some more software on the Pi. We’re going to make the Pi Ethernet port behave in a similar way to a home router. This means assigning a static IP address to it and installing a DHCP service (dnsmasq) that will respond to address requests from the host computer.

Enter these commands:

Code: Select all

sudo apt-get install dnsmasq -y
It’s a good idea to use an IP address range that is very different to your main network, so let’s use 10.0.0.X. To configure this we must edit the network interfaces file, enter the following command;

Code: Select all

sudo nano /etc/network/interfaces
Find the following line;

Code: Select all

iface eth0 inet dhcp
Add a hash symbol at the start of the line to disable it and then add the other four lines shown below.

Code: Select all

# iface eth0 inet dhcp
auto eth0
iface eth0 inet static
address 10.0.0.1
netmask 255.255.255.0
Press Ctrl - O followed by Enter to save, then Ctrl - X to quit from editing.

The Raspberry Pi will now have a static address of 10.0.0.1

Next we need to configure dnsmasq (that we installed earlier) to give out IP addresses. I am going to explicitly specify a configuration file for the dnsmasq service so let’s first make a backup of the default config file and then save my one in its place.

Code: Select all

cd /etc
sudo mv dnsmasq.conf dnsmasq.default
sudo nano dnsmasq.conf
You should now be editing a blank file. Copy and paste the following into it.

Code: Select all

interface=eth0
dhcp-range=10.0.0.2,10.0.0.250,255.255.255.0,12h
dhcp-option=3,10.0.0.1
dhcp-option=6,10.0.0.1
The first line tells dnsmasq to listen for DHCP requests on the Ethernet port of the Pi. The second line is specifying the range of IP addresses that can be given out. The third and fourth lines tell the host computer what it's default gateway and DNS server settings are.

Next we're going to make a small edit to the hosts file. This will allow the user to type in pi into the browser instead of 10.0.0.1.
Enter the following command to edit the hosts file.

Code: Select all

sudo nano /etc/hosts
Find the line that says 127.0.0.1 raspberrypi and add the following line;

Code: Select all

10.0.0.1        pi
Press Ctrl - O followed by Enter to save, then Ctrl - X to quit from editing.

Next disconnect the Pi from the LAN and reboot.

Code: Select all

sudo reboot
You can go ahead and plug in the single Ethernet cable directly from the Pi to the host computer.
The host computer should then be given an IP address which will be 10.0.0.X where X is a random number between 2 and 250.

One thing to try is to open up a command prompt on the host computer (a Terminal on OSX and Linux) and enter the following command;

Code: Select all

ping 10.0.0.1
If you see reply, reply, reply then it's working. If you see request timed out then something is wrong and you'll need to go back and double check everything.

You should now be able to open up a web browser on the host computer and enter pi into the address bar to get to the VNC client page.

Note: Windows users: This may not work properly on Windows (you'll still need to use 10.0.0.1) but if you install a package called winbind you'll be able to type the Raspberry Pi hostname into the browser. Usually this is raspberrypi. The winbind package can be installed with the command below:

Code: Select all

sudo apt-get install winbind
It should be fine on OSX, Ubuntu and any flavour of Linux though.

Image

You will be prompted for the password that you specified when setting up the VNC server.

I have occasionally observed an error on the first time that you try to connect, I think this is being caused by the proxy getting started before the VNC server socket is open.
If you see this the top bar goes red. Just hit refresh (F5), enter the password again and it should work.

Hope it's helpful!
Dave

User avatar
Davespice
Raspberry Pi Foundation Employee & Forum Moderator
Raspberry Pi Foundation Employee & Forum Moderator
Posts: 1618
Joined: Fri Oct 14, 2011 8:06 pm
Location: London, United Kingdom
Contact: Website Twitter

Re: VNC remote desktop via web browser

Tue Jul 15, 2014 3:19 pm

Folks, some testing at Picademy today revealed an issue with these instructions. It was to do with copying and pasting the init.d scripts. It took me a while to find out why. It was an invalid space character being introduced by the way the forum displays the code inside a code-block. So I've fixed it by providing the raw files that you just download using wget. Instructions above have been updated to include this.

If you had any issues with this it should work fine for you now. Thanks!

User avatar
clive
Raspberry Pi Foundation Employee & Forum Moderator
Raspberry Pi Foundation Employee & Forum Moderator
Posts: 1013
Joined: Tue Feb 07, 2012 8:19 pm

Re: VNC remote desktop via web browser

Wed Jul 16, 2014 11:08 pm

Just a thought Dave -- does copy paste to text editor and out again work (ie nuke bad characters)?

User avatar
Davespice
Raspberry Pi Foundation Employee & Forum Moderator
Raspberry Pi Foundation Employee & Forum Moderator
Posts: 1618
Joined: Fri Oct 14, 2011 8:06 pm
Location: London, United Kingdom
Contact: Website Twitter

Re: VNC remote desktop via web browser

Sat Jul 19, 2014 9:01 am

clive wrote:Just a thought Dave -- does copy paste to text editor and out again work (ie nuke bad characters)?
Yeah it might do. Although I think the issue I mentioned above only occurred using Midori on the Pi itself. Either way the changes I've made to the instructions make it guaranteed repeatable :)

User avatar
r3d4
Posts: 912
Joined: Sat Jul 30, 2011 8:21 am
Location: ./

Re: VNC remote desktop via web browser

Sun Jul 20, 2014 9:27 am

clive wrote:Just a thought Dave -- does copy paste to text editor and out again work (ie nuke bad characters)?
Just FYI

Code: Select all

echo "bad_char_string=$HEAR" | hexdump -cC
Might help identify the undesirable char's. { i could not find any bad'ns, perhaps because i was not using 'Midori on the Pi'; }

Then its possible (with a little more certainty) to
# use sed to replace one char with an-other char

Code: Select all

replace="" # assign  char to $replace variable  
with=""      #assign  alternative  char to $with variable  

echo "bad_char_string=$HEAR" |  sed "s/$replace/$with/g"  
To learn who rules over you, simply find out who you are not allowed to criticize.
.
Real life is, to most , a long second-best, a perpetual compromise between the ideal and the possible.
what about spike milligan??
.

joshebosh
Posts: 3
Joined: Thu Oct 16, 2014 8:34 pm

Re: VNC remote desktop via web browser

Thu Oct 16, 2014 8:48 pm

I followed your instructions precisely and ignored the LSB error as you suggested...
I have an apache2 web server running on port 80... so naturally that what displays when I go to ip address...
but when I go to my raspberry ip address on port 5900, 5901, 5800, 5801, nothing pulls up...
Is this noVNC package designed to run on port 80?
I stopped my apache2 server to see if noVNC would show on port 80...
still didnt see anything...
Do you have suggestions?

User avatar
Davespice
Raspberry Pi Foundation Employee & Forum Moderator
Raspberry Pi Foundation Employee & Forum Moderator
Posts: 1618
Joined: Fri Oct 14, 2011 8:06 pm
Location: London, United Kingdom
Contact: Website Twitter

Re: VNC remote desktop via web browser

Mon Oct 27, 2014 11:23 am

joshebosh wrote:I followed your instructions precisely and ignored the LSB error as you suggested...
I have an apache2 web server running on port 80... so naturally that what displays when I go to ip address...
but when I go to my raspberry ip address on port 5900, 5901, 5800, 5801, nothing pulls up...
Is this noVNC package designed to run on port 80?
I stopped my apache2 server to see if noVNC would show on port 80...
still didnt see anything...
Do you have suggestions?
Hi there, yes it is set up to use port 80. You can change that though. You'll need to edit the vncproxy service script and restart it.

Code: Select all

sudo service vncproxy stop
sudo nano /etc/init.d/vncproxy
Find this line:

Code: Select all

screen -S noVNC -dms noVNC /usr/local/share/noVNC/utils/launch.sh --vnc localhost:5901 --listen 80
Change the --listen 80 to whatever port number you want, say 8080?
Ctrl - O then Enter to save followed by Ctrl - X to quit nano.
Restart the vncproxy service.

Code: Select all

sudo service vncproxy start
Go to your browser and type in the Raspberry Pi IP address with :port where port is the port number you used for --listen and it should work.
For example: 10.0.0.1:8080

User avatar
Davespice
Raspberry Pi Foundation Employee & Forum Moderator
Raspberry Pi Foundation Employee & Forum Moderator
Posts: 1618
Joined: Fri Oct 14, 2011 8:06 pm
Location: London, United Kingdom
Contact: Website Twitter

Re: VNC remote desktop via web browser

Fri Oct 31, 2014 10:50 am

Folks. If you were seeing an issue where the mouse cursor showed as a 1x16 black line, they have now fixed it.
https://github.com/kanaka/noVNC/issues/407

slawekw79
Posts: 31
Joined: Tue Dec 30, 2014 3:36 pm

Re: VNC remote desktop via web browser

Fri Jan 02, 2015 4:14 pm

hi
I have a issue with noVNC. it working on devices connected via WiFi but not via LAN, it show a message "starting VNC handshake". I have no idea why.

User avatar
Cancelor
Posts: 743
Joined: Wed Aug 28, 2013 4:09 pm
Location: UK

Re: VNC remote desktop via web browser

Fri Jan 02, 2015 6:46 pm

Your router is blocking it.
Can't find the thread you want? Try googling : YourSearchHere site:raspberrypi.org

slawekw79
Posts: 31
Joined: Tue Dec 30, 2014 3:36 pm

Re: VNC remote desktop via web browser

Fri Jan 02, 2015 10:09 pm

any idea how to fix it? just don't tell me "change router settings"

User avatar
DougieLawson
Posts: 30137
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: VNC remote desktop via web browser

Fri Jan 02, 2015 10:19 pm

What do you get from the following commands:
ifconfig -a
route -n
cat /etc/network/interfaces
ping -c3 8.8.8.8
ping -c3 google.com
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

Since 2012: 1B*5, 2B*2, B+, A+, Zero*2, 3B*3

Please post ALL technical questions on the forum. Do not send private messages.

slawekw79
Posts: 31
Joined: Tue Dec 30, 2014 3:36 pm

Re: VNC remote desktop via web browser

Fri Jan 02, 2015 10:53 pm

Code: Select all

pi@raspberrypi ~ $ ifconfig -a
eth0      Link encap:Ethernet  HWaddr b8:27:eb:b0:8d:f1  
          inet addr:192.168.1.79  Bcast:192.168.1.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:2677 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2473 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:2179891 (2.0 MiB)  TX bytes:294301 (287.4 KiB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

Code: Select all

pi@raspberrypi ~ $ route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.1.254   0.0.0.0         UG    0      0        0 eth0
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0

Code: Select all

pi@raspberrypi ~ $ cat /etc/network/interfaces
auto lo

iface lo inet loopback
iface eth0 inet dhcp

allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp

Code: Select all

pi@raspberrypi ~ $ ping -c3 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_req=1 ttl=56 time=18.4 ms
64 bytes from 8.8.8.8: icmp_req=2 ttl=56 time=20.2 ms
64 bytes from 8.8.8.8: icmp_req=3 ttl=56 time=18.1 ms

--- 8.8.8.8 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2001ms
rtt min/avg/max/mdev = 18.124/18.941/20.212/0.924 ms

Code: Select all

pi@raspberrypi ~ $ ping -c3 google.com
PING google.com (74.125.230.100) 56(84) bytes of data.
64 bytes from lhr14s24-in-f4.1e100.net (74.125.230.100): icmp_req=1 ttl=56 time=18.1 ms
64 bytes from lhr14s24-in-f4.1e100.net (74.125.230.100): icmp_req=2 ttl=56 time=18.5 ms
64 bytes from lhr14s24-in-f4.1e100.net (74.125.230.100): icmp_req=3 ttl=56 time=18.9 ms

--- google.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 18.113/18.541/18.992/0.359 ms
i hope it help in some way

User avatar
DougieLawson
Posts: 30137
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: VNC remote desktop via web browser

Fri Jan 02, 2015 11:05 pm

So your Raspberry Pi is connected to your network and your network is connected to the outside world. There's no reason why you shouldn't be able to connect a VNC client on another machine to a VNC server running on your RPi.

Have you got vncserver running? What port is it listening on?

pi@raspberrypi:~$ vncserver
Found /usr/share/vnc-java for http connections.

New 'raspberrypi:1 (pi)' desktop is raspberrypi:1

Starting applications specified in /home/pi/.vnc/xstartup
Log file is /home/pi/.vnc/raspberrypi:1.log

pi@raspberrypi:~$

Means it's listening on port 5901 as display raspberrypi:1


Have you defined your home network as "home" & "trusted" on your Windows machines?
http://www.pcadvisor.co.uk/how-to/windo ... -settings/
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

Since 2012: 1B*5, 2B*2, B+, A+, Zero*2, 3B*3

Please post ALL technical questions on the forum. Do not send private messages.

slawekw79
Posts: 31
Joined: Tue Dec 30, 2014 3:36 pm

Re: VNC remote desktop via web browser

Fri Jan 02, 2015 11:38 pm

Yes vncserver is working, i check log files is listening port 5901
My network is set as home and trusted, yes is also confused for me because on devices connected via WiFi is working fine but not via lan.

stlinck
Posts: 1
Joined: Wed Mar 04, 2015 8:59 am

Re: VNC remote desktop via web browser

Wed Mar 04, 2015 9:03 am

I followed the steps however I am not able to get in via the browser. I have found if I manually start the socket I am able to get in. any ideas of what i did wrong?
I ended up running
pi@raspberrypi ~ $ vncserver -kill :1
pi@raspberrypi ~ $ vncserver :1 -geometry 1720x780 -depth 16

andycrofts
Posts: 26
Joined: Tue Aug 14, 2012 12:46 pm
Location: Oulu, Finland
Contact: Website

Re: VNC remote desktop via web browser

Sat Mar 07, 2015 7:30 am

Hmmm....
I get:.....

sudo update-rc.d vncboot defaults
update-rc.d: using dependency based boot sequencing
insserv: warning: script 'K02makeramdisk' missing LSB tags and overrides
insserv: warning: script 'vncboot' missing LSB tags and overrides
insserv: warning: script 'makeramdisk' missing LSB tags and overrides
insserv: There is a loop between service monit and vncboot if stopped
insserv: loop involving service vncboot at depth 2
insserv: loop involving service monit at depth 1
insserv: Stopping vncboot depends on monit and therefore on system facility `$al l' which can not be true!
insserv: exiting now without changing boot order!
update-rc.d: error: insserv rejected the script header

AHappyPandaBear
Posts: 1
Joined: Wed Apr 01, 2015 9:41 am

Re: VNC remote desktop via web browser

Wed Apr 01, 2015 9:44 am

What do i need to change when i installed it on a other path? Now there is just the "Server disconnected (code: 1006)" error

User avatar
PiPete
Posts: 9
Joined: Tue Mar 31, 2015 7:28 pm
Location: Cambridge, UK
Contact: Website

Re: VNC remote desktop via web browser

Thu Apr 02, 2015 8:21 pm

I followed these steps but after I wrote the shell script and then rebooted the pi it is now asking for a password? Any ideas on what this might be? I have used my pi so far with no passwords to write lots of python etc. How can I get back into the Pi?
KS2 Class Teacher

mattmiller
Posts: 1429
Joined: Thu Feb 05, 2015 11:25 pm

Re: VNC remote desktop via web browser

Thu Apr 02, 2015 8:51 pm

Always worth trying raspberry as a pi password

User avatar
PiPete
Posts: 9
Joined: Tue Mar 31, 2015 7:28 pm
Location: Cambridge, UK
Contact: Website

Re: VNC remote desktop via web browser

Fri Apr 03, 2015 9:40 am

I tried but it wont let me in.
I've now rebuilt a card for NOOBS and am back in the Pi.
Just out of interest has anyone got this VNC type of connection working?
KS2 Class Teacher

mariley2250
Posts: 1
Joined: Sun Apr 05, 2015 10:54 pm

Re: VNC remote desktop via web browser

Sun Apr 05, 2015 10:56 pm

I have tried and tried, followed the instructions to a tee every single time. This doesnt work for me. It would be great to get some help for this.

User avatar
PiPete
Posts: 9
Joined: Tue Mar 31, 2015 7:28 pm
Location: Cambridge, UK
Contact: Website

Re: VNC remote desktop via web browser

Tue Apr 07, 2015 2:57 pm

I got vnc to work on my laptop. However, mine craft and scratch do not display through the connection. Python and sonic pi work fine. Any ideas why?
KS2 Class Teacher

User avatar
DougieLawson
Posts: 30137
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: VNC remote desktop via web browser

Tue Apr 07, 2015 4:00 pm

PiPete wrote:I got vnc to work on my laptop. However, mine craft and scratch do not display through the connection. Python and sonic pi work fine. Any ideas why?
They use the framebuffer directly, they aren't using XWindows so can NEVER work on a VNC session.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

Since 2012: 1B*5, 2B*2, B+, A+, Zero*2, 3B*3

Please post ALL technical questions on the forum. Do not send private messages.

User avatar
AndyD
Posts: 2320
Joined: Sat Jan 21, 2012 8:13 am
Location: Melbourne, Australia
Contact: Website

Re: VNC remote desktop via web browser

Tue Apr 07, 2015 10:37 pm

DougieLawson wrote:They use the framebuffer directly, they aren't using XWindows so can NEVER work on a VNC session.
Never, is a very long time :). There is a project (that has been resurrected recently) to use the software interface (called DispmanX) to take snapshots of the Raspberry Pi display and provide VNC functionality. There is a thread here about it. It really is a work in progress, but it works surprisingly well on a Pi 2 (for small display sizes). Although, (to be consistent with this thread) I am not sure if that code provides a web interface.

Return to “Picademy”

Who is online

Users browsing this forum: No registered users and 2 guests