Component: MQTT Client (Comms: IoT/Cloud)

From Flowcode Help
Jump to navigationJump to search
Author Matrix TSL
Version 1.1
Category Comms: IoT/Cloud


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_MQTT_Client.fcfx

Please click here to view the component source code (Beta): FC_Comp_Source_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.

MQTT Connection.jpg

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.

FC6 Icon.png SCADA BBC TEMPERATURES


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.

FC6 Icon.png RPI3 MQTT IOT EBM016


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.

FC6 Icon.png MQTT IOT ESP8266


Subscribe

ESP8266 Module

Here we subscribe to a topic and receive it back into Flowcode embedded using an ESP8266 module.

FC6 Icon.png Subscribe ESP8266 MQTT


Flowcode App Developer

Here we subscribe to a topic and receive it back into Flowcode App Developer.

FC6 Icon.png Subscribe App Developer MQTT


Making your own Raspberry Pi based MQTT Broker

Click here for instructions on creating your own Raspberry Pi MQTT Broker.








Macro reference

Connect

Fc9-comp-macro.png Connect
Connect to the MQTT Server. Returns the connected state. 0 if not connected, 1 if successful connection, or already connected.  
Fc9-u8-icon.png - BYTE Return


ConnectTo

Fc9-comp-macro.png ConnectTo
Connect to a variable MQTT Server, overriding the Host and Port properties. Returns the connected state. 0 if not connected, 1 if successful connection, or already connected. 
Fc9-string-icon.png - STRING Host
 
Fc9-u16-icon.png - UINT Port
 
Fc9-string-icon.png - STRING ClientID
Client identifier name - must be unique on server 
Fc9-u8-icon.png - BYTE Return


Disconnect

Fc9-comp-macro.png Disconnect
Disconnects from the MQTT server and the network 
Fc9-u8-icon.png - BYTE Return


ErrorAsString

Fc9-comp-macro.png ErrorAsString
 
Fc9-u8-icon.png - BYTE Error
 
Fc9-string-icon.png - STRING Return


GetPayload

Fc9-comp-macro.png GetPayload
Get the Payload of the last received (Read) packet. Returns the number of bytes for the Payload 
Fc9-string-icon.png - STRING Payload
 
Fc9-u8-icon.png - BYTE Size
Byte count the Payload buffer 
Fc9-u8-icon.png - BYTE Return


GetTopic

Fc9-comp-macro.png GetTopic
Get the Topic of the last received (Read) packet. Returns the number of bytes for the Topic 
Fc9-string-icon.png - STRING Topic
 
Fc9-u8-icon.png - BYTE Size
Byte count the Topic buffer 
Fc9-u8-icon.png - BYTE Return


Initialise

Fc9-comp-macro.png Initialise
 
Fc9-void-icon.png - VOID Return


LastError

Fc9-comp-macro.png LastError
Returns the last error 
Fc9-u8-icon.png - BYTE Return


Ping

Fc9-comp-macro.png Ping
Ping packet is sent to the Server and checks for a reply. Returns non-zero value if successful  
Fc9-u8-icon.png - BYTE Return


Publish

Fc9-comp-macro.png Publish
Publish data to the server (broker) Returns non-zero if successful 
Fc9-string-icon.png - STRING Topic
 
Fc9-string-icon.png - STRING Payload
 
Fc9-u8-icon.png - BYTE Return


Read

Fc9-comp-macro.png Read
Read incoming data. Returns non-zero if packet received. Use GetTopic and GetPayload to read the contents. 
Fc9-u16-icon.png - UINT Return


Subscribe

Fc9-comp-macro.png Subscribe
Subscribe to a Topic. Must be Connected first Returns non-zero if successful  
Fc9-string-icon.png - STRING Topic
 
Fc9-u8-icon.png - BYTE Return


Unsubscribe

Fc9-comp-macro.png Unsubscribe
Unsubscribe from a Topic. Must be Connected first Returns non-zero if successful  
Fc9-string-icon.png - STRING Topic
 
Fc9-u8-icon.png - BYTE Return


Property reference

Fc9-prop-icon.png Properties
Fc9-type-16-icon.png LinkTo
 
Fc9-type-10-icon.png Host
Address of MQTT Broker Can be an IP Address or URL (URL only supported by some hardware platforms) 
Fc9-type-21-icon.png Port
Port used by MQTT Broker Default 1883 for unencrypted access and 8883 for encrypted access. 
Fc9-type-10-icon.png Client identifier
Client identifier (Maximum length 20 characters) Must be unique to the broker. 
Fc9-type-21-icon.png Network Timeout
Maximum time in mS to wait for network responses 
Fc9-type-21-icon.png Read Timeout
Amount of time in ms to wait for incoming messages. 
Fc9-type-21-icon.png Keep Alive
The Keep Alive is the maximum time interval that is permitted to elapse between the point at which the Client finishes transmitting one Control Packet and the point it starts sending the next, measured in seconds. 
Fc9-type-16-icon.png Authentication
Selects if the broker is open or if the broker requires a username and password.