Send event from Azure Blog Storage to Azure IoT Hub - node.js

I have a NodeJS app that can successfully send data to the Azure IoT Hub, which in turn sends the data to the Azure Blob Storage.
That all works fine.
I can also manually send a message with the Message to device tool of the Azure Devices portal and I can receive this message in my NodeJS app.
What I want to do now, is to send a confirmation message back to the NodeJS app when the blob has been created or deleted.
Can someone please guide me on how to do that? There is little information out there to send messages back to the Azure Client.
I see that I can create a subscription to the Azure Blob Storage but I don't know how to hook it up to the Azure IoT Hub.
Cheers

This is possible by using an Azure Function with a Blob Storage trigger. You could write an Azure Function that subscribes to blob storage changes and use the IoT Hub Service SDK to send a message back to the device. I'm assuming you're using IoT Hub's message routing feature to store the telemetry in blob storage. This comes with a challenge, as there is no way to tell from the name of the blob what device it originated from. You would need to combine it with a blob input to read the file input.
Do you absolutely need this confirmation on the device side? Another note, if you're not interested in persisting telemetry, but instead want to upload a file from your NodeJS app, you could consider the IoT Hub File Upload feature instead.

You can use a device twins to represent a state between the device and service sides.
Updating a state (device twin) at the service side, the notification message is delivered to the device side.

Related

How to display log messages from azure iot device client code

I see log messages in azure iot device client source code like this:
log.debug("Connection already opened by TransportClient."); or
log.info("Device client opened successfully");
My question is where these log messages going? how to get that messages for debug purpose?
Thanks
In general, Blob Storage is added as a 'logging endpoint' which shall encompass a storage account, container in the account and blob in the container. The blobs of type 'Block blobs' shall be utilized for storing text and binary data.
All logs get stored in 'Block blobs' in a container named $logs, which is automatically created when Storage Analytics is enabled for a storage account. The $logs container is located in the blob namespace of the storage account, for example: http://.blob.core.windows.net/$logs
To view and analyze your log data, you should download the blobs that contain the log data you are interested in to a local machine. There are many tools like AzCopy, Azure Storage Data Movement library, Azure Import/Export service to import or export data to and from your storage account. To view the logs, you can also use any tool that can access Azure blob storage, such as Visual Studio or Cerebrata Azure Management Studio.
In case of azure-iot-sdk, each IoT hub exposes a set of endpoints(service endpoints) for the solution's back end to communicate with the devices. An IoT hub has a default built-in-endpoint (messages/events). By default, messages are routed to the built-in service-facing endpoint (messages/events) that is compatible with Event Hubs. You can refer to below link to various methods to read from built-in endpoint https://learn.microsoft.com/en-us/azure/iot-hub/iot-hub-devguide-messages-read-builtin
You can also create custom endpoints to route messages to by linking other services in your subscription to the IoT Hub. In case if the custom endpoint is created, a message is routed to multiple endpoints whose routing queries it matches. There are two storage services IoT Hub can route messages to Azure Blob Storage and ADLS (Azure Data Lake Storage) Gen2 accounts. You can refer to the below link to various methods to read from custom endpoint https://learn.microsoft.com/en-us/azure/iot-hub/iot-hub-devguide-messages-read-custom
In the scenario of logs from IoT SDK itself, the logs can get logged in stdout or stderr as per type of log and based on the deployment environment and also can be redirected accordingly as per the requirement. The SDK uses debug library for detailed logs. The below link can be helpful in giving additional details https://github.com/Azure/azure-iot-sdk-node/wiki/Troubleshooting-Guide-Devices

how to send push notification when Azure blob create or update

I am new in Azure development. I managed to make an Azure blob and Notification Hub. I would like to send a push notification as soon as a blob is created. I have no idea how to do it. Could you please share some idea and links? Thanks!
You could use a blob trigger in Azure Function to do it,
The Blob storage trigger starts a function when a new or updated blob is detected.
then set the Notification Hubs output binding, when the function is triggered, it will send push notifications.
This article explains how to send push notifications by using Azure Notification Hubs bindings in Azure Functions. Azure Functions supports output bindings for Notification Hubs.

Message from Azure Blob Storage to Azure Service Bus

I'm trying to figure out if Azure Blob Storage has similar functionality to Amazon S3. An S3 bucket can be configured in a way, that when new object is created, bucket sends message to SQS. I'm wondering if Azure Blob Storage is able to do the same with Azure Service Bus (which is kind of similar to SQS, correct?).
The only resource I've found so far, which mentions something similar is https://learn.microsoft.com/en-us/azure/storage/blobs/storage-blob-event-overview, but there is no Azure Service Bus on the right side. I know I can use Functions as a proxy, but I'm interested in direct connection.
Any ideas?
Service bus(I think you compare service bus with SQS and SNS in AWS) don't have the ability to subscripe to Blob storage events. Event Grid(the link that you reffered to has Service bus support on the roadmap but no date is confirmed.
I think your best choice is Azure Functions(or Logic app if you don't want to write code) that has a blob Storage trigger to catch events and do action X.
https://learn.microsoft.com/en-us/azure/azure-functions/functions-create-storage-blob-triggered-function.
Or wait a litte for event grid but you still get that "proxy" part.
One option is to use logic apps/ event grid and you can add trigger directly from azure blob storage (https://azure.microsoft.com/it-it/blog/azure-service-bus-now-integrates-with-azure-event-grid/) . Another option would be to add blob trigger with azure functions and write the code to do whatever action which you are looking for .

Azure IoT Hub - How to use Table Storage in IoT Hub?

First of all, sorry for my english skill.
I'm a high school student from South Korea who's doing project with Azure IoT Hub.
I am working on a project where a raspberry pi device is sending values to an Azure IoT Hub. I would like to save this data in Azure Table Storage as this data will be used by some other services (Azure WebApp for example).
So I tried to save raspberry pi values in Azure Table Storage.
But when I add endpoints of IoT Hub, I just can use only blob storage container
of course i still don't understand about iot hub
please don't look so bad.
In a nutshell
I want to send raspberry pi values to Azure Table Storage and not Blob Storage however only option available to me is Blob Storage when I am setting endpoints for Azure IoT Hub.
How to send values to Table Storage via Azure IoT Hub.
by any chance, my logic for Azure is completely wrong?
You can use either functions or Azure Stream Analytics to push hub data to Azure table storage. I found Stream Analytics worked best for me as I was better able to format the data.
Simple way how to store D2C messages in the Azure Store Table is using an Azure EventHubTrigger Function.
More details about the function and its integration with Azure IoT Hub can be found here.
IoT Hub natively supports routing messages to Azure storage as blobs. Refer Save IoT hub messages that contain sensor data to your Azure blob storage.
There does, however, seem to be a typo in the doc where it lists ‘table storage’ instead of 'blob storage'. We’ll get those typos corrected.

Uploading file to Azure BLOB using IoT Hub - Permissions

I'm uploading files from a Raspberry Pi to Azure Blob storage using an Azure IoT hub, using this microsoft tutorial as the basis for my C# code, and it's working fine.
Looking at the Microsoft documentation for the method UploadToBlobAsync(), "If the blob already exists, it will be overwritten."
I'm wondering if there's any way to restrict the device's permissions to create-only in the Azure portal or via PowerShell. My concern is that should someone access the device's storage and get the device id and key they would have the means to delete or overwrite files previously uploaded by that device in the storage container.
As a work-around I could have a server-side process pick up files once they've been received and move them elsewhere, but if the device id/key was restricted to create-only then I wouldn't need this overhead.
The method UploadToBlobAsync (assembly Microsoft.Azure.Devices.Client.UWP) is a wrapper of the REST API sequence calls for uploading a blob to the Azure Storage container.
The following sequence is processed:
REST API call to the Azure IoT Hub to obtain a reference for uploading blob, see the following screen snippet:
As you can see in the above picture, the sasToken for this operation has been generated for read/write.
Once the device received the above response, the REST API PUT the blob can be called.
Here is my suggestion. The device can call REST API Get the metadata of the blob, see the following screen snippet:
Based on the above result, this sequence can be either skipped or continue for actually uploading blob using the REST API PUT.
This is a last step of the sequence (very important). The device need to send a notification to the Azure IoT Hub with the status of the uploading sequence. The following screen snippet shows this REST API call:
Well, as you can see the above step #2 can decide about the skipping or overwriting the upload blob process.

Resources