TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Guest User
Tech Writer
2.1k
472.3k
DeviceNotFoundException
Sep 13 2019 5:34 AM
Hi Team
I am running backend application on this module(C#), both on my CMD to check if it connect to my IOT hub, im getting a device not connection exception is being not found.
On my IOT hub i have device called "MyDotnetDevice, but if i use DeviceExolore to test for connecting to my IOT, it sends the message well and can view it on the portal as well on Azure. The code is as follows, but the question is why am i getting this exception both my CMD and VS IDE;
C:\Users\Gcobanim\source\repos\azure-iot-samples-csharp-master\azure-iot-samples-csharp-master\iot-hub\Quickstarts\back-end-application>dotnet run
IoT Hub Quickstarts #2 - Back-end application.
Unhandled Exception: Microsoft.Azure.Devices.Common.Exceptions.DeviceNotFoundException: Device {"Message":"{\"errorCode\":404103,\"trackingId\":\"3a490c8ca97b4ea88a6965bc61d5af5a-G:0-TimeStamp:09/13/2019 10:27:36-G:4-TimeStamp:09/13/2019 10:27:36\",\"message\":\"Timed out waiting for device to subscribe.\",\"info\":{},\"timestampUtc\":\"2019-09-13T10:27:36.06523Z\"}","ExceptionMessage":""} not registered
at Microsoft.Azure.Devices.HttpClientHelper.ExecuteAsync(HttpClient httpClient, HttpMethod httpMethod, Uri requestUri, Func`3 modifyRequestMessageAsync, Func`2 isMappedToException, Func`3 processResponseMessageAsync, IDictionary`2 errorMappingOverrides, CancellationToken cancellationToken)
at Microsoft.Azure.Devices.HttpClientHelper.PostAsync[T,T2](Uri requestUri, T entity, TimeSpan operationTimeout, IDictionary`2 errorMappingOverrides, IDictionary`2 customHeaders, CancellationToken cancellationToken)
at back_end_application.BackEndApplication.InvokeMethod() in C:\Users\Gcobanim\source\repos\azure-iot-samples-csharp-master\azure-iot-samples-csharp-master\iot-hub\Quickstarts\back-end-application\BackEndApplication.cs:line 27
at back_end_application.BackEndApplication.Main(String[] args) in C:\Users\Gcobanim\source\repos\azure-iot-samples-csharp-master\azure-iot-samples-csharp-master\iot-hub\Quickstarts\back-end-application\BackEndApplication.cs:line 39
C# code
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
System.Threading.Tasks;
using
Microsoft.Azure.Devices.Client;
using
Microsoft.Azure.Devices;
using
Microsoft.Azure.Devices.Common.Exceptions;
namespace
BackEndApplication
{
class
Program
{
private
static
ServiceClient s_serviceClient;
private
readonly
static
string
s_connectionString =
"HostName=UniversityIOTHub.azure-devices.net;SharedAccessKeyName=service;SharedAccessKey=r***="
;
private
static
async Task InvokeMethod()
{
var methodInvocation =
new
CloudToDeviceMethod(
"SetTelemetryInterval"
) { ResponseTimeout = TimeSpan.FromSeconds(30) };
methodInvocation.SetPayloadJson(
"10"
);
var response = await s_serviceClient.InvokeDeviceMethodAsync(
"MyDotnetDevice"
, methodInvocation);
Console.WriteLine(
"Response status:{0}, payload"
, response.Status);
Console.WriteLine(response.GetPayloadAsJson());
}
static
void
Main(
string
[] args)
{
Console.WriteLine(
"IOT Hub Test-- BackEndApplication.\n"
);
s_serviceClient = ServiceClient.CreateFromConnectionString(s_connectionString);
InvokeMethod().GetAwaiter().GetResult();
Console.WriteLine(
"Press Enter to exit."
);
Console.ReadLine();
}
}
}
Reply
Answers (
5
)
UnathorizedException Error?
Validating template using powershell script fail?