PubSubClient.h
For details see PubSubClient.h
By default handles packets size to 128
I tested this in Arduino IDE and it does not work with #define , you need to change the PubSubClient.h file for every different use :(
To over ride this this edit PubSubClient.h
#define MQTT_MAX_PACKET_SIZE 512
Note Remember to make sure any buffer(s) you set up have enough size
default keep alive is set to 15 seconds
#define MQTT_KEEPALIVE 20
default keep alive is set to 15 seconds
#define MQTT_SOCKET_TIMEOUT 20
EspMQTTClient
EspMQTTClient Commands
For Wifi and MQTT connection handling (Recommended) :
EspMQTTClient( const char* wifiSsid, const char* wifiPassword, const char* mqttServerIp, const char* mqttUsername, // Omit this parameter to disable MQTT authentification const char* mqttPassword, // Omit this parameter to disable MQTT authentification const char* mqttClientName = "ESP8266", const short mqttServerPort = 1883);
MQTT connection handling only :
EspMQTTClient( const char* mqttServerIp, const short mqttServerPort, // It is mandatory here to allow these constructors to be distinct from those with the Wifi handling parameters const char* mqttUsername, // Omit this parameter to disable MQTT authentification const char* mqttPassword, // Omit this parameter to disable MQTT authentification const char* mqttClientName = "ESP8266");
IMPORTANT : Must be called at each loop() of your sketch
void loop();
Basic functions for MQTT communications.
bool publish(const String &topic, const String &payload, bool retain = false); bool subscribe(const String &topic, MessageReceivedCallback messageReceivedCallback); bool unsubscribe(const String &topic);
Enable the display of usefull debugging messages that will output to serial.
void enableDebuggingMessages(const bool enabled = true)
Enable the web updater. This will host a simple form that will allow firmware upgrade (using, e.g., the .bin file produced by "Export Compiled Binary" in the Arduino IDE's "Sketch" menu). Must be set before the first loop() call.
void enableHTTPWebUpdater(const char* username, const char* password, const char* address = "/"); // this one will set user and password equal to those set for the MQTT connection.void enableHTTPWebUpdater(const char* address = "/");
Enable last will message. Must be set before the first loop() call.
void enableLastWillMessage(const char* topic, const char* message, const bool retain = false);
Connection status
bool isConnected(); // Return true if everything is connected.bool isWifiConnected(); // Return true if WiFi is connected.bool isMqttConnected(); // Return true if MQTT is connected.
Return the number of time onConnectionEstablished has been called since the beginning. Can be useful if you need to monitor the number of times the connection has dropped.
void getConnectionEstablishedCount();
As ESP8266 does not like to be interrupted too long with the delay() function, this function will allow a delayed execution of a function without interrupting the sketch.
void executeDelayed(const long delay, DelayedExecutionCallback callback);
To allow this library to work, you need to implement the onConnectionEstablished() function in your sketch.
void onConnectionEstablished() { // Here you are sure that everything is connected. }
In some special cases, like if you want to handle more than one MQTT connection in the same sketch, you can override this callback to another one for the second MQTT client using this function :
void setOnConnectionEstablishedCallback(ConnectionEstablishedCallback callback);
See exemple "twoMQTTClientHandling.ino" for more details.