Sending sensor data through MQTT Publish
In Chapter 5, we discussed the MQTT protocol and its Publish/Subscribe model. The following figure describes how an MQTT broker (such as AWS IoT Core) interacts with an MQTT Publisher or an MQTT Subscriber (such as IoT devices). In the previous chapter, we established a TLS connection between the MQTT Publisher (ESP32) and the MQTT broker (AWS IoT Core).
Once the TLS connection is successfully set up, the next step is for the IoT device, the MQTT Publisher, to encapsulate sensor payload data in JSON format with a declared topic to send to the MQTT broker, AWS IoT Core.
Figure 14.1 – MQTT flow
The following definitions pertain to topic, payload, and JSON, terms used in the MQTT protocol flow:
- Topic: This is typically a string. In the case of our project, it is formatted as
deviceID/pub
to distinguish the topic amongst various devices. The uniquedeviceID
value is derived fromESP.getEfuseMac()
,...