Ship IoT with ARM mbed, FRDM-K64F, and bip.io
Last October, at ARM TechCon, we showed a demo of a NXP LPC1768 connected to a WS2812 24 color RGB LED. The hardware was programed using ARM mbed Development Platform and connected to the mbed Device Server. We used the wot operating environment to seamlessly integrate the data coming off the devices to a search engine, an analytics package, and a business intelligence platform.
In this tutorial, we are simply going to cover the basics of developing an application with the mbed compiler and a Freescale FRDM-K64F. We will connect the on board Freescale FXOS8700CQ 6 axis accelerometer and magnetometer up to a bip.io workflow.
Prerequisites
In order to follow along with this tutorial you will need:
- an mbed Developer account
- a Ship IoT bip.io account
- a FRDM-K64F board
- an ethernet cable and a micro-USB cable
The cost of the board is around $35, and you probably have spare cables lying around. For my setup, I used Internet Sharing on my Macbook Pro, to connect the FRDM-K64F to the Internet. Optionally, you can wire your board to your switch, and it will receive a DHCP lease as part of the startup sequence.
The code for this tutorial can be imported directly from the public mbed repository.
Configuring your workflow
I am going to reuse a workflow from a prior tutorial so if you have already done the Photon tutorial, this will feel like old hat. If you haven't then first go to ShipIoT.net and sign in. You will then need to Create A Bip
to create a new blank canvas:
You can then click on the central circle to Select Event Source
:
Here we will select Incoming Web Hook
to create a HTTP endpoint to which our FRDM-K64F will send it's data. This is the staring point of our workflow. Once you select that you will be presented with a icon in the center:
Above the central canvas you'll see a URL in which we want to replace the Unlisted
with a proper path. For this workflow, we'll name it accel
which should produce a URL of the form:
http://<your_username>.api.shipiot.net/bip/http/accel
You can view this URL by clicking on the Hide/Show link icon next to the URL. The next step will be to add a Data Visualization
element to the workflow, so that we can chart the values coming from the accelerometer. If you click on Add An Action
you will be presented with a options panel:
If you click on Data Visualization
option, you will be presented with a list of actions.
Here we want to select View Chart
to create a graphical chart of the incoming web hook data. On the main canvas, we then can connect the Incoming Web Hook
icon to the Data Visualization
icon by dragging from one to the other:
This will link the incoming data to the chart. To configure the parsing options, we'll open the Parser
tab and create some representative JSON in the left hand panel:
{ "x": 0, "y": 0, "z": 0}
and then click the Parse
button to generate the associated JSON schema. We can then return to the Setup
tab and double click on the Data Visualization
icon to open up it's settings.
First we can set the X axis value to the time that the FRDM-K64F sent the request by setting it to a custom value of Invoke Time
:
We can then set the Y1 and Y2 values to the values X and Y respectively:
Clicking OK
will then save these settings. Opening the settings a second time will present us with a Chart
tab:
This will display the data as it comes in off of the webhook. The last thing we need to do is set the authorization settings on the URL. For our purposes we'll use HTTP Basic Authorization with a username and password of test
.
The important thing here is to gab a copy of the HTTP Request Header
. We will need to modify the source of the program to use this value to authenticate against the server. Feel free to use any username and password you'd like. Finally click Save
and your workflow will be running.
Developing the ARM mbed Application
As a picture is worth a 1000 words, a 15:48 @ 30fps video is worth 28,440 pictures:
In this video, I cover writing the application, and demonstrate the charting interface of the workflow we created above. If you don't feel like watching the video, just import the code into your mbed Developer account, and edit the three lines commented in the source to reflect your username and authentication choices.
You can then compile, download, and flash your FRDM-K64F board, and everything should just work! If it doesn't odds are good that it is a networking issue. Should your device not be able to acquire an IP address, you won't see the debug messages on the serial console. Similarly, should the webhook not work, you can check the Logs
tab for reasons. Often it is merely a copy/paste bug regarding the authentication token.
Once you have it working, you can extend your workflow to perform additional actions. You can save your data to a Google Spreadsheet, or have it send a tweet to Twitter, or even control your Nest thermostat, or all of the above.