Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Paho » Paho embedded C Client Reconnect Issue(Cannot reconnect to the MQTT Broker after internet connection is lost)
icon9.gif  Paho embedded C Client Reconnect Issue [message #1753671] Wed, 08 February 2017 17:07 Go to next message
Christopher Koch is currently offline Christopher KochFriend
Messages: 1
Registered: February 2017
Junior Member
I am trying to reconnect to the MQTT Broker after a connection to the internet has been lost and then restored. I can reconnect to the Wi-Fi network, as shown by checking the status of my internet connection and confirming the IP address. If internet connection is not lost I can disconnect and reconnect to the MQTT Broker. But when i try to bring the two together I cannot reconnect to the Broker.

I am using the embedded-c client and am using a device that has FreeRTOS and used the CC3100 from TI along with its simplelink stack.

After losing connection to the internet, I tried to disconnect to the broker, this seems to work based on the return code but then I couldn't reconnect to the broker. My thought was that I wasn't actually sending the disconnect to the server. So I waited to disconnect to the broker after I reconnected to the internet, but this time I couldn't disconnect without an error.

After I lose internet connection my system tries to continue to publish data for the next 3 or 4 seconds (1 publish per second) could this be causing an issue? But perhaps I am just not disconnecting and reconnecting correctly for when the internet is lost.

What is the proper way to reconnect to an MQTT broker if the internet connection drops out and then is restored?

here is my disconnect code and my reconnect code:
// Network and Client Configuration
Network n;
Client c;

void clientDisconnect(void)
{
int rc = 0;
rc = MQTTDisconnect(&c);
printf("rc = %d\r\n", rc);
n.disconnect(&n);
}

void clientReconnect(void)
{
// Initialize Variables
int rc = 0;
char* mqttBroker = (char*) CFG_getMqttBrokerName();
int mqttPort = CFG_getMqttPort();

// Setup MQTT Network and MQTT Client
NewNetwork(&n);
rc = ConnectNetwork(&n, mqttBroker, mqttPort);
if (rc != 0) {
printf("Connect Network RC = %d\r\n", rc);
return;
}
MQTTClient(&c, &n, 1000, buf, CLIENT_BUFF_SIZE, readbuf, CLIENT_BUFF_SIZE);

// Configure the MQTT Connection Data
MQTTPacket_connectData data = MQTTPacket_connectData_initializer;
data.willFlag = 0;
data.MQTTVersion = 3;
data.clientID.cstring = (char*) CFG_getMqttClientId();
data.keepAliveInterval = 100;
data.cleansession = 1;

printf("Connecting to %s %d\r\n", mqttBroker, mqttPort);

// Connect to the MQTT Broker
rc = MQTTConnect(&c, &data);

if (rc != 0) {
printf("MQTTConnect Return Code = %d\r\n", rc);
return;
}
}
Re: Paho embedded C Client Reconnect Issue [message #1784556 is a reply to message #1753671] Thu, 29 March 2018 10:12 Go to previous message
Maunik Patel is currently offline Maunik PatelFriend
Messages: 2
Registered: March 2018
Junior Member
Hi
Actually, I don't have answer of your question. Instead, I have a question for you.
It seems like you already have gone through the steps, in which I am having problems.
Hoping to get help from here.
Here are my doubts:
.
1. How to install this library on Ubuntu16.04? (I read the README.md in source of the library, but somehow I am confused)
2. How to compile an application using this library? (please provide steps)
.
One more thing.
I want my Beagle Bone Black (BBB) to send some data to a cloud service, using MQTT protocol.
For that,
3. which paho-MQTT library should I use ?
- Paho-MQTT-C Client OR Paho-MQTT-Embedded-C Client (I think it should be Embedded Client)
4. If it is Embedded-C client, where should I install it ?
- on my Ubuntu16.04 PC OR on BBB itself ?
5. If it is on BBB, is there any way to cross compile it for BBB, from Ubuntu16.04? (to save memory of BBB)
.
If you can't answer all the questions, please try to answer at least question 1 and 2.

Thanks and all the best for your project...

[Updated on: Thu, 29 March 2018 10:16]

Report message to a moderator

Previous Topic:Paho MQTT
Next Topic:Eclipse network data usage
Goto Forum:
  


Current Time: Fri Apr 26 03:19:17 GMT 2024

Powered by FUDForum. Page generated in 0.03203 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top