Difference between revisions of "Component: MQTT Client (Comms: System)"

From Flowcode Help
Jump to navigationJump to search
Line 27: Line 27:
  
 
[[File:MQTT_Connection.jpg]]
 
[[File:MQTT_Connection.jpg]]
 +
 +
 +
Here is a typical setup for using MQTT on a Raspberry Pi.
  
  

Revision as of 09:09, 11 September 2019


Author Matrix TSL
Version 1.0 (Release)
Category Comms: System


Image 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.

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 and Subscribe

A simple example to combine together an embedded device and a SCADA application.

Firstly 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

Next we subscribe to the data and receive it back into Flowcode SCADA.

FC6 Icon.png SCADA MQTT

Downloadable macro reference

GetTopic

Get the Topic of the last received (Read) packet.

Returns the number of bytes for the Topic

Parameters

<- STRING Topic
This parameter may be returned back to the caller
BYTE Size
Byte count the Topic buffer


Return value

BYTE


ErrorAsString

No additional information


Parameters

BYTE Error


Return value

STRING


Connect

Connect to the MQTT Server.

Returns the connected state.

0 if not connected, 1 if successful connection, or already connected.

Parameters

This macro has no parameters


Return value

BYTE


Publish

Publish data to the server (broker)

Returns non-zero if successful

Parameters

<- STRING Topic
This parameter may be returned back to the caller
<- STRING Payload
This parameter may be returned back to the caller


Return value

BYTE


LastError

Returns the last error

Parameters

This macro has no parameters


Return value

BYTE


Read

Read incoming data.

Returns non-zero if packet received.

Use GetTopic and GetPayload to read the contents.

Parameters

This macro has no parameters


Return value

UINT


Disconnect

Disconnects from the MQTT server and the network

Parameters

This macro has no parameters


Return value

BYTE


Ping

Ping packet is sent to the Server and checks for a reply.

Returns non-zero value if successful

Parameters

This macro has no parameters


Return value

BYTE


GetPayload

Get the Payload of the last received (Read) packet.

Returns the number of bytes for the Payload

Parameters

<- STRING Payload
This parameter may be returned back to the caller
BYTE Size
Byte count the Payload buffer


Return value

BYTE


Subscribe

Subscribe to a Topic.

Must be Connected first

Returns non-zero if successful

Parameters

<- STRING Topic
This parameter may be returned back to the caller


Return value

BYTE


Unsubscribe

Unsubscribe from a Topic.

Must be Connected first

Returns non-zero if successful

Parameters

<- STRING Topic
This parameter may be returned back to the caller


Return value

BYTE


Initialise

No additional information


Parameters

This macro has no parameters


Return value

This call does not return a value


Simulation macro reference

This component does not contain any simulation macros


Property reference

Host

This property is of type Line of text and can be referenced with the variable name HOST.

Address of MQTT Broker

Port

This property is of type Unsigned integer and can be referenced with the variable name PORT.

Port used by MQTT Broker

Client identifier

This property is of type Line of text and can be referenced with the variable name CLIENT.

Client identifier

Network Timeout

This property is of type Unsigned integer and can be referenced with the variable name TIMEOUT.

Maximum time in mS to wait for network responses

Keep Alive

This property is of type Unsigned integer and can be referenced with the variable name 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.

Network Component

This property is of type Panel object and can be referenced with the variable name NETWORK_COMPONENT.

Pointer to the network communications component providing TCP simulation and abstraction for embedded

TCP modules.