Closed Noushadalik closed 1 year ago
I'm not familiar with the way you're doing things here. The way I do it in our project is, after successful AzureIoTHubClient_Connect(), execute AzureIoTHubClient_SubscribeCommand() to add a callback method. Within that callback method, you process the incoming message, then respond to the command call with AzureIoTHubClient_SendCommandResponse()
Bare minimum example:
void connect()
{
AzureIoTResult_t xResult = AzureIoTHubClient_Connect(&xAzureIoTHubClient, true, &xSessionPresent, CONNACK_RECV_TIMEOUT_MS);
xResult = AzureIoTHubClient_SubscribeProperties(&xAzureIoTHubClient, propertiesCallback, &xAzureIoTHubClient, SUBSCRIBE_TIMEOUT);
}
Callback:
void commandCallback(AzureIoTHubClientCommandRequest_t *pxMessage, void *pvContext)
{
//process pxMessage
//respond
AzureIoTResult_t xResult = AzureIoTHubClient_SendCommandResponse(xHandle, pxMessage, result, (const uint8_t *)deviceMethodResponse, strlen(deviceMethodResponse));
}
Thanks for helping out here @rtheil-growlink
Hey @Noushadalik
I think the issue is that you're doing a %s
format on a value that isn't guaranteed to be NULL
terminated. Below are the fields in the struct, one of which is a command name length:
If you previously received a device twin in the same buffer or a buffer that is placed near the one which has the topic, you will have a buffer overrun issue.
You could try something like the following to get only the characters for the command name:
ESP_LOGI("AZ IOT","Name > %.*s\r\n",
pxMessage->usCommandNameLength, pxMessage->pucCommandName);
Note the .*
placed before the s
which allows you to pass a length.
Closing this issue for now due to inactivity. If you would like it reopened, please let us know. For any other questions, please open another Github issue.
Hi, Reported properties are getting client-side when reading the direct method. I wrote the following portion of code to read the direct method on client side
I closed relay 5 in the direct method and then get the command and reported properties on the client side. What is the reason behind this?