MQTTClient

Dependents:   IoTGateway_Basic test

Embed: (wiki syntax)

« Back to documentation index

MQTTClient Class Reference

MQTTClient Class Reference

MQTTClient. More...

#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

MQTTClient.

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:
serverThe IP address of the server to connect to
portThe TCP/IP port on the server to connect to
callbackCallback 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:
idThe 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:
serverThe IP address of the server to connect to
portThe TCP/IP port on the server to connect to
userNamePointer to username string, zero terminated. Null for not used
passwordPointer to password string, zero terminated. Null for not used
callbackCallback 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:
serverThe IP address of the server to connect to
portThe TCP/IP port on the server to connect to
callbackCallback 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_topicThe topic name the massage will be publish on.
msgThe 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:
topicThe topic name to be subscribed.
Returns:
-1: Failed to subscribe to topic. 1: Subscribe sucessed.

Definition at line 341 of file MQTTClient.cpp.