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