GSM MQTT Library : Complete MQTT v3.1 Stack Implementation

MQTT Library for SIM800 GSM Modem is available at ElementzTechBlog , ElementzGithubRepository , ElementzOnline

[u]Functionalities:[/u]

Auto connect Automatically connect to TCP and to MQTT server. connect function This function can be used to connect your client to MQTT broker. Use only if you do not use Auto connect functionality. Optionally you can use username, password, WILL topic and WILL Message. OnConnect CallBack function This call back function is called when MQTT connection is established. You can call subscription and publish functions inside it (according to your need). publish function This function can be used to publish messages to different topics. You can select QoS levels and RETAIN flag according to your need. subscribe function This function can be used to subscribe messages from different topics. OnMessage CallBack function This callback function is called when messages are received from subscribed topics Topic, TopicLength, Message, MessageLength are the arguments of OnMessage callback function. Inside this, you can write your custom code. unsubscribe function This function can be used to unsubscribe from a previously subscribed topic. disconnect function This function can be used to disconnect your client from MQTT broker. Keep Alive You can specify your KeepAlive duration while initializing. Ping requests are sent and received automatically.

Great Work

I don’t understand how this library works. I want to post a message on a test topic , but I don’t know how to call the functions in the code…

My code looks like this:

#include “GSM_MQTT.h”
#include <SoftwareSerial.h>
String MQTT_HOST = “test.mosquitto.org”;
/*
MQTT host address
/
String MQTT_PORT = “1883”;
/

MQTT port
/
SoftwareSerial mySerial(18, 19); // RX, TX
/

Software Serial through which mqtt events log is printed at 9600 baud rate
*/
void GSM_MQTT::AutoConnect(void)
{
connect(“Gabriel”, 0, 0, “”, “”, 1, 0, 0, 0, “”, “”);

}
void GSM_MQTT::OnConnect(void)
{

publish(0, 0, 0, _generateMessageID(), “;Test”, “Hello everybody”);

}
void GSM_MQTT::OnMessage(char *Topic, int TopicLength, char *Message, int MessageLength)
{
mySerial.println(TopicLength);
mySerial.println(Topic);
mySerial.println(MessageLength);
mySerial.println(Message);

}
GSM_MQTT MQTT(20);
/*
20 is the keepalive duration in seconds
*/

void setup()
{
// initialize mqtt:
// GSM modem should be connected to Hardware Serial
// index =0;
MQTT.begin();
Serial.begin(9600);

}
void loop()
{

AutoConnect();

if (MQTT.available())
{
OnConnect();

}

MQTT.processing();
}

I’m using a mega with icomsat v 1.1 just like this: http://competefornothing.com/wp-content/uploads/2012/10/wpid-DSC09936.jpg