2016-12-19 153 views
1

我在树莓派3,raspbian OS工作中不工作了,我现在用的是天蓝色的,IOT-SDK-CIOT集线器连接字符串蔚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>"; 

为什么给了我401如果我直接使用从提供的字符串天蓝色的门户?

我都想尽连接字符串(hubowner,服务&设备)和仍然给我401:C

+0

是否有可能对时区和/或时间不正确设置你的树莓派?这会导致SAS中设置的到期时间戳的问题。我问这是因为你的SDK在14:23:36报告错误,但IoT Hub时间戳是22:23:37(UTC)。 – peterdn

+0

我确定树莓中的时间是正确的,时区是否也很重要? – Valeria

+0

是的,我相信。此链接解释了如何设置raspbian中的时区:http://rohankapoor.com/2012/04/americanizing-the-raspberry-pi/ – peterdn

回答

1

我产生和使用的SAS键连接字符串,它都能正常运作。

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

我产生了SAS从Device explorer

预建版本,这工作,因为,在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.