IoT device is different from our computer or server. As well as the way they communicate. Here we will discuss the common way IoT devices are connected with other devices
Size: 1.93 MB
Language: en
Added: Nov 30, 2018
Slides: 26 pages
Slide Content
Understanding IoT Data Protocol
Tegar Imansyah - 4 November 2018
About
●Backend Engineer for Ngabarin IoT Platform
●Surabaya.py Organizer
●Mechatronics Engineering from PENS
●Interested in: Microcontroller, Raspberry Pi, Linux, Web, Data
Get in touch:
http://github.com/tegarimansyah
http://t.me/tegarimansyah
http://linked.in/tegarimansyah
Are you familiar with...
Web framework Microcontroller
WebSocket
Communication Protocol
What is IoT
IoT = Internet of Things, a fancy buzzword when we talk
about Industry 4.0
The Internet of things is the network of physical devices.
Combination from electronics, software, sensors,
actuators, and connectivity which enables these things to
connect, collect and exchange data. - Wikipedia, with
adjustments.
Electronics Software
Sensors Actuators Connectivity
Light Sensor
Humidity Sensor
Water Pump
Microcontroller Server
Why IoT Device Different With Computer
Google Cloud F1-micro (Smallest)
●0.2 vCPU Intel Xeon E5
●Memory: 0.6 GB = 588 MiB
ESP32 (Popular Powerful Microcontroller)
●CPU : Dual Core 240 Mhz
●Memory: 520 KiB
Arduino Uno (ATmega328) - (Most Popular dev board)
●CPU : 20 Mhz
●Memory: 2048 B = 2 KiB
What to discuss
●HTTP
●Websocket
●MQTT
HTTP
HTTP is a request–response protocol in the
client–server computing model.
Request is usually using REST -
GET, POST, PUT, DELETE
Response with status code:
200 - OK
201 - Created
400 - Bad Request
etc….
Test HTTP
Server Side
Client Side
Light Sensor
Humidity Sensor
Water Pump
Microcontroller Server
Problem: How to send data to Microcontroller in Real
Time?
WebSocket
Websockets allows persistent
connections with simultaneous
bi-directional communication.
They come with all the benefits of
HTTP since websockets initially
start off as an HTTP handshake,
before getting elevated to
continue the rest of the
communication in websockets.
Test WebSocket
Callback Function
MQTT
MQTT is a publish-subscribe-based messaging protocol.
It works on top of the TCP/IP protocol.
It is designed for connections with remote locations where a "small code footprint"
is required or the network bandwidth is limited.
The publish-subscribe messaging pattern requires a message broker.
What to learn about MQTT
●Topic
○Wildcart = home/+/lamp
○Wildcart = home/bedroom/#
●User & Access Control List (ACL)
○%u/home/bedroom => for user == tegar, only able to access tegar/home/bedroom
●Quality of Service (QoS)
○0
○1
○2
●Broker Bridging
MQTT over WebSocket (?)
=> HTTP, HTTPS, FTP, FILE
MQTT <> HTTP, HTTPS
WebSocket == HTTP (HTTPS via wss)
HTTP vs MQTT performance tests
Credit to: https://flespi.com/blog/http-vs-mqtt-performance-tests
1K Messages Bytes TransmittedMosquitto MQTT
Client
MQTT over SSL
1 Publish per msg
283.743 5.911
HTTPS
1 POST per msg
15.373.263 115.669
HTTPS
1 POST with 1000
msg
20.515 0.307
Conclusion: MQTTS is 20 times faster and requires 50 times less traffic on the task of
posting consistent time-valuable data.
Conclusion
●Be wise to choose your protocol, there is no One Size Fits All
●HTTP best for one way transmission (client-to-server)
Websocket best for full-duplex persistent connection in browser
MQTT best for persistent connection in IoT
●Many other message broker you can try: AMQP, Kafka, etc.
They best on their own purpose.
Ready to Play with IoT?
●No Undo
●Unseen
●Broken = Start
from Beginning
●Very Fun!
Thanks!
Any questions?
You can find me at @tegarimansyah
Get slide and code:
https://github.com/tegarimansyah/presentation/tree/PyCon-ID-2018