With the rapid rise of IOT Technology, the IOT protocols such as MQTT & CoAP are being deployed on various platforms. CoAP protocol works based on the connection-less UDP protocol, thus requiring less resources to implement the same.
MQTT works on top of TCP which is a connection based protocol. Even though the implementation of TCP is more complex compared to UDP, there is an inclination towards usage of MQTT in IOT environment, due to its advantages like reliability, one to many and many to many communications etc.
TCP is a connection based protocol, involving multiple IP packet transactions for establishing & maintaining the connection. Thus the major complexity with respect to implementing MQTT protocol is having a TCP stack which can take care of TCP connection. Once the TCP connection is established, MQTT can be easily implemented on top of TCP with the set of pre-defined MQTT Command set.
Most of the IOT devices will have network connection using any one of Ethernet, WiFi, GSM, BT/BLE or custom/Standard GHz Wireless connection. Below are some of the approaches that can be used for the implementation of MQTT in these devices.
- Have the TCP stack running on the micro-processor or micro-controller of the IOT device itself. This approach is not suitable for IOT devices with low end micro-controller due to limited resources.
- If the IOT device uses the WiFi/GSM, then TCP stack implementation can be removed from micro-controller by using readily available WiFi/GSM modules with inbuilt TCP stack. With this approach, micro-controller can send / receive the MQTT packets & the WiFi/GSM module can take care of the TCP connection & packetizing the MQTT data into TCP packets.
- IOT devices with BT/BLE will invariably connect to a smartphone / tablet which will take care of sending data to MQTT server. Thus IOT device can send the raw data through BT/BLE & generation of both MQTT & TCP packets can be handled by Software application running on the Smartphone / Tablet.
- Generally, IOT devices which uses Custom GHz Wireless network or dedicated IOT Wireless networks such as LoRA / Sigfox will have a wireless gateway, which collects the data from multiple wireless nodes (i.e. IOT devices) & sends to the MQTT server. With this architecture, the TCP & MQTT implementations can be present at the wireless gateway & all the wireless nodes can send the raw data to the gateway.
By using these approaches, complexity of MQTT implementation can be moved away from the micro-controller, so that micro-controller resources can be used more effectively.