Choose Between REST API and MQTT API
REST is a representational state transfer architectural style designed as a request/response model that communicates over HTTP. MQTT is a publish/subscribe model that runs over TCP/IP sockets or WebSockets. MQTT over WebSockets can be secured with SSL. You can choose to update data to a ThingSpeak™ channel either using a REST GET or POST request or using MQTT Publish method. You retrieve channel data using a REST GET request or MQTT Subscribe.
When to Use REST
In these scenarios, it is useful to use REST calls to update or retrieve data from a ThingSpeak channel.
You need to retrieve any historical data, such as data within a defined time range.
You want to Create Channel, Read Settings, Clear Channel, Delete Channel, or Create Chart.
You need a response for your GET or POST request.
When to Use MQTT
In these scenarios, it is useful to use MQTT to update data to a ThingSpeak channel.
You want to send data quickly with minimum power consumption.
You want to send data when device connectivity is intermittent or you have limited bandwidth.
You want to receive immediate updates of data posted to a channel without polling the server for new messages.
See Also
Write Data | Read Data | Publish to a Channel Field Feed | Publish to a Channel Feed | Subscribe to a Channel Feed | Subscribe to a Channel Field Feed
Related Examples
- Post Temperature Data and Read from Channel
- Prototyping with Sonar Proximity Sensor
- Wireless Network Signal Strength with ESP32 with Arduino IDE
- Remote Sensor Control Using Secure MQTT Publish and Subscribe