Difference between revisions of "Component: MQTT Client (Comms: System)"
(4 intermediate revisions by the same user not shown) | |||
Line 21: | Line 21: | ||
==Examples== | ==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. | ||
+ | |||
+ | [[File:MQTT_Connection.jpg]] | ||
+ | |||
+ | Here is a typical setup for using MQTT on a Raspberry Pi. | ||
+ | |||
===Local Weather=== | ===Local Weather=== | ||
Line 31: | Line 40: | ||
− | ===Publish | + | ===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. | |
{{Fcfile|RPI3_MQTT_IOT_EBM016.fcfx|RPI3 MQTT IOT EBM016}} | {{Fcfile|RPI3_MQTT_IOT_EBM016.fcfx|RPI3 MQTT IOT EBM016}} | ||
− | |||
− | {{Fcfile|SCADA_MQTT.fcsx|SCADA MQTT}} | + | ====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. | ||
+ | |||
+ | {{Fcfile|PublishESP8266.fcfx|MQTT IOT ESP8266}} | ||
+ | |||
+ | |||
+ | ===Subscribe=== | ||
+ | |||
+ | ====ESP8266 Module==== | ||
+ | |||
+ | Here we subscribe to a topic and receive it back into Flowcode embedded using an ESP8266 module. | ||
+ | |||
+ | {{Fcfile|SubscribeESP8266.fcfx|Subscribe ESP8266 MQTT}} | ||
+ | |||
+ | |||
+ | ====Flowcode SCADA==== | ||
+ | |||
+ | Here we subscribe to a topic and receive it back into Flowcode SCADA. | ||
+ | |||
+ | {{Fcfile|SCADA_MQTT.fcsx|Subscribe SCADA MQTT}} | ||
+ | |||
==Downloadable macro reference== | ==Downloadable macro reference== |
Latest revision as of 09:47, 16 October 2020
Author | Matrix TSL |
Version | 1.0 (Release) |
Category | Comms: System |
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.
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 SCADA
Here we subscribe to a topic and receive it back into Flowcode SCADA.
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
ErrorAsString
No additional information
Parameters
- BYTE Error
Return value
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
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
LastError
Returns the last error
Parameters
- This macro has no parameters
Return value
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
Disconnect
Disconnects from the MQTT server and the network
Parameters
- This macro has no parameters
Return value
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
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
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
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
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.