Hi @Vinu George Thank you for posting the question on this platform.
The Arduino IDE provides a simpler way to integrate with Azure SDK C code and send telemetry data to Azure IoT Hub. Please refer the detailed steps provided in the GitHub repository - How to Setup and Run Azure SDK for Embedded C IoT Hub Client on Espressif ESP32 for more information on integration and set up.
During the Set up step 4 requires you provide the configurations needed to establish the connection. The simplest way to perform a quick test is by using the Symmetric key. You can get the Primary key for your registered device in IoT Hub using the steps provided in the section retrieve device connection string and provide it to the IOT_CONFIG_DEVICE_KEY
in the iot_configs.h file. This will set up connection between the ESP32 device and Azure IoT Hub.
You can modify the method generateTelemetryPayload()
in Azure_IoT_Hub_ESP32.ino file to push the weight telemetry to IoT Hub. Here is a sample implementation of the function to push the weight telemetry
static void generateTelemetryPayload()
{
// You can generate the JSON using any lib you want. Here we're showing how to do it manually, for simplicity.
// This sample shows how to generate the payload using a syntax closer to regular delevelopment for Arduino, with
// String type instead of az_span as it might be done in other samples. Using az_span has the advantage of reusing the
// same char buffer instead of dynamically allocating memory each time, as it is done by using the String type below.
if (show_Weighing_Results == true) {
if (LOADCELL_HX711.is_ready()) {
// The value 10 in get_units(10) means getting the average value of 10 readings.
// For more details see in File -> Examples -> HX711 Arduino Library -> HX711_full_example
// Get the reading of the object's weight in grams (g).
weight_In_g = LOADCELL_HX711.get_units(10);
// Get the reading of the object's weight in ounces (oz).
weight_In_oz = float(weight_In_g) / 28.34952;
telemetry_payload = "{ \"Weight In oz\": " + String(weight_In_oz) + " }";
}
else {
Serial.println("HX711 not found.");
}
}
You still need to reference the #include "HX711.h"
library in the Azure_IoT_Hub_ESP32.ino file and include the commands in your setup()
method in the Azure_IoT_Hub_ESP32.ino file's setup()
method to configure your sensor to read values from the ESP32 pin.
Hope this helps! Please let us know if you need any additional assistance.