Difference between revisions of "Component: MQTT Client (Comms: IoT/Cloud)"
Line 17: | Line 17: | ||
==Component Source Code== | ==Component Source Code== | ||
− | Please click here to download the component source project: [https://www.flowcode.co.uk/wiki/componentsource/ | + | Please click here to download the component source project: [https://www.flowcode.co.uk/wiki/componentsource/FC_Comp_Source_temp/MQTT_Client.fcfx FC_Comp_Source_temp/MQTT_Client.fcfx] |
− | Please click here to view the component source code (Beta): [https://www.flowcode.co.uk/FlowchartView/?wfile=componentsource/ | + | Please click here to view the component source code (Beta): [https://www.flowcode.co.uk/FlowchartView/?wfile=componentsource/FC_Comp_Source_temp/MQTT_Client.fcfx FC_Comp_Source_temp/MQTT_Client.fcfx] |
==Detailed description== | ==Detailed description== | ||
Line 127: | Line 127: | ||
Click here for instructions on creating your own [[Raspberry_Pi_MQTT_Broker|Raspberry Pi MQTT Broker]]. | Click here for instructions on creating your own [[Raspberry_Pi_MQTT_Broker|Raspberry Pi MQTT Broker]]. | ||
+ | |||
+ | |||
Line 135: | Line 137: | ||
==Macro reference== | ==Macro reference== | ||
− | === | + | ===Connect=== |
{| class="wikitable" style="width:60%; background-color:#FFFFFF;" | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
|- | |- | ||
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
− | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | ''' | + | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Connect''' |
|- | |- | ||
− | | colspan="2" | | + | | colspan="2" | Connect to the MQTT Server. Returns the connected state. 0 if not connected, 1 if successful connection, or already connected. |
|- | |- | ||
|- | |- | ||
− | | width="10%" align="center" | [[File:Fc9- | + | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE |
− | | width="90%" | | + | | width="90%" style="border-top: 2px solid #000;" | ''Return'' |
+ | |} | ||
+ | |||
+ | |||
+ | ===Disconnect=== | ||
+ | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
|- | |- | ||
− | | | + | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] |
+ | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Disconnect''' | ||
|- | |- | ||
− | | | + | | colspan="2" | Disconnects from the MQTT server and the network |
− | |||
|- | |- | ||
− | |||
|- | |- | ||
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE | ||
Line 178: | Line 184: | ||
− | === | + | ===GetPayload=== |
{| class="wikitable" style="width:60%; background-color:#FFFFFF;" | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
|- | |- | ||
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
− | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | ''' | + | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''GetPayload''' |
+ | |- | ||
+ | | colspan="2" | Get the Payload of the last received (Read) packet. Returns the number of bytes for the Payload | ||
+ | |- | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-string-icon.png]] - STRING | ||
+ | | width="90%" | Payload | ||
|- | |- | ||
− | | colspan="2" | | + | | colspan="2" | |
|- | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE | ||
+ | | width="90%" | Size | ||
+ | |- | ||
+ | | colspan="2" | Byte count the Payload buffer | ||
|- | |- | ||
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE | ||
Line 192: | Line 208: | ||
− | === | + | ===GetTopic=== |
{| class="wikitable" style="width:60%; background-color:#FFFFFF;" | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
|- | |- | ||
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
− | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | ''' | + | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''GetTopic''' |
|- | |- | ||
− | | colspan="2" | | + | | colspan="2" | Get the Topic of the last received (Read) packet. Returns the number of bytes for the Topic |
|- | |- | ||
|- | |- | ||
Line 206: | Line 222: | ||
| colspan="2" | | | colspan="2" | | ||
|- | |- | ||
− | | width="10%" align="center" | [[File:Fc9- | + | | width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE |
− | | width="90%" | | + | | width="90%" | Size |
|- | |- | ||
− | | colspan="2" | | + | | colspan="2" | Byte count the Topic buffer |
|- | |- | ||
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE | ||
Line 216: | Line 232: | ||
− | === | + | ===Initialise=== |
{| class="wikitable" style="width:60%; background-color:#FFFFFF;" | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
|- | |- | ||
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
− | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | ''' | + | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Initialise''' |
|- | |- | ||
− | | colspan="2" | | + | | colspan="2" | |
|- | |- | ||
|- | |- | ||
− | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9- | + | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID |
| width="90%" style="border-top: 2px solid #000;" | ''Return'' | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
|} | |} | ||
− | === | + | ===LastError=== |
{| class="wikitable" style="width:60%; background-color:#FFFFFF;" | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
|- | |- | ||
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
− | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | ''' | + | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''LastError''' |
|- | |- | ||
− | | colspan="2" | | + | | colspan="2" | Returns the last error |
|- | |- | ||
|- | |- | ||
− | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9- | + | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE |
| width="90%" style="border-top: 2px solid #000;" | ''Return'' | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
|} | |} | ||
− | === | + | ===Ping=== |
{| class="wikitable" style="width:60%; background-color:#FFFFFF;" | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
|- | |- | ||
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
− | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | ''' | + | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Ping''' |
|- | |- | ||
− | | colspan="2" | | + | | colspan="2" | Ping packet is sent to the Server and checks for a reply. Returns non-zero value if successful |
|- | |- | ||
|- | |- | ||
Line 258: | Line 274: | ||
− | === | + | ===Publish=== |
{| class="wikitable" style="width:60%; background-color:#FFFFFF;" | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
|- | |- | ||
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
− | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | ''' | + | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Publish''' |
+ | |- | ||
+ | | colspan="2" | Publish data to the server (broker) Returns non-zero if successful | ||
+ | |- | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-string-icon.png]] - STRING | ||
+ | | width="90%" | Topic | ||
+ | |- | ||
+ | | colspan="2" | | ||
|- | |- | ||
− | | | + | | width="10%" align="center" | [[File:Fc9-string-icon.png]] - STRING |
+ | | width="90%" | Payload | ||
|- | |- | ||
+ | | colspan="2" | | ||
|- | |- | ||
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE | ||
Line 272: | Line 298: | ||
− | === | + | ===Read=== |
{| class="wikitable" style="width:60%; background-color:#FFFFFF;" | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
|- | |- | ||
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
− | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | ''' | + | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Read''' |
|- | |- | ||
− | | colspan="2" | | + | | colspan="2" | Read incoming data. Returns non-zero if packet received. Use GetTopic and GetPayload to read the contents. |
|- | |- | ||
|- | |- | ||
− | + | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u16-icon.png]] - UINT | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9- | ||
| width="90%" style="border-top: 2px solid #000;" | ''Return'' | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
|} | |} | ||
Line 330: | Line 346: | ||
|- | |- | ||
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
| width="90%" style="border-top: 2px solid #000;" | ''Return'' | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
|} | |} |
Revision as of 12:02, 3 February 2023
Author | Matrix TSL |
Version | 1.1 |
Category | Comms: IoT/Cloud |
Contents
MQTT Client component
A component providing access to MQTT IoT client. The client can connect to a MQTT server such as ThingSpeak. Allowing IoT type data to be published and read back.
Component Source Code
Please click here to download the component source project: FC_Comp_Source_temp/MQTT_Client.fcfx
Please click here to view the component source code (Beta): FC_Comp_Source_temp/MQTT_Client.fcfx
Detailed description
No detailed description exists yet for this component
Examples
The MQTT component requires connection to a Network Comms component via the "Network Component" property, to provide the bridge for simulated TCP/IP communication.
The Network Comms component can then be linked to an embedded TCP/IP component to provide embedded TCP/IP support.
Here is a typical setup for using MQTT on a Raspberry Pi.
Local Weather
A simple example demonstrating how to use MQTT with Flowcode SCADA to get the local weather conditions.
The example shows temperatures from Halifax in the UK and from Sydney in Australia.
Publish
Raspberry Pi
Here we have an embedded Raspberry Pi project connected to an I2C Sensor, the sensor is sampled and the data is published to a MQTT server.
ESP8266 Module
Here we have an embedded project using an ESP8266 wifi module, an analogue input is sampled and the data is published to a MQTT server.
Subscribe
ESP8266 Module
Here we subscribe to a topic and receive it back into Flowcode embedded using an ESP8266 module.
Flowcode App Developer
Here we subscribe to a topic and receive it back into Flowcode App Developer.
Making your own Raspberry Pi based MQTT Broker
Click here for instructions on creating your own Raspberry Pi MQTT Broker.
Macro reference
Connect
Connect | |
Connect to the MQTT Server. Returns the connected state. 0 if not connected, 1 if successful connection, or already connected. | |
- BYTE | Return |
Disconnect
Disconnect | |
Disconnects from the MQTT server and the network | |
- BYTE | Return |
ErrorAsString
ErrorAsString | |
- BYTE | Error |
- STRING | Return |
GetPayload
GetPayload | |
Get the Payload of the last received (Read) packet. Returns the number of bytes for the Payload | |
- STRING | Payload |
- BYTE | Size |
Byte count the Payload buffer | |
- BYTE | Return |
GetTopic
GetTopic | |
Get the Topic of the last received (Read) packet. Returns the number of bytes for the Topic | |
- STRING | Topic |
- BYTE | Size |
Byte count the Topic buffer | |
- BYTE | Return |
Initialise
Initialise | |
- VOID | Return |
LastError
LastError | |
Returns the last error | |
- BYTE | Return |
Ping
Ping | |
Ping packet is sent to the Server and checks for a reply. Returns non-zero value if successful | |
- BYTE | Return |
Publish
Publish | |
Publish data to the server (broker) Returns non-zero if successful | |
- STRING | Topic |
- STRING | Payload |
- BYTE | Return |
Read
Read | |
Read incoming data. Returns non-zero if packet received. Use GetTopic and GetPayload to read the contents. | |
- UINT | Return |
Subscribe
Subscribe | |
Subscribe to a Topic. Must be Connected first Returns non-zero if successful | |
- STRING | Topic |
- BYTE | Return |
Unsubscribe
Unsubscribe | |
Unsubscribe from a Topic. Must be Connected first Returns non-zero if successful | |
- STRING | Topic |
- BYTE | Return |