Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Paho » paho client subscribe succeed, but no message received(paho client subscribe succeed, but no message received)
paho client subscribe succeed, but no message received [message #1862399] Fri, 01 December 2023 09:42
abu abu is currently offline abu abuFriend
Messages: 1
Registered: December 2023
Junior Member
Hi,
I am using paho to finish a MQTT related project, I can publish topic, but i can not receive message after subscribing a topic. I can receive message using mosquitto_sub, here is the code for subscribing:

/////////////////////////////////////////////////////////////////////
int arrivedcount = 0;

void messageArrived(MQTT::MessageData& md)
{
MQTT::Message &message = md.message;

printf("Message %d arrived: qos %d, retained %d, dup %d, packetid %d\n",
++arrivedcount, message.qos, message.retained, message.dup, message.id);
printf("Payload %.*s\n", (int)message.payloadlen, (char*)message.payload);
}


int main(int argc, char* argv[])
{
IPStack ipstack = IPStack();
float version = 0.3;
const char* topic = "N1_CONTROL";

printf("Version is %f\n", version);

MQTT::Client<IPStack, Countdown,256> client = MQTT::Client<IPStack, Countdown, 256>(ipstack);

const char* hostname = "10.52.19.223";
int port = 1883;
printf("Connecting to %s:%d\n", hostname, port);
int rc = ipstack.connect(hostname, port);
if (rc != 0)
printf("rc from TCP connect is %d\n", rc);

printf("MQTT connecting\n");
MQTTPacket_connectData data = MQTTPacket_connectData_initializer;
data.MQTTVersion = 3;
data.clientID.cstring = (char*)"MQTT_Client_Id1";
rc = client.connect(data);
if (rc != 0)
printf("rc from MQTT connect is %d\n", rc);
printf("MQTT connected\n");

rc = client.subscribe(topic, MQTT::QOS2, &messageArrived);
if (rc != 0)
printf("rc from MQTT subscribe is %d\n", rc);
printf("subscribe rc = %d, topic = %s\n", rc, topic);
while(1)
{
sleep(1);
}

/*
rc = client.unsubscribe(topic);
if (rc != 0)
printf("rc from unsubscribe was %d\n", rc);

rc = client.disconnect();
if (rc != 0)
printf("rc from disconnect was %d\n", rc);

ipstack.disconnect();

printf("Finishing with %d messages received\n", arrivedcount);
*/
return 0;
}


/////////////////////////////////////////////////////////////////////
can some help fix this? thank s very much.
Previous Topic:Paho ws disconnected when internal docker network
Next Topic:MQTT conformance test
Goto Forum:
  


Current Time: Fri May 03 10:44:23 GMT 2024

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

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

Back to the top