Component: MQTT Client (Comms: IoT/Cloud)
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 for the component source code: 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.
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.
Downloadable macro reference
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 |
ErrorAsString | |
- BYTE | Error |
- STRING | Return |
Connect | |
Connect to the MQTT Server. Returns the connected state. 0 if not connected, 1 if successful connection, or already connected. | |
- BYTE | Return |
Publish | |
Publish data to the server (broker) Returns non-zero if successful | |
- STRING | Topic |
- STRING | Payload |
- BYTE | Return |
LastError | |
Returns the last error | |
- BYTE | Return |
Read | |
Read incoming data. Returns non-zero if packet received. Use GetTopic and GetPayload to read the contents. | |
- UINT | Return |
Disconnect | |
Disconnects from the MQTT server and the network | |
- BYTE | Return |
Ping | |
Ping packet is sent to the Server and checks for a reply. Returns non-zero value if successful | |
- BYTE | Return |
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 |
Subscribe | |
Subscribe to a Topic. Must be Connected first Returns non-zero if successful | |
- STRING | Topic |
- BYTE | Return |
Unsubscribe | |
Unsubscribe from a Topic. Must be Connected first Returns non-zero if successful | |
- STRING | Topic |
- BYTE | Return |
Initialise | |
- VOID | Return |