Thank you for asking your question here @Ricardo Zamudio Carbajal !
If you research on the azure iot sdk for C you will find some samples and there is one explaining how Direct Methods work:
Here is the piece of code that you should pay attention for your described scenario:
static int deviceMethodCallback(const char* method_name, const unsigned char* payload, size_t size, unsigned char** response, size_t* response_size, void* userContextCallback)
{
(void)userContextCallback;
(void)payload;
(void)size;
int result;
if (strcmp("getCarVIN", method_name) == 0)
{
const char deviceMethodResponse[] = "{ \"Response\": \"1HGCM82633A004352\" }";
*response_size = sizeof(deviceMethodResponse)-1;
*response = malloc(*response_size);
(void)memcpy(*response, deviceMethodResponse, *response_size);
result = 200;
}
else
{
// All other entries are ignored.
const char deviceMethodResponse[] = "{ }";
*response_size = sizeof(deviceMethodResponse)-1;
*response = malloc(*response_size);
(void)memcpy(*response, deviceMethodResponse, *response_size);
result = -1;
}
return result;
}
Would strongly advise you to take a look at the following doc as well to better Understand how to invoke direct methods from IoT Hub: https://learn.microsoft.com/en-us/azure/iot-hub/iot-hub-devguide-direct-methods
Despites mentioning IoT Hub, would work the same for IoT Central since the technology behind IoT Central is using IoT Hub ;).
Hope I could help you continue with your project.
Remember:
- Please accept an answer if correct. Original posters help the community find answers faster by identifying the correct answer. Here is how.
- Want a reminder to come back and check responses? Here is how to subscribe to a notification.