How to subscribes to topic on mqtt broker with Azure IOT HUB as i want the data to be stored in Azure iot hub when I published my topic - node.js

im new to mqtt and currently trying to setup a mqtt protocol to send data from a gateway devices to azure iot hub. The problem i facing was I couldn't figure out which way that I can received and store data on IoT Hub when i published my data on mqtt broker. The textbook way is to subscribe the mqtt broker using Azure IOT Hub but how should I do it?
Assuming I am doing testing using a laptop
Read data stored in json file -> published to topic "data/device1" -> Data stored in Azure IoT Hub
I tried reading the Azure IoT HUB MQTT Connections but it doesnt work out for me. PLease Help

By default Azure IoT Hub makes incoming telemetry messages available on its Event Hub-compatible endpoint: https://learn.microsoft.com/en-us/azure/iot-hub/iot-hub-devguide-messages-read-builtin It does not matter over which protocol (MQTT, AMQP or HTTPS) you sent in the messages to IoT Hub - they all will land in that endpoint.
From there you can read the information using HTTPS or AMQP. I would recommend to use the Event Hub SDK or use a stream processing service like Azure Stream Analytics or Spark Streaming, which supports Event Hub directly.

Related

Read device to cloud messages without CLI, device explorer

I am trying to read D2C messages in android application. I have successfully implemented it using signalR services. But now i want to remove signalR services and read messages like device explorer or cli.
Is there a way to use sockets or any APIs to read D2C messages ?
Your IoT Hub exposes an Event Hub endpoint. You can read messages from the built-in Event Hub endpoint with an Event Hub client. Here is an example using Java

How to send messages to iot edge hub using REST?

I'm using iot edge modules. I need to send messages to the hub from the edge module.
Per my understanding, I need to send it first to the iot edge hub, the edge hub will take care of transferring it to the cloud iot hub. I can consume it from there.
If that's supported, I'm looking for a REST sample on how to do that (or just REST documentation)
To send data to the IoT Edge hub, a module calls the SendEventAsync method.
ModuleClient client = new ModuleClient.CreateFromEnvironmentAsync(transportSettings);
await client.OpenAsync();
await client.SendEventAsync(“output1”, message);
Checkout the below link for moduleclient class methods and properties.
https://learn.microsoft.com/en-us/dotnet/api/microsoft.azure.devices.client.moduleclient?view=azure-dotnet
You don't necessarily have to use the ModuleClient SDK if you want to sent messages through IoT Edge to the cloud. The alternative would be to use IoT Edge in a transparent gateway mode: https://learn.microsoft.com/en-us/azure/iot-edge/how-to-connect-downstream-device
In this way your (virtual) device could connect to the Edge Hub just as it would connect directly to the IoT Hub - using AMQP, MQTT or - as you want to - HTTP.

How to connect IoT hub to Kafka enabled event hub?

If IoT hub can have built in service endpoints for Event hub service then can it send all its messages to Kafka enabled Event hub, if yes how?
Simple link of documentation would also be helpful.
You can route device-to-cloud messages sent to your IoT hub to one or more endpoints by configuring routes - in addition to the built-in endpoint, you can route messages to Event Hubs, Service Bus, or blob storage. To get started, take a look at: https://learn.microsoft.com/azure/iot-hub/iot-hub-devguide-messages-d2c. There's also a routing tutorial you can follow: https://learn.microsoft.com/azure/iot-hub/tutorial-routing

Azure IoT Hub : Cloud to Device messaging using MQTT and SDK

Microsoft has its own SDK for interacting with IoT Hub (Microsoft.Azure.Devices)
It features a client called ServiceClient that as I understand it is client you are supposed to use when sending messages from your backend to a device through IoT hub.
When initializing the ServiceClient like below the only supported TransportTypes are Amqp and Amqp_websockets_only. My devices only support MQTT. How should I go about that?
public async Task SendMessage()
{
var serviceClient = ServiceClient.CreateFromConnectionString("", TransportType.Amqp);
var commandMessage = new Message(Encoding.ASCII.GetBytes("Cloud to device message."));
await serviceClient.SendAsync("myFirstDevice", commandMessage);
}
According to the c2d guidelines "all protocols" are supported.
I have read through this documentation, but it only documents device to cloud, not cloud to device.
Looking at the SDK documentation it only lists AMQP for key features under device-to-cloud
For device-to-cloud messaging, the device can use the MQTT, MQTT-WS, AMQP, AMQP-WS, or HTTP protocols. See the IoT Hub device SDK key features. A device communicates with IoT Hub for both d2c and c2d using the Microsoft Azure IoT device SDK for .NET. Note that there are also device SDKs available for Java, Node, Python and C.
If you have a back-end application that needs to send a c2d message to a device, then that back-end application should use one of the Azure IoT service SDKs such as
Microsoft Azure IoT service SDK for C# to connect to IoT Hub and send the c2d message. The back-end application must use AMQP or AMQP-WS.
The protocol used by the device to connect to IoT Hub is independent of the protocol used by the back-end application to connect to IoT Hub. For example, a back-end application could connect to IoT Hub using AMQP to send a c2d message to a device that's connected to the hub using MQTT.

Not receiving message for subcribed topic from Azure IoT MQTT broker

Please, help me to resolve this issue, I have tried all the options...
i used MqttClient client to subcribed iot hub mqtt broker using topic
devices/t2c-171bdd65-407d-4de9-992b-36cee0914b3f/messages/devicebound/#
but I wasn't able to receive any callback...
I am running this application from my local machine and connecting to Azure IoT hub MQTT broker. well, I am able to publish message to IoT hub, I can confirm this because IoT hub message count is increasing & device explorer running on my local machine is displaying message in monitor mode.
I'm supposing you're using M2MQTT nuget package for MQTT client.
I have some sample code that proves working on my local PC and my Azure IoT Hub. You can find it in https://github.com/ghjackie/AzureIoTDemo
You need to follow the tutorial from here to modify the deviceId, hostName, etc...

Resources