Component: MQTT Client ( Comms): Difference between revisions
m Text replacement - "style="background-color:#EAE1EA;"" to "class="mtx-class-propfolder"" |
|||
| (8 intermediate revisions by 3 users not shown) | |||
| Line 23: | Line 23: | ||
==Detailed description== | ==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== | ==Examples== | ||
| Line 49: | Line 49: | ||
{{Fcfile|WebApp_MQTT_Client_Demo_Https.fcsx|MQTT Web App Client HTTPS Demo}} | {{Fcfile|WebApp_MQTT_Client_Demo_Https.fcsx|MQTT Web App Client HTTPS Demo}} | ||
An example of this can be seen via the URL: https://flowcode.co.uk/ | An example of this can be seen via the URL: https://flowcode.co.uk/example/index.htm | ||
==Macro reference== | ==Macro reference== | ||
===Connect=== | ===Connect=== | ||
{| class="wikitable | {| class="mtx-class-macrotable wikitable" | ||
|- | |- | ||
| width="10%" align="center" | | 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 68: | Line 70: | ||
===Disconnect=== | ===Disconnect=== | ||
{| class="wikitable | {| class="mtx-class-macrotable wikitable" | ||
|- | |- | ||
| width="10%" align="center" | | 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 82: | Line 84: | ||
===GetClientId=== | ===GetClientId=== | ||
{| class="wikitable | {| class="mtx-class-macrotable wikitable" | ||
|- | |- | ||
| width="10%" align="center" | | 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 96: | Line 98: | ||
===Publish=== | ===Publish=== | ||
{| class="wikitable | {| class="mtx-class-macrotable wikitable" | ||
|- | |- | ||
| width="10%" align="center" | | 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 130: | Line 132: | ||
===PublishBuffer=== | ===PublishBuffer=== | ||
{| class="wikitable | {| class="mtx-class-macrotable wikitable" | ||
|- | |- | ||
| width="10%" align="center" | | 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 164: | Line 166: | ||
===Subscribe=== | ===Subscribe=== | ||
{| class="wikitable | {| class="mtx-class-macrotable wikitable" | ||
|- | |- | ||
| width="10%" align="center" | | 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 193: | Line 195: | ||
===Unsubscribe=== | ===Unsubscribe=== | ||
{| class="wikitable | {| class="mtx-class-macrotable wikitable" | ||
|- | |- | ||
| width="10%" align="center" | | 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 218: | Line 220: | ||
==Property reference== | ==Property reference== | ||
{| class="wikitable | {| class="mtx-class-macrotable wikitable" | ||
|- | |- | ||
| width="10%" align="center" | | width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-prop-icon.png]] | ||
| width="90%" | | width="90%" class="mtx-class-macrohead" | '''Properties''' | ||
|- | |- | ||
|- | |- | ||
| Line 244: | Line 246: | ||
| colspan="2" | A unique identifier for this client, between 1 and 23 characters in length | | colspan="2" | A unique identifier for this client, between 1 and 23 characters in length | ||
|- | |- | ||
| width="10%" align="center" | | width="10%" align="center" class="mtx-class-propfolder" | [[File:Fc9-conn-icon.png]] | ||
| width="90%" | | width="90%" class="mtx-class-propfolder" | Advanced | ||
|- | |- | ||
|- | |- | ||
| Line 293: | Line 295: | ||
| colspan="2" | Determines if additional logging information is sent to the JavaScript console | | colspan="2" | Determines if additional logging information is sent to the JavaScript console | ||
|- | |- | ||
| width="10%" align="center" | | width="10%" align="center" class="mtx-class-propfolder" | [[File:Fc9-conn-icon.png]] | ||
| width="90%" | | width="90%" class="mtx-class-propfolder" | Callbacks | ||
|- | |- | ||
|- | |- | ||
Latest revision as of 14:37, 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