locked
UnauthorizedException after sending a couple of events using DeviceClient RRS feed

  • Question

  • Hi!

    I'm using Azure Iot Hub (F1 / 8000msgs/24hrs) and Microsoft.Azure.Devices.Client.DeviceClient to connect and send Events from a Raspberry PI using Windows 10 Iot Core 10.0.16193.1001 and I'm targeting build 14393. 

    I'm sending the events every 20 seconds so I will not exceed the 8000 messages quota per day. The messages comes through nicely and I use Stream Analytics to store the data in a Table Storage.

    After about 16 messages (or little more than three minutes if sending at another rate) the DeviceClient.SendEventAsync() throws an exception seen below for every event. If I restart the application it goes fine for another three minutes.

    Why does this happen, and how can I resolve it?

    Microsoft.Azure.Devices.Client.Exceptions.UnauthorizedException
    Tracking Id:e54952936a8f487da7ca2e65938999f4-G:8-TimeStamp:06/09/2017 06:57:55
       at Microsoft.Azure.Devices.Client.Transport.AmqpTransportHandler.<SendAmqpMessageAsync>d__34.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.Azure.Devices.Client.Transport.AmqpTransportHandler.<>c__DisplayClass22_0.<<SendEventAsync>b__0>d.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.Azure.Devices.Client.Transport.AmqpTransportHandler.<SendEventAsync>d__22.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.Azure.Devices.Client.Transport.ErrorDelegatingHandler.<>c__DisplayClass19_0.<<ExecuteWithErrorHandlingAsync>b__0>d.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.Azure.Devices.Client.Transport.ErrorDelegatingHandler.<ExecuteWithErrorHandlingAsync>d__20`1.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at Microsoft.Azure.Devices.Client.Transport.ErrorDelegatingHandler.<ExecuteWithErrorHandlingAsync>d__20`1.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.Azure.Devices.Client.Transport.GateKeeperDelegatingHandler.<SendEventAsync>d__16.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.Azure.Devices.Client.TaskHelpers.<WithTimeout>d__15.MoveNext()


    • Edited by Jon Bäcklund Friday, June 9, 2017 8:36 AM Spelling mistake
    Friday, June 9, 2017 7:47 AM

Answers

All replies

  • Hi @Jon Bäcklund

    we'd need to see how you are creating the device client class. Are you using a connection string with device id and device key or a SAS Token directly?

    Friday, June 9, 2017 5:07 PM
  • I'm using exactly the method that is described here, using TPM and SAS Token (in software mode)

    https://github.com/Azure/azure-iot-hub-vs-cs/wiki/Device-Provisioning-with-TPM

    However, now that you say it, I should try also using connection string to see if there is a difference in behaviour. I basically just chose the TPM solution because I wanted to try it out. TPM is not of importance or maybe not really possible anyway for my application on the Pi.

    -Jon

    Monday, June 12, 2017 11:23 AM
  • Creating the Device Client from connection string works fine. I get all the events now. It would still be interesting though to know why the TPM method fails.

    Monday, June 12, 2017 12:23 PM
  • Hi Jon,

    - have a look at this thread

    Thanks

    Roman



    • Edited by Roman Kiss Monday, June 12, 2017 2:41 PM
    • Marked as answer by Jon Bäcklund Monday, June 12, 2017 2:48 PM
    Monday, June 12, 2017 2:41 PM