我正在尝试使用 MQTT 连接 Azure IoT-Hub,并使用来自 Beaglebone black(操作系统:Debian Wheezy)的 Paho C 客户端发送和接收消息。我在 Ubuntu 机器上使用 eclipse CDT 来开发我的应用程序并远程部署/调试。
当我在本机 ubuntu 机器上运行应用程序(使用 gcc 编译)时,Azure 连接成功并且我能够发送数据包。
我交叉编译了此处指定的 OPENSSL,并在“/usr/arm-linux-gnueabihf”文件夹中复制了相应的目录。但是,当我使用 arm-linux-gnueabihf-gcc-4.7 编译并在我的 beaglebone black(使用 gdb-multiarch)上进行远程调试时,我的输出控制台中出现以下错误:
3068126320:error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed:s3_clnt.c:1185:
3068126320:error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed:s3_clnt.c:1185:
Failed to connect, return code -1
请帮我解决这个问题。谢谢。
编辑:可疑链接 - 注册:可疑重复链接中的错误是相同的,但 OPENSSL 错误是由于证书过期。但在我的情况下,它是在与 azure 和 BBB 的 MQTT 连接期间。此外,该链接中我的问题没有答案。根据该链接,当我们选择 SSL/TLS 安全连接时,禁用证书验证毫无意义。
我的代码:
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "MQTTClient.h"
#define PAYLOAD "Hello World!"
#define QOS 1
#define TIMEOUT 10000L
#define TOPIC1 "devices/Manoj_Test/messages/events/"
#define ADDRESS "ssl://xxxxxxxx.azure-devices.net:8883"
#define CLIENTID1 "Manoj_Test"
int main(void)
{
MQTTClient client;
MQTTClient_connectOptions conn_opts = MQTTClient_connectOptions_initializer;
MQTTClient_message pubmsg = MQTTClient_message_initializer;
MQTTClient_deliveryToken token;
int rc1;
MQTTClient_create(&client, ADDRESS, CLIENTID1, 1, NULL);
conn_opts.cleansession = 1;
conn_opts.username = "xxxxxxxx.azure-devices.net/Manoj_Test";
conn_opts.password = "SharedAccessSignature sr=xxxxxxxx.azure-devices.net%2fdevices%2fManoj_Test&sig=GyizT%2b7uyIpOkMJjTfN%2fpOZh9CnuQedNB%2bre2NrL1Kg%3d&se=1496395529";
MQTTClient_setCallbacks(client, NULL, connlost, msgarrvd, delivered);
if ((rc1 = MQTTClient_connect(client, &conn_opts)) != MQTTCLIENT_SUCCESS)
{
printf("Failed to connect, return code %d\n", rc1);
exit(-1);
}
MQTTClient_subscribe(client, TOPIC, QOS);
while(1)
{
pubmsg.payload = PAYLOAD;
pubmsg.payloadlen = strlen(PAYLOAD);
pubmsg.qos = 1;
pubmsg.retained = 0;
MQTTClient_publishMessage(client, TOPIC1, &pubmsg, &token);
printf("Waiting for up to %d seconds for publication of %s\non topic %s for client with ClientID: %s\n", (int)(TIMEOUT/1000), PAYLOAD, TOPIC1, CLIENTID1);
rc1 = MQTTClient_waitForCompletion(client, token, TIMEOUT);
printf("Message with delivery token %d delivered\n", token);
usleep(100000);
}
MQTTClient_disconnect(client, 10000);
MQTTClient_destroy(&client);
return rc1;
}