-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get Device Twin request from IoT Hub not working #2529
Comments
I was able to successfully implement the twin document request by extending the example Azure_IoT_Central_ESP32 based on the sample ino that you've provided above. So thank you for that. I noticed you are not subscribing to the topic '$iothub/twin/GET/?$rid=get_twin'. The response to the GET request will be posted there. Have you tried adding an additional subscription to that topic? For what it's worth here's an extract from my log output which shows all topics I'm using
Hope this helps |
@meta-space Interesting to see that it works for you with ESP32. When it comes to
And no reply. And as mentioned, the odd part is that I can't receive any C2D Messages nor publish with D2C messages, |
@engemil , first, to confirm everything is set up correctly on the Hub side, please use the same device identity with the sample within this repository: https://github.com/Azure/azure-sdk-for-c/blob/main/sdk/samples/iot/paho_iot_hub_twin_sample.c The two topics you must subscribe to are: Also, please keep in mind that Twin is not available on all IoT Hub SKUs: https://learn.microsoft.com/en-us/azure/iot-hub/iot-hub-scaling?branch=release-iotbasic (since you mentioned C2D works, I assume this is not a Basic hub). Based on the logs above, the topics seem to be correct and Hub should have responded to the request. Since the logs though do not show MQTT acknowledgements, we don't know if the connection was terminated or if the subscriptions were successful. To further investigate this issue, we need service-side logs. Please follow https://learn.microsoft.com/en-us/azure/azure-portal/supportability/how-to-create-azure-support-request to open a ticket. |
@engemil You are correct. I removed the subscription call and the twin document still arrived. I think I had accidentally messed up the state in the state machine which resulted in the response not being processed previously |
@CIPop The IoT Hub (free tier) seem to be set up correctly. I managed to run the
I tried to open a ticket with the instructions given in the link you gave, however, the "New support request"-interface sent me to a Diagnostics summary, summarizing that nothing seems to be wrong and recommended steps given where "no action should be needed". I suspect the issue is in the arduino ported version of Azure SDK for C (https://github.com/Azure/azure-sdk-for-c-arduino), or in my own code. I'm available for further troubleshooting if you have more ideas for what should be tested. |
Thank you @engemil for the test and logs! We'll try to repro on our side with the Arduino port. |
Describe the bug
I'm working on a code sample to utilize the IoT Hub device twin, where the first step is to request the device twin from cloud to device. After the request is sent, there is no message received and there is no telling if the cloud (IoT Hub) received the request.
The code is based on the Azure IoT Hub Arduino Nano RP2040 Connect example from https://github.com/Azure/azure-sdk-for-c-arduino/tree/main/examples/Azure_IoT_Hub_Arduino_Nano_RP2040_Connect . I built the example with PlatformIO, which worked. However, the device twin request doesn't seem execute properly. The device twin code is based on:
Exception or Stack Trace
Serial reading from the microcontroller
(Sensitive information sensured out with XXXXX)
To Reproduce
Code Snippet
The .ino-file (main.cpp file for PlatformIO projects)
Expected behavior
The expected behavior of the code is to receive a "message" which includes the device twin Json document. However, this code only checks if there is any message received, and prints the message-topic and message length. The code has not yet implemented code to read the message. It ONLY verifies if the device twin was sent to device.
Setup:
Additional context
Note1: If the problem does not relate to Azure SDK for C, I suspect limitations/problems with ArduinoMQTT. I would like to give an request for adding a device twin example in the Azure SDK for C Arduino repository.
Note 2: (Update 20.03.2023) I made another test with two functionaliteis implemented, twin get request and D2C message in the same code. The code first sends a D2C message, which I detect in Azure Portal (with
az iot hub montir-events --hub-name ...
). The second step is to send a twin get request over MQTT connection. After the request is sent, I can no longer recieve D2C messages in the cloud (IoT Hub). Not able to see this happen. Will try to replace theArduinoMqttClient
with SubPubClient.Note 3: (Update 20.03.2023) Tested
PubSubClient
library, same result. Suspect problem with the arduino porting repository (https://github.com/Azure/azure-sdk-for-c-arduino). NB! Im posting this issue here, as the arduino-ported repo does not have a issue tab.Note 4: (Update 21.03.2023) In the arduinoMqttClient library there is a macro (
MQTT_CLIENT_DEBUG
), commented out by default. With it enabled, it confirmed that the topics where subscripted to correctly (MQTT received data for each subscription). And, as suspected only sends and does NOT receive data when sending a "get_twin" request.Note 5: (Update 21.03.2023) In D2C / Telemetry messages, the Azure SDK for C (for arduino) seem to treat the payload section as non-JSON syntax. Due to the backslashes for each quotation mark, as shown here:
Is this as expected? or is the code in the Arduino framework affecting the handling of Strings/characters, such that the payload behaves wierd? And could this possible affect the "get_twin" request aswell?
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
The text was updated successfully, but these errors were encountered: