C3.2 - IoT Protocols and Connectivity
C3.2 - IoT Protocols and Connectivity
How IoT
IoT devices communicate using IoT protocols
devices
communicate
with the IoT protocols ensure that information from one device or
network? sensor gets read and understood by another
E.g. Internet protocol (IP) is a set of rules that dictates how data gets
sent to the internet
Transport
TCP UDP
layer
Low-Power
Wide-Area Short-Range
Network Wireless
(LPWAN) Technologies
Technologies
Cellular Satellite
technologies technologies
Wire/wireless communication
technologies
Bluetooth
2.4 GHz 100 m 2 Mbps 6 ms Point to point Low
low energy
800-900
Z-wave 100 m 100 kbps NA Mesh Low
MHz
Cellular provides solutions for IoT solutions that require long-distance data
transfers combined with low latency.
Advantage Cellular
• Sending high quantities of data
• Provide the low power, low throughput.
• The lower prices charged by mobile network operators.
2. IOT DATA LINK LAYER PROTOCOLS
Wireless - Long-Range Solutions
Power
Max.
Solution Frequency Max. range Latency Topology consumptio
Throughput
n
Various
LTE CAT 0 (Depending Up to 100 km 1 Mbps NA Star Medium
region)
LTE CAT
250 kbps 1.6 – 10s Low
NB1 (NBIoT)
LTE CAT M1
1 Mbps 10-15 ms Low
(eMTC)
2. IOT DATA LINK LAYER PROTOCOLS
Wireless - Long-Range Solutions LPWAN
It is important to understand that LPWAN itself is not a connectivity standard, but rather an
umbrella term encompassing various implementations and protocols that share common
connectivity characteristics
2. IOT DATA LINK LAYER PROTOCOLS
Wireless - Long-Range Solutions - LPWAN
Max. Power
Solution Frequency Max. range Topology
Throughput consumption
Various (sub - 1
LoraWAN 15 km 50 kbps Star Very Low
GHz)
10 kbps
Sigfox 900 MHz 50 km Star Very Low
Various (sub - 1
Weighless 5 km 10 Mbps Star Very Low
GHz)
Various (sub - 1
Ingenu 1500 km 38 kbps Star Very Low
GHz)
2. IOT DATA LINK LAYER PROTOCOLS
Wire Solutions
Wired solutions are applied when a) the 'thing', for example a machine, usually stays at the
same location and there is no need for mobility, and b) the distance between the sensor and the
gateway is short.
These solutions are usually aimed at broadband applications, such as in-home distribution of
IPTV, Internet connectivity, and smart grids, where data is transferred through the existing
electrical wires installed within the building.
2. IOT DATA LINK LAYER PROTOCOLS
Wire Solutions
Overview of current wired connectivity solutions
3. NETWORK LAYER ROUTING PROTOCOL
Routing layer handles the transfer the packets from source to destination.
RPL
IPv6 Routing Protocol for Low-Power and Lossy Networks (RPL) is
designed for routing IPv6 traffic over low-power networks like those
networks implemented over 6LoWPAN.
RPL (pronounced “ripple”) is designed for routing packets within constrained
networks such as wireless sensor networks, where not all devices are
reachable at all times and where there are high or unpredictable amounts of
packet loss.
RPL can compute the optimal path by building up a graph of the nodes in
the network based on dynamic metrics and constraints like minimizing
energy consumption or latency.
3. NETWORK LAYER ROUTING PROTOCOL
CoRPL
An extension of RPL is CORPL, or cognitive RPL, which is designed for
cognitive networks and uses Destination Oriented Directed Acyclic Graph
(DODAG) topology generation but with two new modifications to RPL.
CORPL utilizes opportunistic forwarding to forward the packet by choosing
multiple forwarders (forwarder set) and coordinates between the nodes to
choose the best next hop to forward the packet to.
DODAG is built in the same way as RPL. Each node maintains a forwarding
set instead of its parent only and updates its neighbor with its changes using
DIO messages. Based on the updated information, each node dynamically
updates its neighbor priorities in order to construct the forwarder set.
3. NETWORK LAYER ROUTING PROTOCOL
CARP
Channel-Aware Routing Protocol (CARP) is a distributed routing protocol
designed for underwater communication. It can be used for IoT due to its
lightweight packets.
It considers link quality, which is computed based on historical successful
data transmission gathered from neighboring sensors, to select the
forwarding nodes.
There are two scenarios: network initialization and data forwarding.
o In network initialization, a HELLO packet is broadcasted from the sink to
all other nodes in the networks.
o In data forwarding, the packet is routed from sensor to sink in a hop- by-
hop fashion. Each next hop is determined independently.
3. NETWORK LAYER ROUTING PROTOCOL
CARP
The main problem with CARP is that it does not support reusability of
previously collected data.
In other words, if the application requires sensor data only when it changes
significantly, then CARP data forwarding is not beneficial to that specific
application. An enhancement of CARP was done in E-CARP by allowing the
sink node to save previously received sensory data. When new data is
needed, E-CARP sends a Ping packet which is replied with the data from
the sensor nodes. Thus, E-CARP reduces the communication overhead
drastically.
3. NETWORK LAYER ROUTING PROTOCOL
Summary
RPL is the most commonly used one. It is a distance vector protocol
designed by IETF in 2012.
CORPL is a non-standard extension of RPL that is designed for cognitive
networks and utilizes the opportunistic forwarding to forward packets at
each hop.
On the other hand, CARP is the only distributed hop based routing protocol
that is designed for IoT sensor network applications. CARP is used for
underwater communication mostly.
3. NETWORK LAYER ROUTING PROTOCOL
IPv6
At the Internet Layer, devices are identified by IP addresses.
IPv6 is typically used for IoT applications over legacy IPv4 addressing.
IPv4 is limited to 32-bit addresses, which only provide around 4.3 billion
addresses in total, which is less than the current number of IoT devices
that are connected, while IPv6 uses 128 bits, and so provides
2 128 addresses (around 3.4 C 10 38 or 340 billion billion billion billion)
addresses.
4. NETWORK LAYER ENCAPSULATION PROTOCOLS
One problem in IoT applications is that IPv6 addresses are too long and cannot
fit in most IoT datalink frames which are relatively much smaller. Hence, IETF is
developing a set of standards to encapsulate IPv6 datagrams in different datalink
layer frames for use in IoT applications.
6LoWPAN
The IPv6 Low Power Wireless Personal Area Network
(6LoWPAN) standard allows IPv6 to be used over 802.15.4 wireless
networks.
6LoWPAN is often used for wireless sensor networks, and
the Thread protocol for home automation devices also runs over
6LoWPAN.
4. NETWORK LAYER ENCAPSULATION PROTOCOLS
6LoWPAN
It efficiently encapsulates IPv6 long headers in IEEE802.15.4 small
packets, which cannot exceed 128 bytes.
The specification supports different length addresses, low bandwidth,
different topologies including star or mesh, power consumption, low cost,
scalable networks, mobility, unreliability and long sleep time.
The standard provides header compression to reduce transmission
overhead, fragmentation to meet the 128-byte maximum frame length in
IEEE802.15.4, and support of multi-hop deliver.
4. NETWORK LAYER ENCAPSULATION PROTOCOLS
6TiSCH
6TiSCH working group in IETF is developing standards to allow IPv6 to
pass through Time Slotted Channel Hopping (TSCH) mode of IEEE
802.15.4e datalinks.
It defines a Channel Distribution usage matrix consisting of available
frequencies in columns and time-slots available for network scheduling
operations in rows.
The standard does not specify how the scheduling can be done and
leaves that to be an application specific problem in order to allow for
maximum flexibility for different IoT applications. The scheduling can be
centralized or distributed depending on application or the topology used
in the MAC layer.
4. NETWORK LAYER ENCAPSULATION PROTOCOLS
6TiSCH
6TiSCH working group in IETF is developing standards to allow IPv6 to
pass through Time Slotted Channel Hopping (TSCH) mode of IEEE
802.15.4e datalinks.
It defines a Channel Distribution usage matrix consisting of available
frequencies in columns and time-slots available for network scheduling
operations in rows.
The standard does not specify how the scheduling can be done and
leaves that to be an application specific problem in order to allow for
maximum flexibility for different IoT applications. The scheduling can be
centralized or distributed depending on application or the topology used
in the MAC layer.
4. NETWORK LAYER ENCAPSULATION PROTOCOLS
IPv6
At the Internet Layer, devices are identified by IP addresses.
IPv6 is typically used for IoT applications over legacy IPv4 addressing.
IPv4 is limited to 32-bit addresses, which only provide around 4.3 billion
addresses in total, which is less than the current number of IoT devices
that are connected, while IPv6 uses 128 bits, and so provides
2 128 addresses (around 3.4 C 10 38 or 340 billion billion billion billion)
addresses.
4. NETWORK LAYER ENCAPSULATION PROTOCOLS
IPv6 over G.9959
RFC 7428 defines the frame format for transmitting IPv6 packet on ITU-T
G.9959 networks.
G.9959 defines a unique 32-bit home network identifier that is assigned
by the controller and 8- bit host identifier that is allocated for each node.
An IPv6 link local address must be constructed by the link layer derived
8-bit host identifier so that it can be compressed in G.9959 frame.
Furthermore, the same header compression as in 6lowPAN is used here
to fit an IPv6 packet into G.9959 frames.
RFC 7428 also provides a level of security by a shared network key that
is used for encryption.
4. NETWORK LAYER ENCAPSULATION PROTOCOLS
IPv6 over Bluetooth Low Energy
Bluetooth Low Energy is also known as Bluetooth Smart and was
introduced in Bluetooth V4.0 and enhanced in V4.1.
RFC 7668 [RFC7668], which specifies IPv6 over Bluetooth LE, reuses
most of the 6LowPAN compression techniques.
However, since the Logical Link Control and Adaptation Protocol
(L2CAP) sublayer in Bluetooth already provides segmentation and
reassembly of larger payloads in to 27 byte L2CAP packets,
fragmentation features from 6LowPAN standards are not used.
Another significant difference is that Bluetooth Low Energy does not
currently support formation of multi-hop networks at the link layer.
Instead, a central node acts as a router between lower-powered
peripheral nodes.
5. APPLICATION LAYER PROTOCOLS
MQTT
Message Queue Telemetry Transport (MQTT) is a publish/subscribe-
based messaging protocol that was designed for use in low bandwidth
situations, particularly for sensors and mobile devices on unreliable
networks.
AMQP
Advanced Message Queuing Protocol (AMQP) is an open standard
messaging protocol that is used for message-oriented middleware. Most
notably, AMQP is implemented by RabbitMQ.
5. APPLICATION LAYER PROTOCOLS
XMPP
The Extensible Messaging and Presence Protocol (XMPP) was originally
designed for real-time human-to-human communication including instant
messaging.
This protocol has been adapted for machine-to-machine (M2M)
communication to implement lightweight middleware and for routing XML
data. XMPP is primarily used with smart appliances.
5. APPLICATION LAYER PROTOCOLS
APPLICATION LAYER
Broker, which is the server that handles the data transmission between the clients.
A topic, which is the place a device want to put or retrieve a message to/from.
The message, which is the data that a device receives “when subscribing” from a topic or
send “when publishing” to a topic.
Publish, is the process a device does to send its message to the broker.
Subscribe, where a device does to retrieve a message from the broker.
5.1.2. CÁC THÀNH PHẦN CƠ BẢN GIAO THỨC MQTT
Broker: là server cài MQTT, server thu thập dữ liệu và giao tiếp các client.
Topic: Là chủ đề mà Broker tạo ra để Device gửi vào. Nó như là folder chứa dữ
liệu vậy nên có thể ở dạng đường dẫn abc/topic1.
Publish: Là gói tin Device gửi lên Broker. Khi Device Publish dữ liệu vào topic,
các Client sẽ nhận được dữ liệu khi đăng kí topic. Gói Publish có thể là gói gửi dữ
liệu gửi vào topic hoặc gói cài đặt Retain Message hay LWT Message do cờ
Retain, LWT quy định
Subscribe: Là gói đăng kí nhận data hay thông tin từ topic đăng kí (Broker sẽ
tạo một topic mới nếu không tìm được topic đăng kí). Khi Client gửi gói tin
Subcribe tới Broker để đăng kí một topic, ví dụ topic “T2Tdemo”. Bất cứ khi nào
Device gửi gói tin Publish vào topic “T2Tdemo”. Dữ liệu trong gói Publish
chuyển về Client. Giống như bạn Subscribe youtube
5.1.2. CÁC THÀNH PHẦN CƠ BẢN GIAO THỨC MQTT
Qos: Chất lượng đường truyền
Qos 0: Device gửi Publish tới Server không cần quan tâm đến gói tin gửi.
Qos 1: Device gửi Publish tới Server ,Sau đó nếu Server nhận được gói tin và gửi lại
Device gói PUBACK để xác nhận đã nhận được gói Publish từ Device
Qos 2: Device gửi Publish tới Server , Server nhận gói Publish gửi PUBREC lại Device
kèm theo ID đã nhận. Device nhận PUBREC gửi PUBREL kèm ID đó lại Server. Server
gửi lại PUBCOMP lại Device.
5.1.2. CÁC THÀNH PHẦN CƠ BẢN GIAO THỨC MQTT
Retain: Là cờ báo gói Publish, Device gửi tới Broker cài đặt Retain Message
cho topic. Khi Client subcribe vào topic đã cài đặt Retain Message sẽ nhận
được ngay Retain Message. Ví dụ “Device online”.
LWT(Last Will and Testament):Là cờ báo gói Publish, Device gửi tới Broker
topic cài đặt LWT Message. Khi Client Subcribe vào topic đã cài đặt LWT
Message sẽ nhận được tin nhắn LWT Message khi Device offline
5.1.2. CÁC THÀNH PHẦN CƠ BẢN GIAO THỨC MQTT
How MQTT works?
When a device (a client) wants to send data to the broker, we call this operation
a “publish”.
When a device (a client) wants to receive data from the broker, we call this
operation a “subscribe”.
5.1.2. CÁC THÀNH PHẦN CƠ BẢN GIAO THỨC MQTT
How MQTT works?
Let’s say there is a device that has a temperature sensor. Certainly, it wants to send his
readings to the broker. On the other side, a phone/desktop application wants to receive this
temperature value. Therefore, 2 things will happen:
The device defines the topic it wants to publish on, ex: “temp”. Then, it publishes the
message “temperature value”.
The phone/desktop application subscribes to the topic “temp”. Then, it receives the message
that the device has published, which is the temperature value.
Again, the broker role here is to take the message “temperature value” and deliver it to
phone/desktop application.
5.1.2. CÁC THÀNH PHẦN CƠ BẢN GIAO THỨC MQTT
MQTT message format – xem thêm tài liệu để thực hành LAB
PHẦN HEADER CỐ ĐỊNH
bit 7 6 5 4 3 2 1 0
byte 1 Loại Message Cờ QoS level RETAIN
byte 2 Độ dài còn lại
Byte 1: Chứa loại Message và các cờ (DUP, QoS level, and RETAIN)
Byte 2: Quy định độ dài còn lại (Ít nhất 1 tức là 1 byte)
PHẦN HEADER CỐ ĐỊNH
Loại Message: Byte 1, bits 7-4.
Từ gợi nhớ Giá trị thứ tự Miêu tả
Reserved 0 Chưa dùng
CONNECT 1 Client yêu cầu kết nối đến Server
CONNACK 2 Kết nối được chấp nhận
PUBLISH 3 Xuất bản message
PUBACK 4 Xuất bản message được chấp nhận
PUBREC 5 Xuất bản đã được nhận (đảm bảo nhận được part 1)
PUBREL 6 Xuất bản release (đảm bảo nhận được part 2)
PUBCOMP 7 Xuất bản hoàn thành (đảm bảo nhận được part 3)
SUBSCRIBE 8 Yêu cầu subcribe từ client
SUBACK 9 Yêu cầu subcriber được chấp nhận
UNSUBSCRIBE 10 Yêu cầu unsubcribe
UNSUBACK 11 Yêu cầu unsubcribe được chấp nhận
PINGREQ 12 Request PING
PINGRESP 13 Response PING
DISCONNECT 14 Client đang mất kết nối
Reserved 15 Reserved
PHẦN HEADER CỐ ĐỊNH
Các cờ: Các bit còn lại của byte đầu tiên tương ứng sẽ mô tả trạng thái của DUP, QoS và RETAIN
DUP: byte 1, bit 3.
Cờ này được bật khi client hoặc server đang cố chuyển lại một gói PUBLISH, PUBREL,
SUBSCRIBE or UNSUBSCRIBE. Giá trị này được sử dụng trong các mesage mà có QoS
lớn hơn 0 và yêu cầu ACK. Khi bit DUP được set, phần header thay đổi sẽ là Message ID.
Phía nhận xem giá trị này là một gợi ý để tự kiểm tra xem gói tin (có Message ID) ở trên đã
chuyển đến trước đó hay không. Còn chỉ từ trạng thái cờ DUP này thì chưa thể chắc chắn
có gói tin lặp được.
QoS: byte 1, bits 2-1. Cờ này sẽ cho biết mức độ tin cậy của việc chuyển message PUBLISH.
Bảng mô tả độ dài có thể biểu diễn với các số byte tương ứng
Số byte Độ dài min Độ dài max
1 0 (0x00) 127 (0x7F)
2 128 (0x80, 0x01) 16 383 (0xFF, 0x7F)
3 16 384 (0x80, 0x80, 0x01) 2 097 151 (0xFF, 0xFF, 0x7F)
4 2 097 152 (0x80, 0x80, 0x80, 0x01) 268 435 455 (0xFF, 0xFF, 0xFF, 0x7F)
PAYLOAD
CONNECT: Chứa một hoặc nhiều chuỗi UTF-8 encoded. Trong đó, chỉ định rõ một identifier duy
nhất cho client, một Will topic and message and và cả user name, password nữa.
SUBSCRIBE: Chứa một danh sách các topic name mà client có thể subcribe và cả QoS level nữa.
Tất cả chúng cũng là UTF-encoded.
SUBACK: Payload sẽ chưa một danh sách của các QoS level được cho phép. Có một mức QoS
level mà administrators của server cho phép client sử dụng để subcribe đến một Topic name cụ thể.
Những QoS level này được liệt kê cùng thứ tự tương ứng với danh sách các Topic Name trong
message SUBSCRIBE.
Phần payload của message PUBLISH chỉ chứa dữ liệu cho ứng dụng cụ thể. Không thể giả định
chúng được tạo bởi dữ liệu tự nhiên hay nội dung của dữ liệu, phần này sẽ được hiểu là một BLOB.
Nếu bạn muốn ứng dụng thực hiện việc nén dữ liệu đưa vào trong payload data, bạn cần định nghĩa
trong ứng dụng một cờ payload tương ứng để xử lý nhưng dữ liệu payload này. Bạn không thể định
nghĩa một cờ chỉ cho ứng dụng cụ thể bên trong bất cứ thành phần nào của header.
MESSAGE IDENTIFIERS
Message identifier được xuất hiện trong phần header của các message dưới đây:
PUBLISH, PUBACK, PUBREC, PUBREL, PUBCOMP, SUBSCRIBE, SUBACK,
UNSUBSCRIBE, UNSUBACK.
Message Identifier (Message ID) chỉ xuất hiện trong message khi giá trị QoS bit
miêu tả trong header chỉ định đến giá trị QoS 1 hoặc 2.
Message ID là một giá trị integer 16 bit không dấu. Thứ tự 2 byte ở đây là MSB ,
sau đó đến LSB
Client sẽ phải maintain một danh sách các message IDs để tách biệt với Message
ODs được sử dụng server mà nó kết nối đến. Điều này cho phép việc gửi một
PUBLISH với message ID bằng 1 tại đúng thời điểm nhận một message được
PUBLISH lên server với message ID bằng 1.
Đừng sử dụng Message ID là 0. Nó thường được sử dụng là Invalid Message ID
UTF-8
UTF-8 (8-bit Unicode Transformation Format - Định dạng chuyển đổi Unicode 8-
bit) là một bộ mã hóa ký tự với chiều rộng biến thiên dành cho Unicode.
UTF-8 có thể biểu diễn tất cả các chữ cái trong bộ ký tự Unicode, nhưng điểm
khác biệt quan trọng nhất là nó có thể tương thích ngược với ASCII. Vì lý do này,
UTF-8 nhanh chóng trở thành bộ mã hóa thống trị trong các tập tin, thư điện
tử, trang web, và các phần mềm xử lý văn bản.
UTF-8 mã hóa mỗi ký tự thành 1 đến 4 octet (tức là byte gồm 8-bit).
128 ký tự đầu tiên của bộ ký tự Unicode (tương ứng một-một với bộ ASCII) chỉ
dùng một octet có cùng giá trị nhị phân như bộ ASCII.
UNUSED BITS
Những bit được đánh dấu không sử dụng thường được set bằng (0)
COMMAND MESSAGES
CONNECT
SUBSCRIBE
CONNACK
SUBACK
PUBLISH
UNSUBSCRIBE
PUBACK UNSUBACK
PUBREC PINGREQ
PUBREL PINGRESP
PUBCOMP DISCONNECT
MQTT brokers?
Bevywise MQTTRoute
IBM Integration Bus VerneMQ
5.1.4. MOSQUITTO MQTT MESSAGING BROKER
Which broker to use?
Mosquitto is an open source message broker that
implements the MQTT protocol.
HTTP là một giao thức ứng dụng của bộ giao thức TCP/IP
5.2.2 CÁC THÀNH PHẦN CƠ BẢN GIAO THỨC HTTP
HTTP client and server communicate by sending text messages. The client sends
a request message to the server. The server, in turn, returns a response message.
5.2.2 CÁC THÀNH PHẦN CƠ BẢN GIAO THỨC HTTP
When you consider which networking technologies to adopt within your IoT
application, be mindful of the following constraints:
Range
Bandwidth
Power usage
Intermittent connectivity
Interoperability
Security
RANGE
Transmitting data from a device consumes power, and transmitting data over
long ranges requires more power than over a short range.
To consider the devices that operate on a battery to conserve power to prolong
the life of the battery and reduce operating costs.
To prolong the battery life, you can put the device into sleep mode whenever it is
idle.
To model the energy consumption of the device under different loads and
different network conditions to ensure that the device’s power supply and storage
capacity matches with the power that is required to transmit the necessary data
by using the networking technologies that you adopted.
INTERMITTENT CONNECTIVITY
IoT devices aren’t always connected. In some cases, devices will connect
periodically by design in order to save power or bandwidth.
However, sometimes an unreliable network might cause devices to drop off due
to connectivity issues.
Sometimes quality of service issues, such as dealing with interference or
channel contention on a wireless network using a shared spectrum.
INTEROPERABILITY
Adopting standard protocols has been the traditional approach for maintaining
interoperability on the internet. However, for the IoT, standardization processes
sometimes struggle to keep up with the rapid pace of change and technologies
are released based on upcoming versions of standards that are still subject to
change. In these cases, consider the ecosystem around the technologies.
SECURITY