2

When remotely accessing my Pi via tightvnc my program won't run if the tightvncserver has been started automatically at boot.

I've run the Raspbian install from the latest noobs on a R Pi 2 with a newly formatted disc..

I've installed tightvncserver and remotely access the Pi from a PC.

When I start tightvncserver manually everything is fine and I can run my program from the PC without problems

However when I run tightvncserver at boot I get an error message when I run my program from the PC (see error message below).

To make tightvncserver run at boot I've modified /etc/rc.local by adding the following line.

su - pi -c '/usr/bin/tightvncserver :1`

What do I need to do?

I've searched the web and found different ways of auto running tightvncserver but this seened the easiest.

Error message

Client is not authorized to connect to ServerClient is not authorized 
to connect to ServerTraceback (most recent call last):
  File "templight15.py", line 427, in <module>
    root = Tk()   
  File "/usr/lib/python2.7/lib-tk/Tkinter.py", 
line 1813, in __init__
    self.tk = _tkinter.create(screenName, baseName, className, 
interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: couldn't connect to display ":1.0"
pi@raspberrypi2:~ $ 
1

What you are trying will not work.

If you are running Jessie this should be started with a systemd service. I copied from https://www.raspberrypi.org/forums/viewtopic.php?t=123457&p=830506

If you are still running Wheezy there are instructions for init.d (which may still work).

Create a new file /etc/systemd/system/vncserver@.service with the following contents:

[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target

[Service]
Type=forking
User=pi
PAMName=login
PIDFile=/home/pi/.vnc/%H:%i.pid
ExecStartPre=-/usr/bin/vncserver -kill :%i > /dev/null 2>&1
ExecStart=/usr/bin/vncserver -depth 24 -geometry 1280x800 :%i
ExecStop=/usr/bin/vncserver -kill :%i

[Install]
WantedBy=multi-user.target

Make executable

sudo chmod +x  /etc/systemd/system/vncserver@.service

You can test with

sudo systemctl start vncserver@1.service

Enable with

sudo systemctl daemon-reload && sudo systemctl enable vncserver@1.service
  • [Unit] Description=Remote desktop service (VNC) After=syslog.target network.target [Service] Type=forking User=pi PAMName=login PIDFile=/home/pi/.vnc/%H:%i.pid ExecStartPre=-/usr/bin/vncserver -kill :%i > /dev/null 2>&1 ExecStart=/usr/bin/vncserver -depth 24 -geometry 1280x800 :%i ExecStop=/usr/bin/vncserver -kill :%i [Install] WantedBy=multi-user.target – Steverat Dec 8 '15 at 19:56
0

Many thanks for your reply.

The R pi 2 now boots up with tightvncserver running and I can access it from my PC.

When I enter the ls command I cannot see my programs listed.

This is what I get

pi@raspberrypi2:/ $ ls bin dev home lost+found mnt proc run srv tmp var boot etc lib media opt root sbin sys usr pi@raspberrypi2:/ $

If I enter “cd home” and then “ls” I get the following.

pi@raspberrypi2:/home $ ls pi

Then I enter “cd pi” and get

pi@raspberrypi2:/home $ cd pi pi@raspberrypi2:~ $ ls Desktop light.py Public templight15.log Tight Documents Music python_games templight15.py Videos Downloads Pictures Templates Testing I2C.txt w1probes1.py pi@raspberrypi2:~ $

My programs are here.

Running “ templight15” produces the same error message as before.

pi@raspberrypi2:~ $ sudo python templight15.py

Importing all kinds of stuff

Finished importing stuff

Client is not authorized to connect to ServerClient is not authorized to connect to ServerTraceback (most recent call last): File "templight15.py", line 427, in root = Tk()
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1813, in init self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use) _tkinter.TclError: couldn't connect to display ":1.0" pi@raspberrypi2:~ $

Have I missed something?

Cheers

Steve

  • This seems to have nothing to do with VNC and is totally incomprensible (at least to me). – Milliways Dec 8 '15 at 22:52
  • HiI'm using tightvncserver. – Steverat Dec 9 '15 at 12:06
  • I'm learning how to use this exchange site and somehow managed to post some code by mistake. Sorry. – Steverat Dec 9 '15 at 12:11
  • I can run a python program on the R Pi. I can run the same program via vnc from my PC if I start tightvncserver manually on the R Pi. However I cannot run the same program via vnc if I get the R pi to start tightvncserver automatically at boot. – Steverat Dec 9 '15 at 12:17
  • I hope this is a little clearer. The problem started after running the latest noobs. All suggestions greatly received. – Steverat Dec 9 '15 at 12:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.