Iot Hub 连接字符串在 azure-iot-sdk-c 示例中不起作用

Iot Hub connection string not working in azure-iot-sdk-c samples

我在 raspberry pi 3,raspbian OS 工作,我正在使用 azure-iot-sdk-c

我遵循了此处的 github 说明:https://github.com/Azure/azure-iot-sdk-c,我下载并正确构建了 iothub_client/samples 文件夹中的所有示例

错误是,当我将连接字符串放在 iothub_client_sample_http.c

这里:

static const char* connectionString = "[device connection string]";

和运行它,我得到很多这样的错误:

Error: Time:Mon Dec 19 14:23:36 2016 File:/home/pi/Desktop/azure-iot-sdk-c/c-utility/adapters/httpapi_curl.c Func:HTTPAPI_ExecuteRequest Line:576 Failure in HTTP communication: server reply code is 401 Info: HTTP Response:{"Message":"ErrorCode:IotHubUnauthorizedAccess;Unauthorized","ExceptionMessage":"Tracking ID:13262df6828d469e9b29e2176a86fad3-G:9-TimeStamp:12/19/2016 22:23:37"} Error: Time:Mon Dec 19 14:23:36 2016 File:/home/pi/Desktop/azure-iot-sdk-c/iothub_client/src/iothubtransporthttp.c Func:DoEvent Line:1626 unexpected HTTP status code (401)

这是我的连接结构:

static const char* connectionString = "HostName=<myiothub>;DeviceId=<mydevice>;SharedAccessKey=<myaccesskey>";

如果我直接使用 Azure 门户提供的字符串,为什么会出现 401?

我已经尝试了每个连接字符串(hubowner、服务和设备),但仍然给我 401 :C

我生成了 SAS 密钥并将其用作连接字符串,一切正常。

static const char* connectionString ="HostName=<myiothub>;CredentialType=SharedAccessSignature;DeviceId=<mydevice>;SharedAccessSignature=SharedAccessSignature sr=<iothub>&sig=<saskey>&se=<time>&skn=device" 

我从 Device explorer

的预构建版本生成了 SAS

这是有效的,因为,如 Control access to IoT Hub 中所述:

The only way that IoT Hub authenticates a specific device is using the device identity symmetric key. In cases when a shared access policy is used to access device functionality, the solution must consider the component issuing the security token as a trusted subcomponent.