首页 文章

如何将 IoT 设备连接到远程监控预配置解决方案(Windows)?如何实现和指定物联网集线器设备的行为?

提问于
浏览
-1

https://docs.microsoft.com/en-us/azure/iot-suite/iot-suite-connecting-devices#create-a-c-sample-solution-on-windows

添加以下在设备从 IoT Hub 接收 SetTemperature 和 SetHumidity 命令时执行的函数:

EXECUTE_COMMAND_RESULT SetTemperature(Thermostat* thermostat, int temperature)
 {
   (void)printf("Received temperature %d\r\n", temperature);
   thermostat->Temperature = temperature;
   return EXECUTE_COMMAND_SUCCESS;
 }

 EXECUTE_COMMAND_RESULT SetHumidity(Thermostat* thermostat, int humidity)
 {
   (void)printf("Received humidity %d\r\n", humidity);
   thermostat->Humidity = humidity;
   return EXECUTE_COMMAND_SUCCESS;
 }

添加以下向 IoT Hub 发送消息的功能:

static void sendMessage(IOTHUB_CLIENT_HANDLE iotHubClientHandle, const unsigned char* buffer, size_t size)
 {
   IOTHUB_MESSAGE_HANDLE messageHandle = IoTHubMessage_CreateFromByteArray(buffer, size);
   if (messageHandle == NULL)
   {
     printf("unable to create a new IoTHubMessage\r\n");
   }
   else
   {
     if (IoTHubClient_SendEventAsync(iotHubClientHandle, messageHandle, NULL, NULL) != IOTHUB_CLIENT_OK)
     {
       printf("failed to hand over the message to IoTHubClient");
     }
     else
     {
       printf("IoTHubClient accepted the message for delivery\r\n");
     }

 IoTHubMessage_Destroy(messageHandle);
   }
 free((void*)buffer);
 }

更多给定链接

1 回答

  • 0

    您在此处引用的文章向您展示了如何使用 Visual Studio 在 Windows 桌面计算机上构建和运行此示例代码。还有另外两篇等效文章向您展示如何在Linux机器或mbed设备上运行相同的代码。

    如果您想关注如何使用其他硬件设备(如 Raspberry Pi 或英特尔 Edison 与 Azure IoT Hub)的 in-depth 教程,请查看Get started文件夹这里中的 IoT Hub 教程集合。

相关问题