Search code examples
iotazure-iot-hubmxchip

Mxchip IOT dev kit receiving data from IOT hub


I just started playing with the mxchip. I want my device to trigger an alarm when receiving some command. It seems to me all examples I found are device collecting info and send to iot hub. Can mxchip receive data from iothub or azure function? And maybe some guidance on getting started?


Solution

  • Yes, assuming you use the SDK from the examples for the MXChip you have those handlers available:

    DevKitMQTTClient_SetMessageCallback(MessageCallback);
    DevKitMQTTClient_SetDeviceMethodCallback(DeviceMethodCallback);
    

    Examples:

    static void MessageCallback(const char *payLoad, int size)
    {
       Screen.print(1, payLoad, true);
    }
    
    static int DeviceMethodCallback(const char *methodName, const unsigned char *payload, 
       int size, unsigned char **response, int *response_size)
    {
       LogInfo("Try to invoke method %s", methodName);
       // Do your logic...
       int result = 200;
       return result;
    }