I was given the iothubower SharedAccessKey for an IoT Hub instance I don't have otherwise access.
Using Visual Studio Code I can Set IoT Hub Connection String using the iothubowner credentials and then Create Device to create a device on the IoT Hub.
However, when I try to Start Monitoring Built-in Event Endpoint on that device, I am asked for additional information, namely the Event Hub compatible connection string.
Is this string something I can retrieve using the iothubowner credentials that I've been given? I don't have access to the Azure Portal.
I see the structure of the Event Hub compatible connection string consists of a namespace (which I don't know) and the event hub name, in addition to the iothubowner credentials.
Is the namespace and event hub name something I can retrieve using the my credentials?
Is there any other way I can monitor events?
Event Hub compatible endpoint with iothubowner credentials in my case looks something like this:
Endpoint=sb://iothub-ns-{part_of_iot_hub_name}-2052657-6507c44fda.servicebus.windows.net/;SharedAccessKeyName=iothubowner;SharedAccessKey={shared_access_key}=;EntityPath={iot_hub_name}
The namespace looks like this and is not a part of iothubowner credentials(connection string):
iothub-ns-{part_of_iot_hub_name}-2052657-6507c44fda
As you can see, this endpoint cuts the IoT hub name and contains some numbers - which would be really hard to guess. So if you have the namespace, you can construct the endpoint, otherwise, I would say no and you need access to the Azure portal or to log in with 'az command' and retrieve it with Powershell.
Even though there is an accepted answer, I could not quite figure out how to get my Endpoint.
You need to go to your IoT Hub and click on "Built-in endpoints" and there you will find the Entry:
Related
I am implementing an azure event hub subscriber which is successfully able to connect but it's not receiving the message for a particular event hub in an event hub namespace. But it's working as expected for the other event hub in the same namespace. there is no error in the logs. Is there any way to find out the root cause of the issue?
I am successfully able to publish the message with the same configuration.
Publisher and Subscriber are running on the same machine.
I have implemented the publisher and subscriber in Dapr.
Both publisher and subscriber logs are exactly the same in Dapr, So I think it's an issue with the storage account.
Adding more information:
I have tried my application with a different storage account and it's working as expected. So what is the issue? How can I resolve it? I want to work with my old storage account.
All issues
There are multiple problems put together in your question, which can be tested separately. (E.g. event hubs, dapr, storage account ...etc.) It is critical to have a granular understanding of these problems, so I would try to test them one-by-one.
Event Hub issues
You can test your Event Hub flow separately by creating simple "hello world" clients locally and reproducing a relationship between them based on your production scenario.
E.g.
try to connect to an event hub with exactly one publisher and exactly one consumer,
try to publish the same message with one publisher to multiple event hubs and see if you can consume them with separate consumers,
...etc.
Based on your comment, I will list 2 example problem scenarios:
Problem 1: "I can access one Event Hub in the namespace, but can't access another in the same namespace."
You can configure "Shared Access Policies" for the scope of the Event Hub Namespace, which will be applied to all event hubs in that namespace.
You can also configure the same policies for the scope of the Event Hub, which will be applied to that single hub only.
Make sure to use the appropriate scope in Azure portal while trying to use the connection strings from your code.
Problem 2: "I can publish messages from a client to an Event Hub, but cannot consume messages with the same client, from the same machine, with the same connection string."
You can configure an infinite number of "Shared Access Policies", each having a custom key and connection string.
You can also configure client access privileges for each policy, chosen from the following 3 options:
Manage
Send
Listen
Make sure to use the appropriate client access privileges. If you want to use the same exact connection string for sending and listening, add both "Send" and "Listen" access to that policy. (You can also have a different policy and connection string for sending and listening...etc.)
Is there a way to send data to a device in Azure IoT Hub using a shared key without first generating a SAS token? The reason I am trying to do this is because I want to send events via a web hook without writing code for it. The device is connected to our system and we're trying to use our web hooks functionality which can relay an event to a HTTP endpoint with preconfigured headers and format but it can't execute the code to get a temporary SAS token.
Alternatively can I make a SAS token that never expires?
Ended up using Azure IoT Central + the Azure IoT Central Bridge. The IoT Bridge is an Azure function where you put some JS code to convert your message to a format that IoT Central understands and then it deals with the tokens and eventual device registration. This is not an exact answer to the question since IoT Central is not exactly IoT Hub (it is a portal over it) but it turns out it works well enough for our case. Also I think the codebase of the IoT Bridge can be used with the IoT Hub if one wants to dig enough through it. Maybe this solution can serve someone else.
Setup till now:
I have created spaces. At the top level I have the IOT hub resource. In two of spaces, I have attached devices to it along with the sensors. I have created a Matcher for the Temperature sensor along with the UDF that is similar to the documentation. I have also assigned permissions to UDF. To send data to IOT hub, I have also fetched the device connection string for the dotnet sample
List of issues I am facing:
When I try to run the dotnet sample, I can see that it is able to reach the UDF(checked it via debugging), but in the UDF, it is not able to access the telemetry variable as given in documentation . The error it shows is :
Unexpected exception occurred while processing user-defined function. Please contact support and provide the correlation ID for the request.
I have created an endpoint to send Raw Telemetry to Event Hub. But I want to send the processed data from UDF to cosmos db. Is it possible? If yes then how?
Thanks for the question and reaching out...for #2 you could do this by doing a notify method in your UDF. You can setup egress to other endpoints such as Event Hub, Event Grid or Service Bus via the endpoint dispatcher. You would setup endpoint via the /endpoint API and then in your UDF you could specify what you want to send out and which changes. For details on the events and endpoints you can see here: https://learn.microsoft.com/en-us/azure/digital-twins/how-to-egress-endpoints
Here's also here is a link to learn more about this connecting Digital Twins over to Logic Apps: https://learn.microsoft.com/en-us/azure/digital-twins/tutorial-facilities-events which would have a similar pattern to sending data over to Cosmos DB.
As for the first one I am not sure if you are still seeing this. Which region? Do you have a correlation ID that you can pass along? Also if you turn on logs and look in Azure Monitor are there details there?
Am working on Azure resources like Azure Service Bus, Azure Functions, IOT Hub. Here am trying to send queue messages from Azure Service Bus to IOT Hub using Azure functions and then display that messages in my local device (Cloud-To-Device). Am able to read my messages in Azure function using Service Bus Queue Trigger and tried to send them to IOT Hub as output of function. Once, when I run the Azure function "Its can sending the messages to IOT Hub as output",but it unable to send them to client device. Can you please suggest me to "How to solve this situation"
As far as I know there is currently no way to select a Cloud to Device Message(C2D) as a Azure Functions Output.
You also cannot use the Event Hub Output as it does not support C2D messages as described here.
I can think of 2 methods to accomplish C2D messaging in Azure functions:
Use the Azure IoT SDK as described in this answer and shown in this channel9 video from 2017 (might be out of date).
Use the Azure IoT Hub REST API. You can find general configuration options here and the API endpoint to use would be senddevicecommand.
Unfortunately there is current no output binding for IoT Hub from Functions (you could write a new custom binding, though ;) )
To talk from a Function to your devices, you need the Azure Device Service SDK of the IoT Hub. Then you can either use Cloud-to-Device messages (asynchronous) or Direct Methods (synchronous). You can find a example of the latter in my GitHub repo here: https://github.com/sebader/iotedge-end2end/blob/master/CloudFunctions/DirectMethodCaller.cs
The important pieces being:
ServiceClient _iothubServiceClient = ServiceClient.CreateFromConnectionString(config["iothubowner_cs"]);
var methodRequest = new CloudToDeviceMethod("YourDirectMethodName", TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(10));
var result = await _iothubServiceClient.InvokeDeviceMethodAsync(device, module, methodRequest).ConfigureAwait(false);
An implementation for C2D messages will look pretty much the same.
So I've been trying to generate a small function app (in JS) that responds to a message sent to the Azure IoT Hub. The output is a simple console log. However, I am unable to load the event hub compatible end point of the IoT Hub as the trigger (the only option available is to create a new Event Hub). How do I proceed? The code for the device to send to Azure' IoT Hub is working and I am able to view the messages via the Device Explorer tool.
You need to create new Event Hub Connection and use the Event Hub-Compatible endpoint from the Iot Hub Messaging section.
But you need to change it to match the service bus connection string format -
"Endpoint=[your iot hub compatible end point];SharedAccessKeyName=[your key name];SharedAccessKey=[your key];EntityPath=[your event hub compatible name]"
key name and key can be taken from the "Shared access policy" section.
Good Luck