Chatting with your Data
by Dominic Cope, on May 17, 2011
Exosite's XMPP chat interface is incredibly easy to work with. In fact, if you know how to chat with someone using an instant messenger app, then you can start chatting with your real time data! We have an XMPP bot (the JID address is commander@m2.exosite.com) that can receive and respond to chat messages.
Here is an example of some basic commands to demonstrate how simple it is to use:
Initialize your chat session
setcik 19cbdefad0b8e90b4d691376d5997f04c1acc18e
Create a new data source to store temperature in Boston
dscreate Boston_Temp Boston_Temp
Store the temperature in Boston
write Boston_Temp 49.6
Check if your plant needs to be watered
read Plant_Soil_Moisture
Response:1305674587,77%
This sequence identifies a device (setcik), creates a new data source (dscreate), and sets the value for the data source (write) and then reads the most recent value from an existing data source (read). The cool part is that you can do this without having any programming knowledge. All you need is a CIK from Exosite Portals and an XMPP account (e.g. myname@jabber.org -> however, even a Google talk account works fine). If you don't already have an XMPP account, these steps can help you get started. Once you are logged in, simply add commander@m2.exosite.com to your contacts, and you can begin interacting with the XMPP API by sending it a chat message.
Try it out for yourself by changing the station code on your weather simulator device. Login to your Exosite Portals account and look at the details of the device called Exosite Device. Copy the device's KEY and send the message "setcik INSERT_YOUR_KEY" to the commander bot. The response should be an "ok" message, which means the command was successful. Weather configuration settings are stored in the simulator_parameters data source. Update this value by sending another message to the commander bot:
write simulator_parameters {"datasource3": {"units": "F", "prefs": "KBOS", "type": "weather", "name": "Boston_Temp"}, "datasource2": {"units": "C", "prefs": "RCSS", "type": "weather", "name": "Taiwan_Temp"}, "datasource1": {"units": "F", "prefs": "KMSP", "type": "weather", "name": "Minneapolis_Temp"}}
The value being saved here is a lengthy string that happens to be a JSON object. I chose to add temperature for Boston, but you can substitute another weather feed by finding the proper code at the NOAA website. Just make sure to add the new code as the "prefs" value and enter a suitable "name" for that part of the JSON object. Refresh your data sources and the simulator_parameters will show the new value. However, even though that value is updated, it could take up to 10 minutes before the new weather data starts reporting.
Now that you know how to manipulate values by using a chat interface, check out the XMPP API documentation to see what else is possible.