2 iot-whitepaper-and-tutorial
2 iot-whitepaper-and-tutorial
www.ueidaq.com
UEI IoT White Paper and Tutorial June 2017
With the advent of interconnected “things,” devices that have not typically been accessible outside of
a local network can become accessible on a world-wide scale. For commercial and industrial data
acquisition (DAQ) systems, these devices include sensors, controllers, signal conditioning units,
machines for connectivity and processing units. One of the strengths of IoT is that it allows multiple
data producers and multiple data consumers to work concurrently. Once devices are interconnected
and accessible, the opportunities for remote diagnostics, predictive maintenance systems,
automation, and real-time data collection and analysis become broader-based and more globally
viable.2
Predictive modeling, machine learning, and other big-data analysis tools for global industrial systems
require high volumes of data from distributed environments. IoT is being looked upon to solve many
data throughput and delivery concerns associated with industrial data acquisition systems.
© 2016 United Electronic Industries, Inc. All Rights Reserved. (508) 921-4600
www.ueidaq.com -1- info@ueidaq.com
UEI IoT White Paper and Tutorial June 2017
At the top of the Internet Protocol Suite stack are application layer protocols, which determine how
applications communicate with each other. These protocols can be associated with distributed
application structures, such as client-server or publish-subscribe applications.4
A popular protocol for industrial IoT (IIoT) applications is Message Queue Telemetry Transport
(MQTT), a lightweight publish-subscribe messaging protocol. MQTT is an open source TCP-based
protocol first authored in 1999 and designed for applications where hosting hardware may have
limited on-board memory and for applications requiring remote communications.
© 2016 United Electronic Industries, Inc. All Rights Reserved. (508) 921-4600
www.ueidaq.com -2- info@ueidaq.com
UEI IoT White Paper and Tutorial June 2017
The following sections of this white paper provide an MQTT overview and tutorials.
© 2016 United Electronic Industries, Inc. All Rights Reserved. (508) 921-4600
www.ueidaq.com -3- info@ueidaq.com
UEI IoT White Paper and Tutorial June 2017
UEIPAC is also pre-loaded with example C code for connecting the UEIPAC to other MQTT clients.
C code examples can be used as a basis for user code development. Additionally, the UEIPAC
Software Development Kit (SDK) comes with the GNU toolchain compiled to run on a host PC and
build binaries targeting the UEIPAC.
One of the strengths of using an MQTT data flow model for IoT is that when a DAQ system publishes
data, multiple data consumers can subscribe to and consume the same data.
Publisher Message A
Messages Subscriber
A&C
Publisher Message B
Broker Message C Subscriber
Messages
Message C
A, B, & C
Publisher Subscriber
MQTT Data Flow Model The MQTT publish/subscribe communication model is event driven.
Messages are pushed to clients (as opposed to clients periodically requesting updates).
MQTT works by clients connecting to a broker to publish data messages or subscribe to them. The
broker is the central communication point and mediator in charge of dispatching all messages among
multiple publishers and multiple subscribers.
Clients publish messages with a topic name embedded in the message, and the broker uses that
topic as routing information. Receiving clients register with the broker and subscribe to specific topics.
The broker delivers all messages with matching topics to the clients. All data storage and transfer
control is done by the broker.
© 2016 United Electronic Industries, Inc. All Rights Reserved. (508) 921-4600
www.ueidaq.com -4- info@ueidaq.com
UEI IoT White Paper and Tutorial June 2017
Traditional DAQ Data Flow Model The traditional DAQ data flow model includes sensors and
DAQ signal conditioning hardware co-located at the edge of a network. Sensors detect real-world
physical conditions, which they convert into electrical representations. DAQ hardware samples the
sensor output and produces digitized data through signal conditioning of the sensor samples.
Digitized data is then acquired by computers for data collection, processing, and analysis.
Supervisory
Supervisory
Sensors
Sensors DAQHW/SW
DAQ HW/SW ControlSystem
System
(sensephenomenon)
(sense phenomenon) (sampleand
(sample andconvert
convert 0.96592
0.96592
Control
0.70715 (collect&&analyze
(collect analyzedata)
data)
to usable data)
to usable data) 0.70715
0.25887
0.25887
-0.25884
-0.25884
-0.70713
-0.70713
-0.96591
-0.96591
Sensors are wired to UEI DAQ hardware through 37- or 62-pin D-Sub connectors, and output data
can be stored locally on an SD-card or other removable media or transferred to a host computer via
a Wifi, copper, or fiber optic Ethernet connection.
IoT Data Flow Model For IoT systems, the traditional DAQ data flow model changes such that
DAQ hardware acts as client to a broker instead of transferring data directly to a supervisory system.
DAQ hardware still collects raw data from sensors at the point of creation, but through a
pre-established authenticated instance with a cloud service, the digitized data is transferred to a
broker using the MQTT protocol. Once data is secured by the broker, any authenticated subscriber
can access the data, asynchronously and concurrently with other subscribers.
Subscribe
Sensors
UEIPAC
Sensors
Publish IoT Subscribe IoT
Sensors Subscribers
Broker
...
Sensors Subscribe
0.08002
-0.02211
0.03402
0.09911
0.02916
© 2016 United Electronic Industries, Inc. All Rights Reserved. (508) 921-4600
www.ueidaq.com -5- info@ueidaq.com
UEI IoT White Paper and Tutorial June 2017
Formatting Overview
Text formatting Text formatted in fixed typeface generally represents source code or other
text that should be entered verbatim at the command line or into the source code, initialization, or
other file. These commands should be typed exactly as shown.
Topic formatting MQTT clients publish messages with a topic name embedded in the message,
and the broker uses that topic as routing information. One MQTT topic is mapped to each specified
UEIPAC channel.
Topic names in this tutorial consist of three topic levels with each level separated by a forward slash:
<Channel type>/<Device position>/<Channel number>.
• Channel type is the type of I/O board being referenced. For example, AI is an analog input
board, DI is a digital input board, and CT is a counter board.
• Device position is the board position in the chassis. For example, Dev0 is the first or top DAQ
I/O board installed in the UEIPAC chassis, Dev1 is the second board, Dev2 is the third, etc.
• Channel number is the channel number of the board. For example, the DIO-449 board is a 48
channel digital input board. The topic name can reference any channel from “Ch0” to “Ch47” to
specify the input.
• Wild cards are also permitted in the topic name: # is the multi-level wildcard, and + is the single
level wildcard.
© 2016 United Electronic Industries, Inc. All Rights Reserved. (508) 921-4600
www.ueidaq.com -6- info@ueidaq.com
UEI IoT White Paper and Tutorial June 2017
• AI/Dev0/Ch0: Channel 0 of the analog input board in the first chassis position
• AI/Dev1/Ch0: Channel 0 of the analog input board in the second chassis position
• DI/Dev2/Ch1: Channel 1 of the digital input board in the third chassis position
• AI/#: All channels of all analog input boards in any chassis position
Sample code parameter formatting The SampleDMAP_MQTT example code collects input
samples from the specified channels and publishes those samples to the specified host/broker.
Parameter Description
-d <device list> The list of devices (or board positions) to include in the
data acquisition (DMAP)
(e.g., -d 0,1 will include I/O boards in the chassis at
positions 0 and 1)
-c <channel per device> The list of channels to configure for each device
(e.g., -c 4,8 configures 4 channels on device 0 (chan-
nels 0 thru 3), and 8 channels on device 1 (channels 0
thru 7)
-h <MQTT host> The IP address of the MQTT broker. If using DHCP, this
can be the hostname
© 2016 United Electronic Industries, Inc. All Rights Reserved. (508) 921-4600
www.ueidaq.com -7- info@ueidaq.com
UEI IoT White Paper and Tutorial June 2017
Alternatively, you can remote shell (ssh, telnet, etc.) into the UEIPAC from a PC running
Linux OS, from a PuTTY telnet or SSH session from a Windows PC, or from a Cygwin shell.
Type the following at the UEIPAC Linux prompt (~#), and then enter and reenter the password
(the default password is powerdna):
• ~# adduser mosquitto
Publish The tutorial starts the sample code running on the UEIPAC, which
acquires and publishes data from an analog input board. Then the
local MQTT command line subscriber is used to request the
analog input data from the on-board Mosquitto broker.
If the Mosquitto service hasn’t already been started, follow the steps in “Setting Up UEIPAC for MQTT
Publishing” above.
In this example, the host IP address of the broker is the loopback IP address (127.0.0.1),
and the port is 1883.
© 2016 United Electronic Industries, Inc. All Rights Reserved. (508) 921-4600
www.ueidaq.com -8- info@ueidaq.com
UEI IoT White Paper and Tutorial June 2017
NOTE The mosquitto_sub command invokes a simple MQTT client that will
subscribe to a single topic and print all messages it receives.
Type the following command at the UEIPAC Linux prompt to see subscribed data messages:
Figure 4: Analog Input Values Pushed to Local Subscriber from Local Broker
The subscriber requests AI/Dev0/# topics. The -t option specifies which topics are
requested, and -v specifies verbose printing.
In this example, the mosquitto_sub service subscribes to receive all channels from the first
analog input board in the UEIPAC chassis. The analog input board in this example has even
channels tied to +7.5 volts and odd channels tied to -7.5 volts.
© 2016 United Electronic Industries, Inc. All Rights Reserved. (508) 921-4600
www.ueidaq.com -9- info@ueidaq.com
UEI IoT White Paper and Tutorial June 2017
> Using the Local MQTT Publisher & Broker and Remote MQTT Subscribe Service
The following tutorial uses a remote MQTT
subscription service to request and view UEIPAC MQTTLens 7.74999
topics from the local Mosquitto broker on the -7.75211
UEIPAC. 7.75402
Publish -7.50421
Subscribe
This tutorial sets up running sample code on
the UEIPAC the same way as in the previous
example; however, the MQTT subscriber is
provided by the Chrome application, MQTTLens.
If the Mosquitto service hasn’t already been started, follow the steps in “Setting Up UEIPAC for MQTT
Publishing” on page 8.
The host IP address of the broker is the loopback IP address (127.0.0.1), and the port is
1883.
Launch MQTTLens:
© 2016 United Electronic Industries, Inc. All Rights Reserved. (508) 921-4600
www.ueidaq.com - 10 - info@ueidaq.com
UEI IoT White Paper and Tutorial June 2017
Click Connections + to add a connection, and then enter a connection name in the
Connection name field and the UEIPAC IP address under Hostname:
© 2016 United Electronic Industries, Inc. All Rights Reserved. (508) 921-4600
www.ueidaq.com - 11 - info@ueidaq.com
UEI IoT White Paper and Tutorial June 2017
© 2016 United Electronic Industries, Inc. All Rights Reserved. (508) 921-4600
www.ueidaq.com - 12 - info@ueidaq.com
UEI IoT White Paper and Tutorial June 2017
> Using the Local MQTT Publisher, a Remote Cloud Broker, & Remote MQTT
Subscription Applications
The following tutorial uses the local Mosquitto publisher
on the UEIPAC, a remote MQTT broker cloud service,
IoT Broker and remote MQTT subscription services (a Chrome app
mqttcloud.com and a hand-held device app).
This example also provides the steps to set up the UEIPAC to use a DHCP assigned IP address.
Using DHCP will configure the gateway and DNS properly, so the “cloudmqtt.com” hostname can be
entered instead of a semi-static IP address. The dynamically allocated IP address for the UEIPAC
will be needed when we setup the MQTT instance.
If the Mosquitto service hasn’t already been started, follow the steps in “Setting Up UEIPAC for MQTT
Publishing” on page 8.
~ # ifconfig
eth0
Link encap:Ethernet HWaddr 00:0C:94:00:D0:D0
inet addr:192.168.0.91 Bcast:192.168.0.255
Mask:255.255.255.0
© 2016 United Electronic Industries, Inc. All Rights Reserved. (508) 921-4600
www.ueidaq.com - 13 - info@ueidaq.com
UEI IoT White Paper and Tutorial June 2017
© 2016 United Electronic Industries, Inc. All Rights Reserved. (508) 921-4600
www.ueidaq.com - 14 - info@ueidaq.com
UEI IoT White Paper and Tutorial June 2017
Note the Server and Port information. These will be used later to connect the Mosquitto
publication service on the UEIPAC to the cloudMQTT broker:
Figure 10: Note the Server hostname and Port on the hosted broker
© 2016 United Electronic Industries, Inc. All Rights Reserved. (508) 921-4600
www.ueidaq.com - 15 - info@ueidaq.com
UEI IoT White Paper and Tutorial June 2017
For this example, we set up two usernames: one for the UEIPAC as a publisher
(ueipac-publisher), and one for the subscriber (ueipac).
© 2016 United Electronic Industries, Inc. All Rights Reserved. (508) 921-4600
www.ueidaq.com - 16 - info@ueidaq.com
UEI IoT White Paper and Tutorial June 2017
In this example, we set the User to the credentials set up for the UEIPAC as a publisher
(ueipac-publisher) and specify published topics from the UEIPAC will be the Topic AI/#.
Publishers must have Write Access checked, and subscribers must have Read Access
checked.
© 2016 United Electronic Industries, Inc. All Rights Reserved. (508) 921-4600
www.ueidaq.com - 17 - info@ueidaq.com
UEI IoT White Paper and Tutorial June 2017
In this example, the host is the mqttcloud broker. The hostname is “m13.cloudmqtt.com” as
noted when the instance was created in Step 4 on page 12. The port and credentials are also
what were setup in the previous two steps.
Once we start the SampleDMAP_MQTT code running, the local Mosquitto publisher will
publish analog input samples acquired from the first 8 channels on board 0 (Dev0) and the first
8 channels on board 1 (Dev1) this time to the cloud based MQTT broker.
© 2016 United Electronic Industries, Inc. All Rights Reserved. (508) 921-4600
www.ueidaq.com - 18 - info@ueidaq.com
UEI IoT White Paper and Tutorial June 2017
In this example, we have an analog input board (AI) as the first board in the UEIPAC chassis
(Dev0), and we are publishing data from channels 0 through 7.
At this point, any MQTT client from any location in the world can subscribe to this data.
The following steps set up Google Chrome’s MQTTLens (used in the previous tutorial) and the
iPhone app, ICPDAS MQTT, to subscribe to the mqttcloud.com broker and view samples.
© 2016 United Electronic Industries, Inc. All Rights Reserved. (508) 921-4600
www.ueidaq.com - 19 - info@ueidaq.com
UEI IoT White Paper and Tutorial June 2017
Figure 15: Enter Broker Connection Information for MQTTLens Subscription Client
The broker is the mqttcloud service. Refer to the instance setup in previous steps for the
Server, Port, and user credentials.
© 2016 United Electronic Industries, Inc. All Rights Reserved. (508) 921-4600
www.ueidaq.com - 20 - info@ueidaq.com
UEI IoT White Paper and Tutorial June 2017
© 2016 United Electronic Industries, Inc. All Rights Reserved. (508) 921-4600
www.ueidaq.com - 21 - info@ueidaq.com
UEI IoT White Paper and Tutorial June 2017
13.Setup mqttcloud as the broker connection for the MQTT client on the hand-held device
Enter connection information for the cloud broker: Host, Port, User ID and Password
credentials, and Topic settings can be found in step 4 through step 6:
Click Done to finish setup. The hand-held device will connect to the broker.
© 2016 United Electronic Industries, Inc. All Rights Reserved. (508) 921-4600
www.ueidaq.com - 22 - info@ueidaq.com
UEI IoT White Paper and Tutorial June 2017
© 2016 United Electronic Industries, Inc. All Rights Reserved. (508) 921-4600
www.ueidaq.com - 23 - info@ueidaq.com
UEI IoT White Paper and Tutorial June 2017
In summary
As industries progress to streamlining or automating operations, interconnected “things” that are able
to communicate in real-time with data processing equipment become increasingly important. As an
example, one big-data analytic scenario for the airline industry estimates the considerable amount of
flight operation data from onboard sensors that will need to be transferred to processing stations on
the ground for collection, storage and processing of data may be in the terabyte range.7
UEI provides rugged and flexible solutions that support IoT applications, with IoT hardware and
software configurations offered through our programmable automation controllers (UEIPACs).
UEIPACs are installed with any combination of UEI’s extensive selection of input/output boards to
meet the needs of an application, providing a modular design that facilitates communication and
interoperability with other devices, networks, and systems.
© 2016 United Electronic Industries, Inc. All Rights Reserved. (508) 921-4600
www.ueidaq.com - 24 - info@ueidaq.com
UEI IoT White Paper and Tutorial June 2017
Endnotes
1. Source: IEEE Spectrum.
Nordrum, Amy, “Popular Internet of Things Forecast of 50 Billion Devices by 2020 Is Outdated”
(Tech Talk, Aug 2016), spectrum.ieee.org/tech-talk/telecom/internet.
2. Source: Industrial Internet Consortium.
Industrial Internet Consortium, Manufacturing & Smart Factory, www.iiconsortium.org/verti-
cal-markets/manufacturing.htm.
3. Source: LinkedIn article.
Stansberry, James, “The IoT communication protocols” (October 2015), www.linke-
din.com/pulse/iot-communication-protocols-james-stansberry.
4. Source: SlideShare.
Patierno, Paolo, “IoT protocols landscape” (June 2014), www.slideshare.net/paolopat/io-t-proto-
cols-landscape.
5. Source: Wind River Press Release.
Wind River, “Wind River Unveils IoT-Enabled Product Portfoilio” (February 2015),
https://www.windriver.com/news/press/pr.html?ID=13288.
6. Source: OPC Foundation Press Release.
OPC Foundation, “OPC Foundation Announces support of Publish / Subscribe for OPC UA” (May
2016), opcfoundation.org/news/opc-foundation-news.
7. Source: Sampathkumar, Arun Kumar, “Commercial Aviation, Big Data and What I Think About
Them” (September 2014),
www.linkedin.com/pulse/20140923105538-238203970-commercial-aviation-big-data-and-what-i
-think-about-them?trk=pulse_spock-articles.
Evans, Dave, “How the Next Evolution of the Internet Is Changing Everything” (April 2011),
www.cisco.com/c/dam/en_us/about/ac79/docs/innov.
Heimes,Felix, “Fleet Health Monitoring and Machine Learning Technology for CBM+” (October
2009), www.phmsociety.org/sites/phmsociety.org/files/FieldedSystems_Dresch.pdf.
Keranen, Ari and Bormann, Carsten, “Internet of Things: Standards and Guidance from the IETF”
(April 2016). www.internetsociety.org/publications/ietf-journal-april-2016.
Schneider, Stan, “Understanding the Protocols Behind the Internet of Things” (Oct 2013),
electronicdesign.com/iot/understanding-protocols-behind-internet-things
About United Electronic Industries United Electronic Industries (UEI) is a leader in the data
acquisition and control, data logging, and embedded automation controller markets. Our cube, rack
and military chassis provide a rugged and powerful platform that is ideal for many applications in the
industrial, aerospace, military, and simulation fields – plus many more! Our chassis are uniquely
flexible, capable of being deployed as a remote Ethernet I/O node, a standalone data logger, or an
embedded controller. We offer incredible I/O flexibility with over 60 I/O boards available which include
analog/digital I/O, avionics (including 1553, 429, AFDX™, 664, 708/453, 825), speed/freq input,
CAN-bus, serial I/O and more. UEI supports all popular OSs such as Windows, Linux, VxWorks, QNX
and other RTOSs as well as all programming languages. We also offer complete and seamless
support of all major application packages, including LabVIEW™, MATLAB® and Simulink™.
© 2016 United Electronic Industries, Inc. All Rights Reserved. (508) 921-4600
www.ueidaq.com - 25 - info@ueidaq.com