我已经使用我的设备连接到IBM Iot Foundation,据我所知,有两种方法可以建立连接:quickstart和已注册的设备。首先,我尝试连接到快速入门。 (quickstart.messaging.internetofthings.ibmcloud.com)我从paho。(http://www.eclipse.org/paho/)下载了C / C ++ MQTT嵌入式客户端库,套接字已成功建立并且代码中没有错误,我建立了mqttconnect,我无法接收响应CONNACK,它直接转到退出。什么可能导致这个问题?
len = MQTTSerialize_connect((unsigned char*)buf, buflen, &data);
rc=transport_sendPacketBuffer(mysock,buf,len);
/****wait for connack***/
if (MQTTPacket_read(buf, buflen, transport_getdata) == CONNACK)
{
unsigned char sessionPresent, connack_rc;
printf("receive connack\n");// can't print this setence.
if (MQTTDeserialize_connack(&sessionPresent, &connack_rc, buf, buflen) != 1 || connack_rc != 0)
{
printf("Unable to connect, return code %d\n", connack_rc);
goto exit;
}
}
else
goto exit;
topicString.cstring = "iot-2/evt/status/fmt/json";
len += MQTTSerialize_publish((unsigned char *)(buf + len), buflen - len, 0, 0, 0, 0, topicString, (unsigned char *)payload, payloadlen);
len += MQTTSerialize_disconnect((unsigned char *)(buf + len), buflen - len);
rc=transport_sendPacketBuffer(mysock,buf,len);
if (rc == len)
printf("Successfully published\n");
else
printf("Publish failed\n");
exit:
printf("close socket.\n");
transport_close(mysock);