if ((rc = MQTTClient_connect(client, &conn_opts)) != MQTTCLIENT_SUCCESS)
{
printf("Failed to connect, return code %d\n", rc);
exit(-1);
}
printf("Topic - %s \nClientID: %s\n", TOPIC, CLIENTID);
pubmsg.qos = QOS;
pubmsg.retained = 0;
deliveredtoken = 0;
int count = 0;
while (count != messageCnt)
{
count++;
std::string message = "Telemetry Data #MSG_";
std::ostringstream outputString;
outputString << count;
message += outputString.str();
pubmsg.payload = malloc(message.size() + 1);
strcpy_s((char *)pubmsg.payload, message.size() + 1, message.c_str());
//cout << "Peer: " << (char*)pubmsg.payload << endl;
pubmsg.payloadlen = message.length();
if (count == 26)
{
printf("\n Manual intervention \n");
system("pause");
}
MQTTClient_publishMessage(client, TOPIC, &pubmsg, &token);
std::thread::id mainthdID = std::this_thread::get_id();
printf("\n MSG TOKEN :: %d \n MSG PUBLISHED :: %s\n\n\n", token, pubmsg.payload);
free(pubmsg.payload);
}
while (deliveredtoken != token)
{
// Run until the delivery token is received
// We should have a timeout for this to ensure waiting infinitely for a response
};