我克隆了最新版本的 Azure C-SDK。最近的一条提交消息说,添加了基于 AMQP 的设备孪生。我尝试将序列化程序示例的 devicetwin_simplesample.c 切换到 AMQP:
git diff devicetwin_simplesample/devicetwin_simplesample.c
diff --git a/serializer/samples/devicetwin_simplesample/devicetwin_simplesample.c b/serializer/samples/devicetwin_simplesample/devicetwin_simplesample.c
index 7da717c..d390a25 100644
--- a/serializer/samples/devicetwin_simplesample/devicetwin_simplesample.c
+++ b/serializer/samples/devicetwin_simplesample/devicetwin_simplesample.c
@@ -14,7 +14,7 @@
/*String containing Hostname, Device Id & Device Key in the format: */
/* "HostName=<host_name>;DeviceId=<device_id>;SharedAccessKey=<device_key>" */
-static const char* connectionString = "HostName=...";
+static const char* connectionString = "HostName=XXXX.azure-devices.net;DeviceId=XXXX;SharedAccessKey=XXXX";
// Define the Model - it is a car.
BEGIN_NAMESPACE(Contoso);
@@ -47,6 +47,7 @@ DECLARE_DEVICETWIN_MODEL(Car,
WITH_REPORTED_PROPERTY(Maker, maker), /*this is a structured reported property*/
WITH_REPORTED_PROPERTY(CarState, state), /*this is a model in model*/
+ WITH_DESIRED_PROPERTY(CarSettings, settings) /*this is a model in model*/
WITH_DESIRED_PROPERTY(CarSettings, settings), /*this is a model in model*/
WITH_METHOD(getCarVIN)
);
@@ -101,7 +102,7 @@ void device_twin_simple_sample_run(void)
else
{
/*create an IoTHub client*/
- IOTHUB_CLIENT_HANDLE iotHubClientHandle = IoTHubClient_CreateFromConnectionString(connectionString, MQTT_Protocol); // Change to AMQP_Procotol if desired.
+ IOTHUB_CLIENT_HANDLE iotHubClientHandle = IoTHubClient_CreateFromConnectionString(connectionString, AMQP_Protocol); // Change to AMQP_Procotol if desired.
if (iotHubClientHandle == NULL)
{
printf("Failure creating IoTHubClient handle");
它编译。但是,当我启动它时,我收到以下错误并且应用程序立即退出:
Info: IoT Hub SDK for C, version 1.1.21
Info: Retry policy set (5, timeout = 0)
Error: Time:Fri Aug 18 17:15:22 2017 File:/home/user/workspaceMisc/azure-iot-sdk-c/iothub_client/src/iothubtransport_amqp_common.c Func:IoTHubTransport_AMQP_Common_Subscribe_DeviceMethod Line:1720 Not implemented
Error: Time:Fri Aug 18 17:15:22 2017 File:/home/user/workspaceMisc/azure-iot-sdk-c/iothub_client/src/iothub_client_ll.c Func:IoTHubClient_LL_SetDeviceMethodCallback_Ex Line:1854 IoTHubTransport_Subscribe_DeviceMethod failed
Error: Time:Fri Aug 18 17:15:22 2017 File:/home/user/workspaceMisc/azure-iot-sdk-c/iothub_client/src/iothub_client.c Func:IoTHubClient_SetDeviceMethodCallback Line:1619 IoTHubClient_LL_SetDeviceMethodCallback_Ex failed
Error: Time:Fri Aug 18 17:15:22 2017 File:/home/user/workspaceMisc/azure-iot-sdk-c/serializer/inc/serializer_devicetwin.h Func:Generic_IoTHubClient_SetCallbacks Line:193 failure in IoTHubClient_SetDeviceMethodCallback
Error: Time:Fri Aug 18 17:15:22 2017 File:/home/user/workspaceMisc/azure-iot-sdk-c/serializer/inc/serializer_devicetwin.h Func:IoTHubDeviceTwinCreate_Impl Line:261 failure in Generic_IoTHubClient_SetCallbacks
Failure in IoTHubDeviceTwin_CreateCarError: Time:Fri Aug 18 17:15:22 2017 File:/home/user/workspaceMisc/azure-iot-sdk-c/serializer/inc/serializer_devicetwin.h Func:IoTHubDeviceTwin_Destroy_Impl Line:306 invalid argument void* model=(nil)
Info: Transport state changed from AMQP_TRANSPORT_STATE_NOT_CONNECTED to AMQP_TRANSPORT_STATE_CONNECTING
Info: Transport state changed from AMQP_TRANSPORT_STATE_CONNECTING to AMQP_TRANSPORT_STATE_CONNECTED
Info: Transport state changed from AMQP_TRANSPORT_STATE_CONNECTED to AMQP_TRANSPORT_STATE_BEING_DESTROYED
Error: Time:Fri Aug 18 17:15:22 2017 File:/home/user/workspaceMisc/azure-iot-sdk-c/uamqp/src/amqp_management.c Func:amqp_management_close Line:888 AMQP management instance not open
Error: Time:Fri Aug 18 17:15:22 2017 File:/home/user/workspaceMisc/azure-iot-sdk-c/iothub_client/src/iothubtransport_amqp_connection.c Func:on_cbs_open_complete Line:149 CBS open failed
Error: Time:Fri Aug 18 17:15:22 2017 File:/home/user/workspaceMisc/azure-iot-sdk-c/iothub_client/src/iothubtransport_amqp_cbs_auth.c Func:on_cbs_put_token_complete_callback Line:188 CBS reported status code 0, error: '(null)' for put-token operation for device ''
Error: Time:Fri Aug 18 17:15:22 2017 File:/home/user/workspaceMisc/azure-iot-sdk-c/uamqp/src/saslclientio.c Func:saslclientio_send_async Line:1165 send called while not open
Error: Time:Fri Aug 18 17:15:22 2017 File:/home/user/workspaceMisc/azure-iot-sdk-c/uamqp/src/connection.c Func:on_bytes_encoded Line:241 Cannot send encoded bytes
Info: Closing tlsio from a state other than TLSIO_STATE_EXT_OPEN or TLSIO_STATE_EXT_ERROR
Error: Time:Fri Aug 18 17:15:22 2017 File:/home/user/workspaceMisc/azure-iot-sdk-c/uamqp/src/saslclientio.c Func:on_underlying_io_open_complete Line:178 Open complete received in unexpected state
-> [CLOSE]* {}
Error: Time:Fri Aug 18 17:15:22 2017 File:/home/user/workspaceMisc/azure-iot-sdk-c/uamqp/src/saslclientio.c Func:saslclientio_close_async Line:1114 saslclientio_close called while not open
Error: Time:Fri Aug 18 17:15:22 2017 File:/home/user/workspaceMisc/azure-iot-sdk-c/uamqp/src/connection.c Func:connection_close Line:1339 xio_close failed
我还尝试从模型中删除 CarVIN 并评论相应的方法,这也没有帮助。
正如我在错误日志中看到的“未实现”:是否可以使用 AMQP 设备双胞胎或者稍后会“完成”?
编译器/操作系统:gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609