This is a guest post from one of 43oh's forum members, Dennis Tong a.k.a Pine. Pine is best known for making good of what he has available.
From the recent email received from TI announcing their new Connected LaunchPad line, I noticed the free partner service they offered to Exosite – a cloud platform focused on collecting and visualizing data from IoT devices. It is really cool for us hobbyists to have services of this kind, easy to configure yet providing such a sophisticated communication platform. How could I miss the opportunities to explore these exciting features!
Below is an overview of what we will be trying to accomplish. A temperature sensor connected to the Launchpad, relays information to a OpenWRT enabled router serially, which then pushes information online. This published information can then be viewed anywhere on a PC, Tablet or Phone.
1. Device Registration
The first thing you do is register a free account at the TI Exosite page. After registration, some basic configuration tasks are required to be completed before Exosite will accept data sent from your test rig.
These configurations include adding a device (the LaunchPad), configuring the data to capture, and most importantly, creating a “widget” to display the data captured. The flow to prepare the cloud service at Exosite is pretty straight forward and user friendly, and the user interface is consistent across different areas of configuration.
Before moving on to the micro-controller section of this voyage, you have to write down a piece of information provided from Exosite after your device is registered. This piece of information is known as CIK, assigned by Exosite, and is always displayed under the Device Information page. It is kind of a key used for identification. Exosite needs this CIK to associate the data they receive to the corresponding account, and that means we have to put it in the HTTP request to Exosite while sending data.
2. Preparing The Embedded Side
In my settings for this test, I planned to deploy a temperature measuring sensor, have the data captured and sent to Exosite for storage and visualization. Although my test rig enlisted three components, any Launchpad with an internal temperature sensor with a working serial port, like the classic MSP430G2553 line, should suffice. Of course, it doesn’t have to be temperature - what the IoT can serve is only limited by your imagination.
To achieve this design goal, an MSP430F5529 USB LaunchPad with TI TMP006 temperature booster pack was selected as the test rig. This test rig was originally a small project from last month and includes also a 3.3V compatible 1602 LCD. As mentioned this is optional for testing connectivity with Exosite.
Unlike the new Connected Line LaunchPad just released by TI with built-in IoT support, most notably the Integrated 10/100 Ethernet MAC+PHY, my plain vanilla MSP430F5529LP, without Ethernet BoosterPacks like the Ethernet Booster Pack by Rob at the 43oh Store or the CC3000, is just sitting there and silently capturing temperature data without anyone on the Internet hearing about it.
3. Bringing It Together
Having the data capture device and the cloud platform ready, the question remains is how are they going to connect together?
Some months earlier I got my feet wet in OpenWRT and flashed an “Attitude Adjustment” firmware to a TP-Link NR-703N WiFi router. The good thing about this little router, beside the internet connectivity and cuteness for obvious reasons, is the provision of USB host and together with the OpenWRT firmware. This allows me to serial connect the MSP430 LaunchPad via USB. Currently this router is configured as client mode and talks to my broadband router, or mobile phone when I’m on the go.
The next part is to prepare the test rig. The software for the F5529LP is done in Energia. Kind souls from the 43oh forum helped me out by giving advice on library porting as well as guidance to arrive the desired code. Although the LCD shows a lot of info in the original project (including sensor temperature and die temperature, together with their min/max), the data output from serial is currently limited to the TMP006 sensor current temperature only, and this value is registered on Exosite as parameter “s”. The attached Lua code later will demonstrate how this “s” argument is to be sent to Exosite. All in all, the critical part of the programming for the MCU is to capture the temperature value, and send the data through serial by the following line of Energia code (objt is the variable storing the temperature value):
The completed and programmed F5529+TMP006+LCD package is then connected to a TP-Link WR703N wireless router with OpenWRT. The Energia code is programmed such that every 4 seconds the LaunchPad sends the sensor temperature through serial to the OpenWRT. This router is installed with ser2net package and a Lua program is written to loop and capture that value, and construct an HTTP request conforming to Exosite’s standard.
Remember that CIK value mentioned earlier? This value is required in the call as well. The HTTP request crafted will finally be send to m2.exosite.com. The details of the protocol is available at github.
Yes, that is a Haagen Dazs behind the LaunchPad... to make sure the temperature goes below 0 Degree C. I get desert tonight 🙂
For the 703N router, the package ser2net is required to relay the serial data to a TCP port (installed by command opkg update and then opkg install ser2net). Given that the serial communication between OpenWRT and MSP430 LaunchPads worked pretty much out of the box at device port /dev/ttyACM1, the configuration of ser2net is easy enough by modifying the configuration file at /etc/ser2net.conf as below (meaning that fetch data from /dev/ttyACM1 at 9600 bps to port 2002)
2002:raw:600:/dev/ttyACM1:9600 NONE 1STOPBIT 8DATABITS XONXOFF LOCAL -RTSCTS
Finally, a small lua program is used to capture the output from ser2net, do some legwork, and finally send data to Exosite. Lua is installed by default on the OpenWRT firmware and after some research it seems capable of doing what this exercise needed.[WordPress seems to be parsing some of the code below, especially rn, please download the raw text file from here]
tcp:connect(host, port); while true do local s, status, partial = tcp:receive() print(s or partial) if status == "closed" then break end local socket = require("socket") local host = "m2.exosite.com" local sock = assert(socket.connect(host, 80)) sock:send("POST /api:v1/stack/alias HTTP/1.1rn") sock:send("Host: m2.exosite.comrn") sock:send("Content-Type: application/x-www-form-urlencoded; charset=utf-8rn") sock:send("X-Exosite-CIK: [SECRET_CIK_HERE]rnrn") sock:send("Content-Length: 8rn") sock:send("s=") sock:send(s) sock:send("rnrnrn") repeat local chunk, status, partial = sock:receive(122) print(chunk or partial) until status ~= "closed" sock:close() end tcp:close()
The whole Exosite experience is pretty nice. It only takes less than half hour from opening a new account to have the site ready to receive data, which already include reading the documentation on how to send data with their simple HTTP protocol.
It is quite an enjoyable experience to have little things connected to the Internet 🙂
If you have any questions or comments, let us know in the comments below or in this forum project thread.