## 5 IoT Platform Communication with IoT Sensors and Applications  
IoT devices and sensors communicate with IoT platforms through their layers using protocols. At each layer, a set of communication protocols is defined. Each protocol dictates the rules on how data are sent through the layer at which the protocol is implemented. With the help of the IoT protocols, the messages are read and understood among the devices and services. For different IoT scenarios and use cases, different protocols are designed and optimized. It is important to use the right protocol for each IoT use case. Depending on the architecture of each layer, the types of protocols differ. A map of the various IoT layers that communicate with each other by sending and receiving data  
Figure 8: Proposed models of IoT architecture layers. The three-layer architecture on the left can be divided into sublayers. The most recent architectural designs propose five layers. is given in the systems interconnection (OSI) model. The model shows how the data flow within the layers of IoT, meaning the communication types are based on the sending and receiving points or layers (for instance device-to-device, device-to-gateway, and so on). Figure 9 shows the major IoT protocols by layer [39; 40]. The most used protocols at the application layer are the Constrained Application Protocol (CoAP); Message Queue Telemetry Transport (MQTT) for M2M lightweight communication in remote locations with low bandwidths; the Advanced Message Queuing Protocol (AMQP), which allows interoperability between messaging middleware; and the Data Distribution Service (DDS) as a peer-to-peer protocol, which is run on small devices and connects to high-performance networks. The dominant protocol for the majority of the Internet is the Transmission Control Protocol (TCP) at the transport layer and the User Datagram Protocol (UDP), which enables peer-to-peer communication and has improved data transfer rates over TCP, making it the best option for lossless data transmission. At the network layer, IoT applications use IPv4, while recent operations regarding traffic routing have used IPv6 as well as the 6 LoWPAN protocol for the best results in low-power devices. IEEE 802.15.4 at the data link layer is a standard option for radio communication in low-power mode. IEEE 802.15.4 is used with standards such as Zigbee and 6 LoWPAN in embedded systems. Additionally, some LPWAN networks enabling long-distance communication (500 m to over 10 km) are implemented at this layer. The physical layer is the layer of devices where Bluetooth Low-Energy (BLE) dramatically reduces the power consumption, where wired connections over Ethernet are less expensive and provide fast connections and low latency rates, and the use of wireless LTE broadband increases the capacity and speed of the wireless networks. Radio frequency identification (RFID) is also used at the link layer, which utilizes electromagnetic fields to track otherwise unpowered electronic tags. WiFi/802.11 is a widely spread standard at this layer too. Additionally, the key messaging protocols, MQTT and CoAP, are usually the first choices for IoT purposes, as the needs of constrained devices are considered in them (such as small message sizes and overheads) [41]. Figure 9: IoT protocols by layer. In order to explain the two mentioned protocols, one must understand the IoT communication models. Basically, there are four communication models:  
* Request-response, in which the client sends a request to the server and the server, after fetching and processing the data, sends the response back to the client;
* Publish-subscribe, involving three major roles: data publishers, brokers, and data consumers. The publishers, as the data sources, send the data to the brokers, who manage topics to which the consumers are subscribed. The publishers are not aware of the consumers but are aware of the topics.