Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Paho » Multiple subscription Problem(I am not able write code for multiple subscription ; where to write lines for..)
Multiple subscription Problem [message #1797528] Thu, 01 November 2018 08:22
vivek kumar is currently offline vivek kumarFriend
Messages: 6
Registered: October 2018
Junior Member
//.............If anybody can write some demo code for multiple subscriptions & publish.


void connect()
{

char hostname[] = "broker.hivemq.com";
int port = 1883;

Serial.print("Connecting to ");
Serial.print(hostname);
Serial.print(":");
Serial.println(port);

int rc = ipstack.connect(hostname, port);
if (rc != 1)
{
Serial.print("rc from TCP connect is ");
Serial.println(rc);
}

Serial.println("MQTT connecting");


MQTTPacket_connectData data = MQTTPacket_connectData_initializer;
data.MQTTVersion = 3;
data.clientID.cstring = (char*)topicArr[0];

rc = client.connect(data);
if (rc != 0)
{
Serial.print("rc from MQTT connect is ");
Serial.println(rc);
}
Serial.println("MQTT connected");

//..........................................THIS IS I AM WRITING DUE TO WHICH rc = 2 GETTING...................//

rc = client.subscribe(sub[0], MQTT::QOS2, messageArrived);
if (rc != 0)
{

Serial.print("rc from MQTT subscribe is ");
Serial.println(sub[0]);

Serial.println(rc);

}

rc = client.subscribe(sub[1], MQTT::QOS2, messageArrived);
if (rc != 0)
{
Serial.print("rc from MQTT subscribe is ");
Serial.println(sub[1]);

Serial.println(rc);

}



Serial.println("MQTT subscribed");


}

Previous Topic:Not able to simultaneously Publish & Subscribe
Next Topic:Time delayed Condition for MQTT
Goto Forum:
  


Current Time: Fri Apr 26 13:00:11 GMT 2024

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

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

Back to the top