Azure / azure-sdk-for-c

This repository is for active development of the Azure SDK for Embedded C. For consumers of the SDK we recommend visiting our versioned developer docs at https://azure.github.io/azure-sdk-for-c.
MIT License
218 stars 115 forks source link

Arduino port version for ESP32 Compile Time setting vs. Runtime settings for IOT hub client and MQTT client #2819

Open hcr-mit opened 1 month ago

hcr-mit commented 1 month ago

Query/Question Why does the ESP32 for Hub example work when the device id, device key and Azure IoT Hub URL are set in #define works correctly, but when set at runtime, does not connect?

Why is this not a Bug or a feature Request? This is not a bug because the example works when ran per the instructions.

Setup (please complete the following information if applicable):

I am storing the device id, device key and Azure IoT Hub info in NVM on the ESP32S3 device. This is done during a provisioning session. I have copied and pasted the example code that works, into a C++ class that retrieves the device and hub info and then sets the local variables at run-time before trying to execute the IoT Client and MQTT Client initializations. (no modifications to these functions). I have set a 30 sec. delay between attempts to connect. Once the MQTT Client is started, I get the "Before Connect" event then I get the "Error" event with MQTT reporting "MQTT event MQTT_EVENT_ERRORE (39791) MQTT_CLIENT: MQTT connect failed".

The only modification from the example code was to declare the variables: [ static const char host; static const char mqtt_broker_uri; static const char device_id; static const char device_type; ]

Then run a function to set the values for these variables before initializing the clients (IoT , MQTT).

Information Checklist Please make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report