首页 > 解决方案 > Mxchip IOT 开发套件从 IOT 集线器接收数据

问题描述

我刚开始玩mxchip。我希望我的设备在收到某些命令时触发警报。在我看来,我发现的所有示例都是设备收集信息并发送到物联网集线器。mxchip 可以从 iothub 或 azure 函数接收数据吗?也许还有一些入门指南?

标签: iotazure-iot-hubmxchip

解决方案


是的,假设您使用 MXChip 示例中的 SDK,您可以使用这些处理程序:

DevKitMQTTClient_SetMessageCallback(MessageCallback);
DevKitMQTTClient_SetDeviceMethodCallback(DeviceMethodCallback);

例子:

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;
}

推荐阅读