Twitter

This week I’m in Kenya helping run a developer event in partnership with Strathmore University.

In preparing for the Internet of Things workshop I decided to share some more verbose and detailed instructions on setting up Texas Instruments BeagleBone Black and SensorTag with the IBM BlueMix (IBM Codename: BlueMix) Internet of Things service.

Many thanks to Joshua Carr @Josh_schwaa for guiding me in preparing this workshop.

Part 1 – Collecting and visualising sensor data

In this section we’ll collect data from the world around us using a simple device set up that is useful for prototyping an Internet of Things solution. We’ll use a Texas Instruments BeagleBone as a device gateway to collect data from Texas Instruments SensorTags. The tags relay data to the BeagleBones using Bluetooth Low Energy. The BeagleBones then publish this data using a very efficient Internet protocol – MQTT – to distribute this data across the Internet. A set of pre-prepared cloud applications running on IBM BlueMix, capture, analyse and display this sensor data. These cloud applications are supplied ready to deploy in a Boilerplate template called IBM Internet of Things.

1. Power up the BeagleBone and connect to the Internet

Plug the BeagleBone USB cable into your PC. This provides power as well as a direct way to configure the BeagleBone. Share your PC’s network with the BeagleBone.

To connect your machine over USB to the BeagleBone you first need to install some drivers.

Next we want to enable your BeagleBone to use your machine’s Internet connection.

First find your network connections. Go to the Control Panel and search for Network Connections.

Make sure you have your BeagleBone attached with the USB cable. Now identify the network connection that represents the BeagleBone. Typically this shows up as a Local Area Connection followed by a number. I already had two Local Area Connections defined, so the BeagleBone showed up as Local Area Connection 3.

Next I recommend you rename this connection to something more useful. I’ve renamed mine to BeagleBone001 because it’s easier to find and 001 because I’m fortunate enough to have a few. Although I’ll probably configure BeagleBone007 next ;-)

Next identify the network connection you’re using to connect your computer to the Internet. In this case Local Area Connection since I’m using a LAN right now. Choose Wireless Network Connection if you’re on Wi-Fi.

Now right click and get the Properties for the Internet connection you’re using.

Click on the Sharing tab. Check the box to allow other network users to connect through your computer’s Internet connection. A drop down list should appear. Find your BeagleBone entry and click OK. This grants permission to the BeagleBone to proxy through your computer to reach the Internet.

Now something a little odd usually happens. Windows 7 assigns a static IP address to the BeagleBone. We don’t want that. So go into the network Properties for your BeagleBone.

Click on the IP V4 connection and then on Properties.

And change the settings to Obtain and IP address and DNS server address automatically. Save these changes.

2. Install PuTTY and log into the BeagleBone with PuTTY

The BeagleBone communicates with your PC via SSH. There are several SSH clients but I like PuTTY best.

Press next. In “Protocol and ports” choose protocol type “ICMPv4″ then press on “Customize”, then choose “Specific ICMP types”, check the box “echo request” then OK out of the settings. On the previous panel just choose defaults “Any IP address”, press next, “Allow the Connection”, apply the rule to all of Domain, Private and Public, can call it “Beaglebone Ping Rule” and press Finish.

If you’re using Symantec Endpoint Protection I haven’t worked out how to configure it to allow the BeagleBone traffic through. The only solution I know of is to turn it off. It’ll probably turn itself back on every now and again as well, so if you’re network starts dropping check on it.

Now your BeagleBone is connected to the Internet, let’s download the code we need from Github to connect the SensorTag to the BeagleBone and the BeagleBone to the BlueMix Internet of Things cloud.

If you can’t see a light in the Bluetooth LE dongle use these commands to force it to start. You should set a light appear. The light may disappear later which is normal.

hciconfig hci0

downhciconfig hci0 up

If the Bluetooth LE dongle doesn’t respond e.g. you get an error like:

Can't get device info: No such device

Then run this command to get the USB port of the BeagleBone to start:

isusb –v

And run this command to enable the Bluetooth service:

systemctl enable bluetooth.service

If the Bluetooth service still does not find the Bluetooth dongle, try:

rfkill list

sudo rfkill unblock 0

hcitool lescan

6. Find out what the MAC address of your SensorTag is

Navigate to this directory on the BeagleBone:

/iot-beaglebone/samples/nodejs

Run this nodejs program and follow the instructions. You should see the SensorTag’s MAC address appear. This is a unique number that identifies the SensorTag and looks similar to this: 1C:BA:8C:A8:72:1A.

node ibm_iot_sensortag_quickstart.js

If you copy this number from the PuTTY command line make sure the nodejs program doesn’t stop before the next step. If it does, re-start it by running the command again. The SensorTag MAC address won’t change.

7. Use the Internet of Things Cloud to visualize data from your SensorTag

Enter the MAC address of your SensorTag and explore the data it can capture and visualise.

This Web app uses IBM BlueMix and the Internet of Things service to capture, analyse and display the SensorTag data. It uses an open protocol designed for capturing sensor data called MQTT to publish this data from the BeagleBone to the Internet of Things service.

You’ll be able to select from a list of graphs that display the sensor data collected from the SensorTag.

Well done. You have successfully captured a variety of data from the world around you and made this data part of the Internet of Things.

Now let’s learn how to create cloud applications in BlueMix that put this data to work!

IMPORTANT NOTE: How to Power down the BeagleBone

When you’re finished using the BeagleBone don’t pull out the USB cable as this can cause problems. You wouldn’t unplug your computer when you finished using it! Instead either run this command from your PuTTY window:

sudo shutdown -hP now

Or press and hold down the PWR button on the BeagleBone – it’s near the USB port to the right of the RESET button.

Look for the link to Sign up to Twilio. Follow the instructions to set up your trial account. When finished you will be issued with a virtual Twilio number, an account SID and an Authentication Token. You will find these numbers on your Twilio account dashboard.

Back in your BlueMix Node-Red application, configure the Twilio node to use these credentials.

Double click on the Twilio node, and enter your details.

You’ll need to configure a new Twilio service using the Pen icon on the Twilio drop down. Enter the credentials into the screen that appears. You only need to do this once and can re-use this Twilio service definition across other Node-Red Twilio nodes.

If you want to test that the Twilio node is working correctly, add an Inject node and wire it into your Twilio node.

Now configure the Inject node to inject a string and enter the text you want to SMS into the Payload both below.

Now deploy your Node-Red flows. You’ll get warnings about the other nodes we haven’t configured yet – just ignore this. Each time your click on the Inject nodes button (the blue rounded box attached to the left of the Inject node), it should send an SMS to the number you configured in the Inject node message payload.

Ok – So now the SMS is working, let’s use the SensorTag data to send the SMS messages.

To do this we need to add some logic to test the temperature being measured against our threshold. To add this logic we’ll use the Function node. Drag and add a Function node to the canvas. We’ll add some Javascript to this in just a bit.

Our SensorTag is publishing sensor data every 5 milliseconds. We don’t want to send SMS messages that often! Rather than modify the rate the SensorTag publishes data (because other applications may still want the data this frequently) let’s introduce a delay into our flow that ignores all but 1 message every minute. This will limit the frequency of SMS messages that we send to every 60 seconds.

Add the delay node to the canvas.

Let’s configure the delay node now, so that we don’t forget later. If we did forget, Node-Red will attempt to send an SMS message ever 5 milliseconds and this will cause issues!

Edit the delay node and set the rate limit to 1 message per minute. Check the box to drop intermediate messages as we don’t want these.

Next, wire all our nodes together so that the output from the SensorTag subscription feeds into the delay node, then the function node, which in turn feeds the Twilio node. Also wire the debug node so that the function node is also feeding it along with the IoT node.

Your flow will look something like this:

Now let’s use the functionnode to write some Javascript to test the temperature against a threshold.

Edit the function node and paste in this Javascript.

//set the temp thresholds var hotTemp = 28; var warmTemp = 22;

//obtain the current temp of the SensorTag var tagTemp = msg.payload.d.objectTemp;

//convert the temp into a number var tagTempNum = parseFloat(tagTemp);

This function uses msg.payload.d.objectTemp to retrieve the current temperature published by the SensorTag.

msg is the data being inserted into the function node from the IoT node that feeds it.

d.object is the JSON structure used by the nodejs program on the BeagleBone that is publishing the SensorTag data into the BlueMix Internet of Things service.

We convert this string into a number and compare it against our values for hot, warm and cool temperatures (I’m creating this workshop in Africa so the values are much higher than for my native England!)

Finally we set the payload of the message the function node outputs to the string we want to send via SMS. The Twilio node will then use the msg.payload value as the content of the SMS message it sends.

Now deploy your nodes. Remember to also start the nodejs program that publishes the SensorTag data. From your PuTTY window, run the quickstart javascript program.

cd /iot-beaglebone/samples/nodejs

node ibm_iot_sensortag_quickstart.js

Check the debug panel and you should see a steady stream of SensorTag temperature data as before.

However this time you should also get one SMS text to your phone every 60 seconds or so with the current temperature.

Remember to stop the SensorTag data flowing or your phone will fill up with messages, or alternatively remove the wire input to the Twilio node and re-deploy to cease sending texts.

Part 4 – A Challenge

Try to create an Internet of Things application that acts as a motion sensor alarm so that you’ll receive an SMS message wherever the SensorTag is moved.

Remember first to remove the wires from your Temperature flow so that it won’t interfere with the next application.

You can use a nice new canvas for this app. To create another sheet click on the large plus sign at the top right of the canvas.

Hint: msg.payload.d.accelX, msg.payload.d.accelY and msg.payload.d.accelZ data changes when the SensorTag is moved. Take care not to create a flow that sends you hundreds of SMS messages!

Great workshop Ben, successfully connecting data to the Quickstart Data Dashboard and can see all the values. I’m struggling with the new Bluemix service to get the data flowing in Node Red as per the second part?

– Registered the Device and created an API key
– Set up the Device and API in Bluemix IoT J7 service
– Started App and Node Red and set up IoT node with MAC address and debug node and deployed the flow

Who writes this stuff?

I'm a Product Manager based in Nairobi, Kenya focused on software and cloud solutions for Africa. I'm involved in every kind of software including Bluemix, Mobile, Big Data Analytics, Security, Integration and the Internet of Things. Previously based for 16 years in Hursley, UK - the home of CICS, MQ, MQTT and IBM Integration Bus.

Covering my back

The postings on this blog are my own and do not necessarily represent IBM’s positions, strategies or opinions.