Published: September 07, 2015, Edited by: Mads Hobye

IOT: Chat with your Arduino/esp8266 through the XMPP protocol

Internet of things has been around for a couple of years. There are many different ways to connect technology to the internet and the physical world. Among many solutions we tested the old and tried XMPP/Jabber protocol. We hacked together a simple framework to communicate over the protocol.

The solution is based on a heavily hacked version of Adam Rudds example with Arduino and an ethernet shield. We converted his code to run on an esp8266 specifically a NodeMCU version of it. Further, we added a receive method to the library so we also can receive messages from the cloud/user/etc..

This library enables you to use your everyday phone to send/get messages and commands from your "Arduino".

Setup:

  • Install Arduino for Esp - read the guide here: https://github.com/esp8266/Arduino
  • Install the custom libraries in your Arduino library folder from here: https://www.dropbox.com/s/wlk7ko6aj4mhtr7/xmppNodeMcu.zip?dl=1 (this also includes the examples sketches).
  • You need to either find an xmpp server without TLS (secure layer) or setup your own. We used EjabberD on Ubuntu.
  • Create two users: One user for your board and one for you.
  • Change a lot of settings in example sketch "SimpleMessageToDisplayExample"
    • Setup user login for the first user: "if (client.connect("USERNAME", "DOMAIN", "DOMAIN", "PASSWORD"))"
    • Setup wifi password and ssid.
    • Add ip of your xmpp server (use ping in the terminal if you do not know it).
    • Add the second user and the recipient user: USERNAMERECEIVE.
  • Add both users in a XMPP client e.g. Adium.
    • Add each user to each account and make sure to authorize them (this is the only way they can communicate).

At his point you should be able to send messages to your "Arduino" board.

In our example we relay the messages to a display. The keywords "Status" and "Clear" will trigger certain actions (Writing a response and clearing the display):

if (msg == "Status")
{
  client.sendMessage("USERNAMERECEIVE", "I am listening!");
}

if (msg == "Clear")
{
  Serial.write(0x0C);
  Serial.write(0x1B);
  Serial.write(0x12);
  client.sendMessage("USERNAMERECEIVE", "Cleared");
}

There are many libraries to communicate with the xmpp protocol from Nodejs, Processing etc. This enables you to have simple protocol to communicate to your embedded devices.