2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

DeviceClient.SendEventAsyncでUnauthorizedExceptionが出る

Last updated at Posted at 2016-04-13

Windows IoTをインストールしたRaspberry Pi 2でAzure IoT Hubにメッセージを送ろうとしたら次のような例外が出た。

string uri = "<Azure IoT Hub URI>";
string deviceId = "<DeviceID>";
string deviceKey = "<DeviceKey>";

var deviceClient = DeviceClient.Create(
    uri,
    new DeviceAuthenticationWithRegistrySymmetricKey(deviceId, deviceKey),
    TransportType.Http1);
    
var message = new Message(Encoding.UTF8.GetBytes("Test Message"));
await deviceClient.SendEventAsync(message);

例外:Microsoft.Azure.Devices.Client.Exceptions.UnauthorizedException
メッセージ:{"Message":"The specified SAS token is expired"}

どうもこの例外はWindows IoTデバイスの時刻が大きくずれていると発生するようだ。

対処方法

デバイスの時刻を正しいものにすればいいので、下の自分の記事にあるように時刻同期を行ったら正常にメッセージを送れるようになった。

Windows IoTで時刻を同期する - Qiita

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?