Component: MQTT Client ( Comms): Difference between revisions
m Text replacement - "width="10%" align="center" style="background-color:#D8C9D8;"" to "width="10%" align="center" class="mtx-class-macrohead"" |
m Text replacement - "width="90%" style="background-color:#D8C9D8; color:#4B008D;"" to "width="90%" class="mtx-class-macrohead"" |
||
| Line 59: | Line 59: | ||
|- | |- | ||
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | | width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | ||
| width="90%" | | width="90%" class="mtx-class-macrohead" | '''Connect''' | ||
|- | |- | ||
| colspan="2" | Connects to the MQTT server (returns false if already connected) | | colspan="2" | Connects to the MQTT server (returns false if already connected) | ||
| Line 73: | Line 73: | ||
|- | |- | ||
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | | width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | ||
| width="90%" | | width="90%" class="mtx-class-macrohead" | '''Disconnect''' | ||
|- | |- | ||
| colspan="2" | Disconnect from the MQTT server (returns false if client is already disconnected) | | colspan="2" | Disconnect from the MQTT server (returns false if client is already disconnected) | ||
| Line 87: | Line 87: | ||
|- | |- | ||
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | | width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | ||
| width="90%" | | width="90%" class="mtx-class-macrohead" | '''GetClientId''' | ||
|- | |- | ||
| colspan="2" | Returns the unique identifier currently used when communicating with the server. | | colspan="2" | Returns the unique identifier currently used when communicating with the server. | ||
| Line 101: | Line 101: | ||
|- | |- | ||
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | | width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | ||
| width="90%" | | width="90%" class="mtx-class-macrohead" | '''Publish''' | ||
|- | |- | ||
| colspan="2" | Publish a message to the MQTT server (returns false in the client is not connected) | | colspan="2" | Publish a message to the MQTT server (returns false in the client is not connected) | ||
| Line 135: | Line 135: | ||
|- | |- | ||
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | | width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | ||
| width="90%" | | width="90%" class="mtx-class-macrohead" | '''PublishBuffer''' | ||
|- | |- | ||
| colspan="2" | Publish an array of bytes to the MQTT server (returns false in the client is not connected) | | colspan="2" | Publish an array of bytes to the MQTT server (returns false in the client is not connected) | ||
| Line 169: | Line 169: | ||
|- | |- | ||
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | | width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | ||
| width="90%" | | width="90%" class="mtx-class-macrohead" | '''Subscribe''' | ||
|- | |- | ||
| colspan="2" | Subscribe to messages from the MQTT server (returns false in the client is not connected) | | colspan="2" | Subscribe to messages from the MQTT server (returns false in the client is not connected) | ||
| Line 198: | Line 198: | ||
|- | |- | ||
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | | width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | ||
| width="90%" | | width="90%" class="mtx-class-macrohead" | '''Unsubscribe''' | ||
|- | |- | ||
| colspan="2" | Unsubscribe from messages from the MQTT server (returns false in the client is not connected) | | colspan="2" | Unsubscribe from messages from the MQTT server (returns false in the client is not connected) | ||
| Line 223: | Line 223: | ||
|- | |- | ||
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-prop-icon.png]] | | width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-prop-icon.png]] | ||
| width="90%" | | width="90%" class="mtx-class-macrohead" | '''Properties''' | ||
|- | |- | ||
|- | |- | ||
Revision as of 14:23, 13 July 2026
| Author | MatrixTSL |
| Version | 0.1 |
| Category | Comms |
MQTT Client component
A component providing access to MQTT IoT client. The client can connect to a MQTT server such as ThingSpeak via WebSockets. Allows IoT type data to be published and read back.
Component Source Code
Please click here to download the component source project: FC_Comp_Source_WEBEXP_MQTT.fcsx
Please click here to view the component source code (Beta): FC_Comp_Source_WEBEXP_MQTT.fcsx
Detailed description
Please note this component currently only supports Web Sockets and must be connected to the Web Socket enabled port of the broker.
Examples
Temperature and Humidity
Here is an example MQTT project showing how to collect data from a remote device using MQTT.
The heater and fan buttons have onclick event macros that encode JSON data and send to a MQTT topic named mtx_demo_switchdata.
The OnMqttConnected event macro subscribes to MQTT topics named mtx_demo_sensedata which contains the embdeeded temperature and humidity data and mtx_demo_switchdata which contains the current fan and heater output states.
Here is a corresponding ESP32 project that samples a temperature and humidity sensor and sends the data.
Temperature and Humidity HTTPS
Here is the temperature and humidity example again but this time set to use HTTPS so that it can be ran from a enabled HTTPS webserver.
MQTT Web App Client HTTPS Demo
An example of this can be seen via the URL: https://flowcode.co.uk/example/index.htm
Macro reference
Connect
| Connect | |
| Connects to the MQTT server (returns false if already connected) | |
| Return | |
Disconnect
| Disconnect | |
| Disconnect from the MQTT server (returns false if client is already disconnected) | |
| Return | |
GetClientId
| GetClientId | |
| Returns the unique identifier currently used when communicating with the server. | |
| Return | |
Publish
PublishBuffer
Subscribe
Unsubscribe