MQTTClient
Dependents: IoTGateway_Basic test
MQTTClient Class Reference
#include <MQTTClient.h>
Public Member Functions | |
MQTTClient () | |
Default Constructor. | |
~MQTTClient () | |
Default Destructor. | |
MQTTClient (IpAddr server, int port, void(*callback)(char *, char *)) | |
Alternative Constructor with parameters. | |
void | init (IpAddr *server, int port, void(*callback)(char *, char *)) |
MQTT initialisation method. | |
void | init (IpAddr *server, int port, char *userName, char *password, void(*callback)(char *, char *)) |
A brief description of the function foo. | |
int | connect (char *) |
Open TCP port, connect to server on given IP address. | |
void | disconnect () |
Disconnect from server. | |
int | publish (char *, char *) |
Publish a message on a topic. | |
int | subscribe (char *) |
Subscribe to a topic. | |
void | live () |
Send heartbeat/keep-alive message. |
Detailed Description
Based on MQTTClient code from http://ceit.uq.edu.au/content/mqttclient-mbed-version-20 A simple MQTT client for mbed, version 2.0 By Yilun FAN, , 2011
Bug fixes and additions by Andrew Lindsay (andrew [at] thiseldo [dot] co [dot] uk)
Definition at line 50 of file MQTTClient.h.
Constructor & Destructor Documentation
MQTTClient | ( | ) |
Default Constructor.
Definition at line 32 of file MQTTClient.cpp.
~MQTTClient | ( | ) |
Default Destructor.
Definition at line 36 of file MQTTClient.cpp.
MQTTClient | ( | IpAddr | server, |
int | port, | ||
void(*)(char *, char *) | callback | ||
) |
Alternative Constructor with parameters.
Allow object to be constructed with minimum parameters.
- Parameters:
-
server The IP address of the server to connect to port The TCP/IP port on the server to connect to callback Callback function to handle subscription to topics
Definition at line 46 of file MQTTClient.cpp.
Member Function Documentation
int connect | ( | char * | id ) |
Open TCP port, connect to server on given IP address.
- Parameters:
-
id The client name shown on MQTT server.
- Returns:
- -1: If connect to server failed. -2: Failed to open session on server. 1: Connection accessed.
Definition at line 173 of file MQTTClient.cpp.
void disconnect | ( | ) |
Disconnect from server.
Definition at line 256 of file MQTTClient.cpp.
void init | ( | IpAddr * | server, |
int | port, | ||
char * | userName, | ||
char * | password, | ||
void(*)(char *, char *) | callback | ||
) |
A brief description of the function foo.
More details about the function goes here and here
- Parameters:
-
server The IP address of the server to connect to port The TCP/IP port on the server to connect to userName Pointer to username string, zero terminated. Null for not used password Pointer to password string, zero terminated. Null for not used callback Callback function to handle subscription to topics
Definition at line 88 of file MQTTClient.cpp.
void init | ( | IpAddr * | server, |
int | port, | ||
void(*)(char *, char *) | callback | ||
) |
MQTT initialisation method.
Used when default constructor used and need to specify parameters at runtime
- Parameters:
-
server The IP address of the server to connect to port The TCP/IP port on the server to connect to callback Callback function to handle subscription to topics
Definition at line 66 of file MQTTClient.cpp.
void live | ( | ) |
Send heartbeat/keep-alive message.
Definition at line 372 of file MQTTClient.cpp.
int publish | ( | char * | pub_topic, |
char * | msg | ||
) |
Publish a message on a topic.
- Parameters:
-
pub_topic The topic name the massage will be publish on. msg The massage to be published.
- Returns:
- -1: Failed to publish message. 1: Publish sucessed.
Definition at line 233 of file MQTTClient.cpp.
int subscribe | ( | char * | topic ) |
Subscribe to a topic.
- Parameters:
-
topic The topic name to be subscribed.
- Returns:
- -1: Failed to subscribe to topic. 1: Subscribe sucessed.
Definition at line 341 of file MQTTClient.cpp.
Generated on Fri Jul 15 2022 10:44:02 by 1.7.2