Arduino
An open-source hardware and software platform for building
electronics projects.
Arduino is an open-source electronics platform based on
easy-to-use hardware and software. It's intended for
anyone making interactive projects.
Arduino senses the environment by receiving inputs from
many sensors, and affects its surroundings by controlling
lights, motors, and other actuators.
You can tell your Arduino what to do by writing code in
the Arduino programming language and using the
Arduino development environment.
Several Arduino-Board variants exist e.g.: UNO, NANO,
MEGA, DUE, YUN, etc.
4 / 44
IoT Protocols
The IoT needs standard protocols. Two of the most promising
for small devices are MQTT and CoAP.
MQTT gives flexibility in communication patterns and acts purely
as a pipe for binary data.
CoAP is designed for interoperability with the web.
Both MQTT & CoAP:
Are open standards
Are better suited to constrained environments than HTTP
Provide mechanisms for asynchronous communication
Run on IP
Have a range of implementations
See: MQTT and CoAP, IoT Protocols
32 / 44
Architecture
CoAP packets are much smaller than HTTP TCP flows. Bitfields
and mappings from strings to integers are used extensively to
save space. Packets are simple to generate and can be parsed in
place without consuming extra RAM in constrained devices.
CoAP runs over UDP, not TCP. Clients and servers communicate
through connectionless datagrams. Retries and reordering are
implemented in the application stack. Removing the need for
TCP may allow full IP networking in small microcontrollers. CoAP
allows UDP broadcast and multicast to be used for addressing.
CoAP follows a client/server model. Clients make requests to
servers, servers send back responses. Clients may GET, PUT,
POST and DELETE resources.
CoAP is designed to interoperate with HTTP and the RESTful web
at large through simple proxies.
Because CoAP is datagram based, it may be used on top of SMS
and other packet based communications protocols.
CoAP
CoAP is the Constrained Application Protocol from the CoRE
(Constrained Resource Environments) IETF group.
Architecture
Like HTTP, CoAP is a document transfer protocol. Unlike HTTP,
CoAP is designed for the needs of constrained devices.
33 / 44
MQTT
MQTT is a publish/subscribe messaging protocol designed for
lightweight M2M communications. It was originally developed
by IBM and is now an open standard. It was designed in 1999
for use on satellites and as such is very light-weight with low
bandwidth requirements making it ideal for M2M or IoT
applications.
Architecture
MQTT has a client/server model, where every sensor is a client
and connects to a server, known as a broker, over TCP.
MQTT is message oriented. Every message is a discrete chunk of
data, opaque to the broker.
Every message is published to an address, known as a topic.
Clients may subscribe to multiple topics. Every client subscribed
to a topic receives every message published to the topic.
34 / 44
MQTT
For example, imagine a simple
network with three clients and a
central broker.
All three clients open TCP
connections with the broker. Clients
B and C subscribe to the topic
temperature .
At a later time, Client A publishes a
value of 22.5 for topic temperature .
The broker forwards the message to
all subscribed clients.
The publisher subscriber model
allows MQTT clients to
communicate one-to-one, one-to-
many and many-to-one.
35 / 44
MQTT - Publish / Subscribe
The publish / subscribe (often called pub-sub) pattern lies at the heart of MQTT. It's based
around a message broker, with other nodes arranged around the broker in a star topology.
This is a very different model to the standard client/server approach, and at first it might
seem a little strange, but the decoupling it provides is a huge advantage in many situations.
Clients can publish or subscribe to
particular topics which are
somewhat like message subjects.
They are used by the broker to
decide who will receive a message.
Topics in MQTT have a particular
syntax. They are arranged in a
hierarchy using the slash character
(/) as a separator, much like the
path in a URL. So a temperature
sensor in your kitchen might
publish to a topic like
sensors/temperature/home/kitchen.
See: Zoetrope
36 / 44
That's all for now..
Enough talking
Let's get our hands dirty!!
37 / 44
AREF
GND
RESET
3V3L
TX
RX
USB
EXT
PWRSEL
PWR
ICSP
TX
RX
3
1
2
1
1
1
0
1
9 8
DIGITAL
7 6 5 4 3 2 1 0
1
5V Gnd
POWER
www.adruino.cc
ANALOG IN
Vin 0 1 2 3 4 5
ADRUINO
Arduino - Sensor Node
Publish data to the topic sensors/led/status every 2 seconds.
These values are the actual device state with considering local
input to the sensors (potentio and push button)
The data consist of a status (either "ON" or "OFF") and of an
intensity (any integer ranging 0 - 254) in the following JSON
format:
{
"data":{
"status":"ON",
"intensity":200
}
}
40 / 44
MQTTLens - Client Node
Subscribe to the topic sensors/led/status.
41 / 44
Refs
1. Arduino - Official Site | Tutorials
2. Guide - Getting Started | Windows
3. Tutorials - WebClient | WebClientRepeating | EthernetBegin
4. Playground - WebClient POST
5. MQTT and CoAP, IoT Protocols
6. A Brief, but Practical Introduction to the MQTT Protocol and its Application to
IoT | Zoetrope
7. Earthshine Design, Arduino Starter Kit Manual: A Complete Beginners Guide to
the Arduino
43 / 44