Error when invoking Device Methoths on IoTHub

Damir Dobric Posts

Next talks:

 

    

Follow me on Twitter: #ddobric



 

 

Archives

Sometimes, wen your service code tries to invoke a Device Method, you might get following exception:

Device {"Message":"ErrorCode:DeviceNotOnline;Timed out waiting for device to connect.","ExceptionMessage":"Tracking ID:61936222f52a4c159f4942f342daf269-G:6-TimeStamp:01/07/2017 11:35:20"} not registered

Following server-side code snippet throws the error:

m_ServiceClient = ServiceClient.CreateFromConnectionString(m_ConnStr);

CloudToDeviceMethod method = new CloudToDeviceMethod("RouteRequest", TimeSpan.FromSeconds(30));

method.SetPayloadJson(JsonConvert.SerializeObject(
               new {
                   Url= "test",
                   Method = "",
                   Payload = "payload",
               }
               ));

           var result = await m_ServiceClient.InvokeDeviceMethodAsync("D001", method);

           string jsonResult = result.GetPayloadAsJson();    

However the code which causes this exception is on the client side:

m_DeviceClient = DeviceClient.CreateFromConnectionString(m_ConnStr);
    
MethodCallback methodCallback = new MethodCallback(routeRequest);

m_DeviceClient.OpenAsync().Wait();

m_DeviceClient.SetMethodHandler("RouteRequest", methodCallback, "context");

Right now, you need to explicitly set the protocol to workaround this issue. Simply change the initialization line in client code as follows:

m_DeviceClient = DeviceClient.CreateFromConnectionString(m_ConnStr, TransportType.Mqtt);


Posted Dec 06 2016, 07:00 AM by Damir Dobric

Comments

Simon wrote re: Error when invoking Device Methoths on IoTHub
on 01-17-2017 9:27

Thanks for this posting! Saved us some time .. ;)

Add a Comment

(required)  
(optional)
(required)  
Remember Me?
developers.de is a .Net Community Blog powered by daenet GmbH.