Read azure iot hub device data using built in endpoint

120 Views Asked by At

I am currently trying to read data sent from a device to an IoT Hub using built-in endpoints. I have used Python and successfully read the data. Now, I want to do this using the Dart language (Flutter). Is it possible? If so, are there any references on how to do it? Initially, I used the Python function EventHubConsumerClient.from_connection_string (endpoint connection string from Iothub -> built-in endpoints -> Eventhub compatible endpoint) to read data coming to the IoT Hub device from my ESP32. Now, I want to read the data from the ESP32 to the IoT Hub using Flutter (Dart language).

1

There are 1 best solutions below

0
Sampath On

I followed this DOC to write to Azure Event Hub using Flutter, but there is no azure_event_hub package on pub.dev.

  • Another method is to connect MQTT messages to Event Hubs and stream Flutter events with the Mosquitto MQTT Broker.
Future<int> connect() async {

client.logging(on: true);

client.keepAlivePeriod = 60;

client.onConnected = onConnected;

client.onDisconnected = onDisconnected;

client.onSubscribed = onSubscribed;

client.pongCallback = pong;

final connMessage =

MqttConnectMessage().startClean().withWillQos(MqttQos.atLeastOnce);

client.connectionMessage = connMessage;

try {

await client.connect();

} on NoConnectionException catch (e) {

print('MQTTClient::Client exception - $e');

client.disconnect();

} on SocketException catch (e) {

print('MQTTClient::Socket exception - $e');

client.disconnect();

}

return 0;

}

Output:

enter image description here

Alternative methods include Azure Event Hubs Integration and Flutter SDK to Azure Event Hubs integration with RudderStack.