我正在尝试使用paho MQTT C库连接到AWS。我已经正确设置了我的AWS物品和证书。我通过使用mosquitto和MQTTFx工具进行发布进行了测试。
我尝试将连接URL,证书文件和密钥映射到MQTTClient.ssl所需的参数,但是连接调用始终失败。
我不能在此处发布整个代码,所以我只发布相关的代码。
#define ADDRESS "ssl://xxxxxxxxxxxxxxxx-2.amazonaws.com:8883"
#define CLIENTID "testclient"
#define TOPIC_REQ "req/16000393" //this is the topic I'm subscribing to at AWS side (publishing from client laptop)
...
#define CRT_FILE "./certificate.pem.crt"
#define KEY_FILE "./private.pem.key"
#define CA_FILE "./rootCA.pem"
...
int main(int argc, char* argv[])
{
MQTTClient client;
MQTTClient_connectOptions conn_opts = MQTTClient_connectOptions_initializer;
MQTTClient_message pubmsg = MQTTClient_message_initializer;
MQTTClient_deliveryToken token;
MQTTClient_SSLOptions sslopts = MQTTClient_SSLOptions_initializer;
int rc;
int ch;
conn_opts.ssl = &sslopts;
conn_opts.ssl->trustStore = CRT_FILE;
conn_opts.ssl->keyStore = CA_FILE;
conn_opts.ssl->privateKey = KEY_FILE;
conn_opts.ssl->verify = 1;
MQTTClient_create(&client, ADDRESS, CLIENTID,
MQTTCLIENT_PERSISTENCE_NONE, NULL);
conn_opts.keepAliveInterval = 20;
conn_opts.cleansession = 1;
MQTTClient_setCallbacks(client, NULL, connlost, msgarrvd, delivered);
if ((rc = MQTTClient_connect(client, &conn_opts)) != MQTTCLIENT_SUCCESS)
{
printf("Failed to connect, return code %d\n", rc);
exit(EXIT_FAILURE);
}
...
连接不断失败。请帮助!我没主意了。