Difference between revisions of "Component: MQTT Client ( Comms)"
(Created page with "{| style="width:50%" |- | width="20%" style="color:gray;" | Author | MatrixTSL |- | width="20%" style="color:gray;" | Version | 0.1 |- | width="20%" style="color:gray;...") |
|||
(4 intermediate revisions by 2 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== | ||
− | + | ===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. | ||
+ | |||
+ | {{Fcfile|WebApp_MQTT_Client_Demo.fcsx|MQTT Web App Client Demo}} | ||
+ | |||
+ | |||
+ | Here is a corresponding ESP32 project that samples a temperature and humidity sensor and sends the data. | ||
+ | |||
+ | {{Fcfile|ESP_MQTT_Client_TempHumidityDemo.fcfx|MQTT ESP32 Client Demo}} | ||
+ | |||
+ | |||
+ | ===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. | ||
+ | |||
+ | {{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/example/index.htm | ||
+ | |||
+ | |||
==Macro reference== | ==Macro reference== |
Latest revision as of 16:36, 11 December 2023
Author | MatrixTSL |
Version | 0.1 |
Category | Comms |
Contents
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