Azure IoT:无法将 ESP8266 设备连接到 IoT Edge(证书错误)

Azure IoT: Cannot connect ESP8266 device to IoT Edge (Certificate error)

我能够通过 python 示例 成功连接到我创建的 IoT Edge。但是,相同的配置不适用于我的实际下游设备 (ESP8266)。

下游设备(ESP8266)配置

我正在为 ESP8266 使用以下示例:https://github.com/Azure/azure-iot-arduino/tree/master/examples/esp8266/iothub_ll_telemetry_sample

在代码中添加了证书和连接字符串:

// DEVICE_CONNECTION_STRING
HostName=iot-edge.leister;DeviceId=wemosd1mini;SharedAccessKey=XXXXXXXXX=

// CERTIFICATE
// same certificate as in python example (content of file azure-iot-test-only.root.ca.cert.pem)
static const char edgeCert [] =
"-----BEGIN CERTIFICATE-----\r\n"
...
"-----END CERTIFICATE-----\r\n";
IoTHubDeviceClient_LL_SetOption(device_ll_handle, OPTION_TRUSTED_CERT, edgeCert);

边缘设备配置

我根据文档配置了一个raspberry pi(文章中提到的演示证书)https://docs.microsoft.com/en-us/azure/iot-edge/how-to-create-transparent-gateway?view=iotedge-2018-06

我可以通过命令openssl s_client -connect iot-edge.leister:8883 -CAfile "C:\Users\micha\Desktop\azure-iot-test-only.root.ca.cert.pem" -showcerts

成功验证证书

结果:验证return代码:0(ok)

ESP8266 日志

Creating IoTHub Device handle...
Sending message 1 to IoTHub...
dowork TLSIO_STATE_OPENING_WAITING_SOCKET
dowork TLSIO_STATE_OPENING_WAITING_SSL
Error opening socket 0
Calling error callback
The device client has been disconnected
Error: failure opening connection to endpoint

我无法使用 相同配置 连接到我的 IoT Edge,ESP8266 作为下游设备。

可以在此处找到更多详细信息:https://github.com/Azure/azure-iot-sdk-c/issues/1902

终于可以用了。 将硬件从 ESP8266 切换到 ESP32 和 运行(相同的代码)没有任何问题。