Connecting Devices to the Internet of Things Bernard Kufluk, MessageSight Product Manager
Jun 27, 2015
Connecting Devices to the Internet of Things
Bernard Kufluk, MessageSight Product Manager
© 2014 IBM Corporation
Please NoteIBM’s statements regarding its plans, directions, and intent are subject to change or withdrawal without notice at IBM’s sole discretion. Information regarding potential future products is intended to outline our general product direction and it should not be relied on in making a purchasing decision.
The information mentioned regarding potential future products is not a commitment, promise, or legal obligation to deliver any material, code or functionality. Information about potential future products may not be incorporated into any contract. The development, release, and timing of any future features or functionality described for our products remains at our sole discretion
Performance is based on measurements and projections using standard IBM benchmarks in a controlled environment. The actual throughput or performance that any user will experience will vary depending upon many factors, including considerations such as the amount of multiprogramming in the user’s job stream, the I/O configuration, the storage configuration, and the workload processed. Therefore, no assurance can be given that an individual user will achieve results similar to those stated here.
2
Agenda
• The Internet of Things and its Ecosystem
• The IBM IoT Foundation and the IoT Foundation Quickstart
• Quickstart device recipes and demonstration
• How is Quickstart implemented?
• Writing your own device code
• Signing up and registering a device
3
The Internet of Things and its Ecosystem
The Internet of Things is the next Internet Frontier
Source:http://www.digitalcommunities.com/articles/FutureStructure-The-New-Framework-for-Communities.html
How Many Things ?•IoT 2020 View
What is the IoT being used for today?
Extend the value of goods and services, e.g. Lock/Unlock/Find your car
Tell me when my washing is doneHow well am I cleaning my teeth?
Monetize through new business modelsAd-hoc care hirePay-as-you-drive insurance
Optimize by understanding behaviour and anticipating most optimal actions
White goods manufacturer understanding customer behaviour
Improved product support and maintenanceSmarter Supply Chain
Control remote behaviour with automationHome automation / remote controlEnergy Demand ManagementSmarter CitiesManufacturing
Key areasAgriculture AutomotiveConsumer productsEnergy and UtilitiesGovernmentHealthcareHome AutomationInsuranceManufacturingTransportOil and Gas
Consumers lead the Internet of thingsToday Tomorrow Integration
A few connected devices per
person…
Almost every device that consumers own will be connected, and many new ones will be created to leverage the value created by
consumer connections.
Cross-platform integrators will
connected devices and automate
personal activity:Door Lock
Dishwasher
Clothes Washer
Clothes Dryer
Window Lock
Garage Door
Toothbrush
Garden Moisture
Coffee Maker
Home Lights
Examples:
Ifttt.comZapier.com
Just as consumers have led enterprises in embracing new mobile services, we believe they will lead the adoption of connected devices & integrated services
Ecosystem & Partners are crucial
Solutions & Applications
SmarterCities
Transport& Rail
Energy & Utilities
ConsumerElectronics
Life Science& Healthcare
Oil & Gas
ConnectedVehicle
IndustrialManufacturing
Devices Gateways CloudsNetworks
IBM IndustrySolutions
IBM SWG
MessageSight
Streams
SDK SDK Partnerships
MaximoIoC
IoT use cases have many common requirements
Core Requirements: Easily on-board connected “things” Create a real-time communication channel with the “thing” Begin capturing data from the “thing” Visualize data from the “thing” Collect data in a historian DB Provide access to the collected data Manage the “things” and the connectivity to them Secure the data from the “thing” and control access to that that data Pay for the service based on usage
Extended Requirements: Perform analytics both in real-time and on historical trend data Trigger events based on specific data conditions Interact with the “thing” from business apps and/or from mobile devices Send commands to the “thing”
IBM Internet of Things Foundation and Quickstart
IBM Internet of Things Foundation
Secure + Connect(Messaging)
Secure + Connect(Messaging)
Collect Data(Historian)
Collect Data(Historian)
Manage Connections(IoTF Portal)
Manage Connections(IoTF Portal)
22 Assemble Assemble
Analytics Analytics
IBM IoT FoundationIBM IoT Foundation
IBM BluemixIBM Bluemix
Mobile Mobile
1. Management API2. Real-time data API3. Historical data API
1. Management API2. Real-time data API3. Historical data API
1133
IBM Internet of Things Foundation Quickstart
Key Capabilities:• Extremely rapid device onboarding• Real-time collection of data from devices• Visualization of data from devices• Communications api to allow custom devices to be added• Access to data for Bluemix applications via the IoT Service
What Users Can Do:Connect devices, collect, route, and visualize dataBuild internet of things applications to analyze dataCustomize and add further devices
Note: IoT Foundation Quickstart is a tool to let embedded device developers connect to the IoT and see data from their device, and to provide data for IoT application developers to use. It is not intended for production use.
It is a free service, there is no device or user registration step, and all data sent to the Quickstart service could potentially be viewed by any internet user.
Platformas a Service
Try our IoT Foundation Quickstart …
14
What You Can Do with Quickstart
• Simply connect & “recognize” device types• Visualize real-time data stream
• Visually define logic flowsusing Node-RED
• Mix with other services in BlueMix• Build applications that incorporate IoT
• Select from a growing list of device recipes
Quickstart Device Recipes
Simple Connection for Internet of Things
Unpack device and connect it to the InternetUnpack device and connect it to the Internet
Install software* on the deviceInstall software* on the device
Start collecting and visualizing dataStart collecting and visualizing data
* We provide source code samples for a variety of devices on
https://github.com/ibm-messaging
with Wi-Fi Shield
Quickstart comes with recipes and code for the following
The parts of each Recipe
• Ingredients– The hardware that you need
• Preparation– Unpacking the device, installing the OS if necessary, connecting
it to your Computer, etc.
• Connecting– Installing the QuickStart software and starting it up
• Visualization– Type in your device’s MAC address and see the results
ARM mbed
New - ARM mbed starter kit for IBM IoT Cloud
https://mbed.org/blog/entry/IBM-teams-up-with-mbed-for-IoT-kit/
Visualizing the results
http://quickstart.internetofthings.ibmcloud.com/?deviceId=aabbccddeeffgghh
Chart View
Raspberry Pi
Node-Red running in the device
This shows the Sensor Tag device application logic implemented in Node-Red
Writing your own Device Code
Quickstart - how is it implemented?
MQTT Server infrastructure (based on IBM MessageSight)
MQTT Server infrastructure (based on IBM MessageSight)
Bluemixapplications
Bluemixapplications
Softlayer cloud
MQTT MQTT
Embedded device appC, C++ or JavaScript
Visualization app – HTML5
A lightweight publish/subscribe protocol with predictable bi-directional message delivery
MQTT - Open Connectivity for Mobile, M2M and IoT
Lossy or Constrained
Network
Lossy or Constrained
Network Monitoring & Analytics
ServerCommands or Data Visualisation
High volumes of data/eventsIT Systems
In the era of a Smarter Planet, open source and standards are essential
1999 Invented by Dr. Andy Stanford-Clark (IBM), Arlen Nipper (now Cirrus Link Solutions)
2011 - Eclipse PAHO MQTT open source project
2004 MQTT.org open community
2013 – MQTT Technical Committee formed
Cimetrics, Cisco, Eclipse, dc-Square, Eurotech, IBM, INETCO Landis & Gyr, LSI, Kaazing, M2Mi, Red Hat, Solace, Telit Comms, Software AG, TIBCO, WSO2
Evolution of an open technology
A producer publishes a message (publication) on a topic (subject)A consumer subscribes (makes a subscription) for messages on a topic (subject) A message server matches publications to subscriptions If none of them match the message is discarded If one or more matches the message is delivered to each matching consumer
Publish / Subscribe has three important characteristics:1. It decouples message senders and receivers, allowing for more flexible applications2. It can take a single message and distribute it to many consumers3. This collection of consumers can change over time, and vary based on the nature of the message.
Publish / Subscribe Messaging (One to Many)
• The HTTP standard revolutionized how we consume data‒ A single simple model: Send a request, read the response‒ Available via any tablet, laptop, phone, PC etc.‒ Good for requesting data from a known source
• MQTT brings features specifically designed for mobile or M2M use…
MQTT and HTTP
HTTP MQTTStyle/Paradigm Synchronous,
request/responseAsynchronous, event-driven
Design Point Web browsers M2M / IoT
Message size Rich headers 2 bytes in minimum header
Reliability over fragile networks
Need to implement by custom code on top of HTTP
Built-in
Push client->server Yes Yes
Push server->client Polling has to used on top of HTTP
Efficient, scalable push is built into the protocol
Ubiquity Widely available Growing number of OSS and commercial implementations
Standards IETF OASIS
Data distribution 1-to-1 only Supports 1-to-none, 1-to-1, 1-to-n, n-to-1
MQTT Clients and APIs
Client libraries provide some or all of the following:
• Functions to build and parse the MQTT protocol control packets
• Threads to handle receipt of incoming control packets
• QoS 1 and QoS 2 delivery using a local persistence store
• KeepAlive handling
• Simple API for developers to use
Open Source clients available in Eclipse Paho project
• C, C++, Java, JavaScript, Lua, Python and Go
Clients for other languages are available, see mqtt.org/software
• E.g. Delphi, Erlang, .Net, Objective-C, PERL, PHP, Ruby
• Not all of the client libraries listed on mqtt.org are current. Some are at an early or experimental stage of development, whilst others are stable and mature.
You can develop an MQTT client application by programming directly to the MQTT protocol specification, however it is more convenient to use a prebuilt client
Eclipse Paho clients
• C / C++ – MQTT C Client for Posix and Windows– MQTT C++ Client for Posix and Windows– Embedded MQTT C Client
• Java– J2SE client– J2ME client– Android service
• Others– JavaScript (for browser and hybrid applications)– Lua– Python– Go
Paho C Client libraries
• Linux (Posix) or Windows– Full featured clients providing an MQTT api with QoS1, QoS2 and keepAlive
handling– Synchronous client (fully synchronous mode)
• Connect, Disconnect, Publish, Subscribe and Unsubscribe calls block until they receive a response from the server
• Applications use mqtt_receive() to read inbound messages• Client library runs entirely on the calling application’s thread
– Synchronous client (asynchronous mode)• Selected by registering a messageReceived, messageDelivered or connectionLost
callback.• Library starts a separate thread to handle these callbacks
– Asynchronous (use MqttAsynch )• All API calls are processed asynchronously and invoke a callback when complete
• Embedded Client– Limited to the construction and parsing of MQTT control packets– Client runs entirely on the calling application’s thread– Intended for embedded devices that don’t run Linux (e.g. ARM mbed)
Programming your own device to use Quickstart
You must• Use MQTT 3.1 or MQTT 3.1.1 (3.1.1 is preferable)• Connect to quickstart.messaging.internetofthings.ibmcloud.com, port 1883• Supply a client-id of the form d:<org-id>:<device-type>:<device-id>, where:
• <org-id> = “quickstart”• <device-type> = an identifier you provide, e.g. “acme-thing”• <device-id> = a 12 hexadecimal character mac address in lower case, without
delimiting : (colon) characters. For example, a36d7c91bf9e.• Publish to the topic “iot-2/evt/status/fmt/json”• Publish at QoS=0 only
You should be aware that...• The retained flag will not be honoured• Subscribing to receive messages isn’t supported.
Programming your own device – Quickstart message format
The message payload must be in JSON and must not exceed 4096 bytes (that’s the QuickStart limit).
The message payload must contain a single top-level property called "d". This property may contain an arbitrary number of child properties, these having either integer or string datatypes:
{ "d": { "name1": "stringvalue", "name2": intvalue, ... } }
Here's an example: { "d": { "myName": "Stuart's Pi", "cputemp": 46, "sine": -10, "cpuload", 1.45 } }
"myName" is optional – but if you supply it, it’s displayed as a title on the visualization page.
Security ConsiderationsAs we have already noted, the IBM IoT Cloud Quickstart service is free and does not provide any security features.
When designing an IoT application for production use, you need to consider its security implications, including:
1. Do I need to secure the data coming from the devices? This could mean• Authenticating the devices when they connect, to protect against an
attacker who attempts to impersonate them• Using TLS to protect the data as it travels from the device, to prevent the
data from being modified in transit• Protecting the devices and the software that runs on them from being
subverted by an attacker.2. Do I need to restrict access to the data itself, for privacy or other reasons?
• Use TLS to encrypt the data as it travels from the device• Authenticate any applications that try to access the device data
Registering devices with the IoT Foundation
Signing up allows permanent usage of the IoTF service in a secure fashion.
• Administration dashboard that lets you register devices and monitor their status
• Security of data, the device and the communications channel (TLS + authentication and authorisation for devices & applications)• Inbuilt historian with API for time series data access• Allows publishing of information to registered devices (i.e. sending commands to devices)
Available Plans
30-day Free Trial: Available from IBM Marketplace Free plan: Available from IBM Bluemix Bronze: Get started quickly and move to production with a small number of devices Silver: For standard needs: development, test and production use Gold: For advanced needs and large-scale production use
Signing up to the IoT Foundation Service
Two ways to sign up for an IoT account1. Via IBM Bluemix
• Sign up to Bluemix itself• Open the Bluemix Catalog and scroll
down till you find Internet of Things• Create an instance of the IoT Service
• You may bind it to a Bluemix application or leave it unbound
2. Via IBM Cloud Marketplace• Log in to marketplace• Select 30-day Free Trial or paid
subscription
You can start on either route from https://internetofthings.ibmcloud.com/dashboard/#/signup
Signing up (by either route) creates an “IoT Foundation Organization”. This represents you usage of the Foundation
Registering Devices with and IoTF Organization
When registering a device with an IoTF organization you must provide• A Device Type - this describes the kind of device it is• A Device Identifier – unique for this device (within its Device Type)
Registering devices – Credentials
The id of the owning organization
The device type that you provided
The device id that you provided
Indicates that authentication is to be by token
Secret token to be used by your device.
When you have successfully registered your device, the IoT Foundation generates a Token for it to use on the MQTT Connect call.
The UI provides a block of credentials (including this token) as shown below
Registering devices – using the Credentials
• The recipes that come with the Quickstart devices tell you how to update the device code so that it uses the credentials generated by the IoTF– In some cases this is simply a question of downloading a
file onto the device.• If you are writing your own device code, you need to
connect as follows:– Make the MQTT connection to
<org-id>xyzzyz.messaging.internetofthings.ibmcloud.com:1883, or <org-id>xyzzyz.messaging.internetofthings.ibmcloud.com:8883 (TLS)
– Use an MQTT client identifier of the form:d:<org-id>:<device-type>:<device-id>
– Supply the literal "use-token-auth" as the MQTT username– Supply the authorization token as the MQTT password
Registered devices – receiving commands
• Once a device has been registered, it can subscribe to receive commands sent to it by IoT Foundation applications
• The device connects as described on the previous slide• It can subscribe to any topic of the form
– iot-2/cmd/<cmd-type>/fmt/<format-id>• <cmd-type> is used to distinguish between different types of command. A
device that supports more than one type of command can make more than one subscription. Alternatively it can subscribe to all commands that are targeted to it by using the ‘+’ MQTT wildcard character in this topic element.
• <format-id> is used to distinguish different payload encodings. Multiple formats might be published and this distinction subscribes the device only to a relevant encoding format. If possible, applications and devices should use a format-id of “json” and encode the command as a JSON object. However, no constraints are imposed on the message structure or encoding, or on the content of the commands.
Internet of ThingsRapidly growing space, across nearly every industryPartner ecosystem plays a vital part
IoT FoundationConnect devices, collect, route, and visualize dataBuild internet of things applications to analyze dataCustomize and add further devices
MQTT Messaging optimized for mobile, smart sensors and telemetry devicesSimple APIs for Java, JavaScript and other languages
Summary
intelligentinterconnectedinstrumented
Useful Links
IBM IoT Foundation and Quickstart http://internetofthings.ibmcloud.com
Quickstart recipes on developerWorks https://www.ibmdw.net/iot/recipes
Quickstart code on GitHub https://github.com/ibm-messaging
MQTT information http://mqtt.org
MQTT 3.1.1 Specification• http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/cos02/mqtt-v3.1.1-cos02.pdf
Questions?
Thank You
WebSphere Technical University and Digital Experience Europe 2014 Your feedback is valuable - please complete your session or lab evaluation!
Session numberA34Provide your evaluations by:
Evaluation forms:Fill out a form at the end of each session Paper forms are located in each of the session or lab roomsPlace the completed form in the tray as you exit the room
- Or –
Complete the session survey on Event Connect Portal: ibmeventconnect.eu/euxdx
Select Sessions, then Session Finder, and complete the survey