This project enables Google Glass to talks to a hardware platform, raspberry Pi, with Mirror API and XMPP protocol. So users can access physical stuff with their Google Glass via voice commands.

Who can benefit from this tutorial:

You have a Glass and you want to connect it to Rapsberry Pi
You have a Glass and you want to connect it to other platforms that can support XMPP by Python or other languages.
You have a Rapsberry Pi and you want it to talk to another device or Website.
You are interested in this topic.

What is XMPP

Extensible Messaging and Presence Protocol (XMPP) is a communications protocol for message-oriented middleware based on XML (Extensible Markup Language). The protocol was originally named Jabber, and was developed by the Jabber open-source community in 1999 for near real-time, instant messaging (IM), presence information, and contact list maintenance.

What is the problem if we don't use XMPP

In most cases the Raspberry Pi does not have a public IP address. The Raspberry Pi can initiate a connection to web servers that have public IP addresses. But those servers can not initiate a connection to Raspberry Pi. That means servers can not send any information to Raspberry Pi until Raspberry Pi start the connection. So the latency of messages from servers can not be guaranteed.

In order to minimize that latency, our Raspberry Pi can either inquire the server periodically or keep the connection alive. The first option is not efficient and the second option is not supported in free web services such as App Engine.

How XMPP solve this problem

There are many free XMPP servers on Internet and those servers can keep a long-lived TCP connection with our Raspberry Pi. Since all XMPP servers have public IP address, they can exchange messages freely. This method can eliminate the unnecessary latency introduced by polling intervals.
I modified the python example to add XMPP support and created this website. You can access this on https://bareboneglass.appspot.com/ and it's source code is on https://github.com/DeqingSun/bare_glass_app.
It's quite similar to the python example. When you click "Add a card you can pin and reply", a card will be inserted into your timeline and that card has an option to reply. Also you can pin that card for easier access. You can also add your XMPP address to server by typing your address in the text field and press "Add XMPP address". If you don't have one, you can find a provider on http://xmpp.net/ and register an address.
Before you write any code, you can try this service by logging in your XMPP account on your computer with a client like Psi. All messages replied to that card will be forwarded to your XMPP address and you should see that on your computer. On your computer side, you can send messages to "[email protected]". You can send "/echo something" to test if this service is working or send "/push some message" to send a message into your timetime for you to view on your Glass.
I used python with xmpppy library to send and receive XMPP messages. The example code in my repository can send back Raspberry Pi's CPU temperature if you reply to the card with a message that includes "temperature". The only thing you need to change is the XMPP address and password.
If you want to know more about the xmpppy library. a_practical_guide_to_xmpppy.pdf is a good start.
If you have a webcam you can try to connect it to Raspberry Pi and let it to take pictures for your glass.
I used fswebcam to take pictures and compress it to jpg format. And then requests library was used to send the image and other information in POST method to https://bareboneglass.appspot.com/upload .

You can change this line to your own XMPP address and customized message with image.
payload = {'xmpp_addr': '[email protected]/pi', 'msg': 'Photo from Pi'}

This guide was first published on Aug 15, 2013. It was last updated on Jul 31, 2013.