我在Ubuntu Mate上使用一个RaspberryPi,并尝试运行Iot Hub Client中的示例。我为Ubuntu doumentedhere构建了库。我也建立了Windows版本只是为了测试,它与确切的代码工作良好在Unix上,使用IoTHubClient.send_event_async时出现的错误是:

Python 2.7.12 (default, Nov 19 2016, 06:48:10)
[GCC 5.4.0 20160609]
IoT Hub for Python SDK Version: 1.0.17
Starting the IoT Hub Python sample...
    Protocol MQTT
    Connection string=HostName=<hub name>.azure-devices.net;DeviceId=BananaPi_rasp;SharedAccessKey=<access kwy>
Info: IoT Hub SDK for C, version 1.0.17
IoTHubClient sending 2 messages
IoTHubClient.send_event_async accepted message [0] for transmission to IoT Hub.
Error: Time:Tue Jan 10 02:21:25 2017 File:/home/pi/azure-iot-sdks/c/iothub_client/src/iothubtransport_mqtt_common.c Func:mqtt_operation_complete_callback Line:951 Connection Not Accepted: 0x5: Not Authorized
Error: Time:Tue Jan 10 02:21:25 2017 File:/home/pi/azure-iot-sdks/c/c-utility/src/tlsio_openssl.c Func:decode_ssl_received_bytes Line:654 SSL channel closed in decode_ssl_received_bytes.
Error: Time:Tue Jan 10 02:21:25 2017 File:/home/pi/azure-iot-sdks/c/c-utility/src/tlsio_openssl.c Func:on_underlying_io_bytes_received Line:709 Error in decode_ssl_received_bytes.

我试图通过设置系统时间和检查证书规范来修复它:
我试图“ping”服务器以查看是否可以通过以下方式连接到它:
openssl s_客户端-连接.azure设备.net:8883
我得到:
CONNECTED(00000003)
depth=2 C = IE, O = Baltimore, OU = CyberTrust, CN = Baltimore CyberTrust Root
......
Server certificate
-----BEGIN CERTIFICATE-----
MIIGcjCCBFqgAwIBAgITWgABtrN..........<etire certificate>...
......
SSL handshake has read 3677 bytes and written 531 bytes
---
New, TLSv1/SSLv3, Cipher is ECDHE-RSA-AES256-SHA384
Server public key is 2048 bit
.....
Protocol  : TLSv1.2
Cipher    : ECDHE-RSA-AES256-SHA384
Session-ID: B0010000E7F6C6ADDC09A37DC7C618C4F4522528E20C8AD6E08DCB5B302101D2
Session-ID-ctx:
Start Time: 1483986649
Timeout   : 300 (sec)
Verify return code: 0 (ok)
---
read:errno=0

从我可以理解一切看起来都很好。
我还试图检查证书的有效性:
openssl x509-in/usr/lib/ssl/certs/Baltimore_CyberTrust_Root.pem中
我得到:
  ........
  Validity
            Not Before: May 12 18:46:00 2000 GMT
            Not After : May 12 23:59:00 2025 GMT
    ......

所以看起来没问题,
这里一切看起来都很好,但我还是犯了那个错误。
有人知道可能是什么问题吗?
谢谢

最佳答案

我在这方面有一些经验可以帮助你。
首先,确保您的覆盆子系统时间正确。
然后打印设备密码以查看se字段是否正确:
在umqtt/src/mqtt_codec.c constructConnPayload()中
mqttOptions->密码如下所示:
共享访问签名sr=IoT xxxx.azure devices.net/devices/xxxx&sig=xxxxxxxxxx&se=1484812561&skn=
如果您的see=3600或不等于(当前UTC时间+3600),那么您的情况与我的相同。
如何修复:
在iothub_client/src/iothubtransport_mqtt_common.c SendMqttConnectMsg()中
外壳设备密钥:
修改size_t secSinceEpoch=(size_t)(difftime(get_time(NULL),EPOCH_time_t_VALUE)+0);
to size_t secSinceEpoch=(大小)(时间(空));
EPOCH_TIME_T_值在我的系统上是0,因此(difftime(get_TIME(NULL),EPOCH_TIME_T_VALUE)+0)应该等于get_TIME(NULL)。
但difftime似乎不适用于我的系统,所以secSinceEpoch总是0。
最后我用时间(空)来做。
我花了好几天时间来解决这个问题。希望它能帮助你。

关于linux - send_event_async时,Em Linux上的IoT中心客户端返回SSL channel 关闭,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41565874/

10-10 10:26