Creating desktop icons

Create desktop icons to start the smart mirror software.

In this article I’ll be describing a way to quickly start the applications with a shortcut on the desktop.  For a good working smart mirror I will need to start at least the following applications :

  • The smart mirror software itself
  • The Java Client
  • The Wake word agent

In order to avoid hooking up a keyboard every time I want to start them, I will create desktop icons.  That way I’ll only have to connect a mouse to start the applications.

Turns out that’s quite easy.

Log on to the Raspberry Pi with ssh, or take over the screen using VNC, and open a terminal on the desktop.

Next, navigate to the Desktop directory :

cd Desktop

Create a new file called client.desktop :

nano client.desktop

This will automatically open the nano editor.  There is a fixed format in which these files are structure.  First of all, it needs to start with [Desktop Entry], and the settings are key value pairs separated with an equals sign.  The settings to start the java client are as follows :

[Desktop Entry]
Exec=mvn exec:exec

A few settings are important :

  • Always use “Application” as the Type.
  • Set a path.  It is the working directory for the application where it can find its configuration files etc.
  • Set Terminal=false to avoid starting a terminal every time.

More info on the other settings can be found here.

I’ve pasted the settings for the smart mirror and the wake word engine below.

[Desktop Entry]
Exec=npm start
[Desktop Entry]
Exec=lxterminal -e "/home/pi/smartmirrorproject/"

Notice above how the “Exec” value is configured.  For the wake word engine a script is started instead of an executable.  In order to show its progress in a terminal I chose to start is as a command with inside a terminal by using the lxterminal command.

The result looks like this :

Schermafbeelding 2017-01-14 om 20.11.33.png


Setting up a static IP

Setting up a static IP address for your Raspberry Pi.

When connecting to the Pi via the network, by default, DHCP is enabled.  This way it is possible for your Pi to change IP address from time to time.

That’s annoying when creating bookmarks, and having to find out the address time and again.

That’s why I’m going to setup a static IP for my Pi now.

Just connect to the Pi using ssh and type

sudo ifconfig

This outputs some text where you can find your wireless adapter (probably called wlan0) .

Take a piece of paper and note down

  • The current address (inet addr)
  • Broadcast range (bcast)
  • Subnet Mask (mask)

after that, type the command

sudo route -n

Note down the address of the gateway (second column) and the destination (first column).

Next, we need to adjust a configuration file, for the Pi to read when booting.

Do this the following way :

sudo nano /etc/network/interfaces

This starts the nano text editor, while editing an existing file called “interfaces”.

Somewhere in the file you should find something like

iface wlan0 inet manual

change it to

iface wlan0 inet static

and type the following below it

address [your chosen fixed IP address]
netmask [your netmask]
network [your destination]
broadcast [your broadcast range]
gateway [your gateway]

Lastly, reboot your Pi

sudo reboot

That should do the trick.

Connecting to the Pi

My first steps connecting to the Raspberry Pi.

In the package I bought, there was an SD card included containing the Raspbian operating system.  This is a linux distribution especially created for the Raspberry Pi.  It already contains quite some applications in a graphic user interface.

The fact that it comes with the package is handy, but for those who don’t have that privilege, there are some great tutorials out there that explain how to format any micro SD card and install Raspbian on it.  It’s really straight forward, so it shouldn’t pose any problems.

The first thing we’ll be doing is configuring “ssh”.  “ssh” is short for “secure shell”.  A tool that lets you connect to the terminal of another computer remotely.

In order to do so, we need to make sure, the Raspberry Pi is correctly configured to accept such “ssh” connections.

While you’re logged into the user interface of your Pi, go to the menu in the top left corner, choose Preferences, and choose “Raspberry Pi Configuration”.

In the dialog that follows, make sure the “SSH” interface is enabled in the “Interfaces” tab.

If you own a windows computer, connecting to the Pi can be done using a tool called “putty”.  You can find it here.

I happened to own a mac, and with mac you can do it simply via the terminal.  And that’s what I will do.

Open a terminal.

In order to connect to the Pi we need its IP address.  The IP address is the address on the network assigned to a network card through which a computer can be addressed.  By default the Pi is configured to automatically obtain an IP address from your router using a protocol called DHCP (short for Dynamic Host Control Protocol).  In short (very short), your Pi will get a random IP address.  If you’re not into networking, go ahead and search on google for more information on that.

Anyhow.  How to obtain the network address of the Pi.  This is quite simple.  By default the Pi is given a name through which it can be pinged on the network : “raspberry.local”.  In order to get the IP address just type the following command in the terminal :

ping raspberry.local

If all is well, you should be seeing some output like this.  However, the output will keep on coming.  Press ctrl-c to stop the output.

Schermafbeelding 2017-01-06 om 20.26.24.png

“ping” is a tool to check if a network card can be found on the network.  You can see some stats, but most importantly, you can see the network address.  It’s

Armed with this knowledge, we can start the “ssh” tool using the following command :

ssh pi@

the “pi@” prefix of the IP address denotes the user (“pi”) that’s used to connect.  After pressing enter, the “ssh” tool will prompt you for a password.  The default is “raspberry”.  Mind the lower case.

That should do it.  After you log on remotely, the prompt will change to something like this :

Schermafbeelding 2017-01-06 om 20.30.20.png