# Google Glass talks to Raspberry Pi with XMPP

## What is this project

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.

![](https://cdn-learn.adafruit.com/assets/assets/000/010/417/medium800/projects_Glass_with_Pi_camera.png?1396905243)

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.

# Google Glass talks to Raspberry Pi with XMPP

## What is XMPP and why using it

## **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. ![](https://cdn-learn.adafruit.com/assets/assets/000/010/418/medium800/projects_XMPP_structure.png?1396905289)

## 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.# Google Glass talks to Raspberry Pi with XMPP

## How to bridge Mirror API and XMPP

I modified the python example to add XMPP support and created this website. You can access this on [https://bareboneglass.appspot.com/](https://bareboneglass.appspot.com/) and it's source code is on [https://github.com/DeqingSun/bare\_glass\_app](https://github.com/DeqingSun/bare_glass_app).

![](https://cdn-learn.adafruit.com/assets/assets/000/010/476/medium800/projects_barebone_glass_page.png?1396906567)

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/](http://xmpp.net/ "Link: 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](http://psi-im.org/ "Link: http://psi-im.org/"). 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 "bareboneglass@appspot.com". 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.

# Google Glass talks to Raspberry Pi with XMPP

## Set XMPP on Raspberry Pi

![](https://cdn-learn.adafruit.com/assets/assets/000/010/477/medium800/projects_Pi_glass.png?1396906602)

I used python with xmpppy library to send and receive XMPP messages. The [example](https://github.com/DeqingSun/bare_glass_app/blob/master/code_for_other_devices/raspberry_pi_script/xtalk_cp.py "Link: https://github.com/DeqingSun/bare\_glass\_app/blob/master/code\_for\_other\_devices/raspberry\_pi\_script/xtalk\_cp.py") 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](http://xmpppy-guide.berlios.de/nightly/a_practical_guide_to_xmpppy.pdf "Link: http://xmpppy-guide.berlios.de/nightly/a\_practical\_guide\_to\_xmpppy.pdf") is a good start.

# Google Glass talks to Raspberry Pi with XMPP

## Take a picture with Raspberry Pi

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](https://bareboneglass.appspot.com/upload "Link: https://bareboneglass.appspot.com/upload") .   
  
You can change this line to your own XMPP address and customized message with image.  
payload = {'xmpp\_addr': 'remotedev@wtfismyip.com/pi', 'msg': 'Photo from Pi'}

![](https://cdn-learn.adafruit.com/assets/assets/000/010/478/medium800/projects_Glass_with_Pi_camera.png?1396906642)


## Related Guides

- [Motion Controlled Matrix Bed Clock](https://learn.adafruit.com/motion-controlled-matrix-bed-clock.md)
- [CircuitPython Libraries on Linux and the NVIDIA Jetson Nano](https://learn.adafruit.com/circuitpython-libraries-on-linux-and-the-nvidia-jetson-nano.md)
- [CircuitPython Libraries on Linux and ODROID C2](https://learn.adafruit.com/circuitpython-libaries-linux-odroid-c2.md)
- [CircuitPython Libraries on Linux and the 96Boards DragonBoard 410c](https://learn.adafruit.com/circuitpython-libraries-on-linux-and-the-96boards-dragonboard-410c.md)
- [Turning your Raspberry Pi Zero into a USB Gadget](https://learn.adafruit.com/turning-your-raspberry-pi-zero-into-a-usb-gadget.md)
- [CircuitPython Libraries on Linux and Raspberry Pi](https://learn.adafruit.com/circuitpython-on-raspberrypi-linux.md)
- [Use Docker to Compile Linux for ESP32-S3](https://learn.adafruit.com/docker-esp32-s3-linux.md)
- [Adafruit ATtiny Breakouts with seesaw](https://learn.adafruit.com/adafruit-attiny817-seesaw.md)
- [Circuit Playground Express Serial Communications](https://learn.adafruit.com/circuit-playground-express-serial-communications.md)
- [Hacking Yoto Music Players](https://learn.adafruit.com/hacking-the-yoto-music-players.md)
- [Adding a Single Board Computer to PlatformDetect for Blinka](https://learn.adafruit.com/adding-a-single-board-computer-to-platformdetect-for-blinka.md)
- [CircuitPython Libraries on Linux and Google Coral](https://learn.adafruit.com/circuitpython-on-google-coral-linux-blinka.md)
- [Adafruit CH9328 UART to HID Keyboard Breakout](https://learn.adafruit.com/adafruit-ch9328-uart-to-hid-keyboard-breakout.md)
- [CircuitPython Libraries on Linux and Orange Pi](https://learn.adafruit.com/circuitpython-on-orangepi-linux.md)
- [Adding a Single Board Computer to Blinka](https://learn.adafruit.com/adding-a-single-board-computer-to-blinka.md)
