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

Azure 如何将物联网设备连接到远程监控预配置解决方案(Windows)?如何实施和指定物联网集线器设备的行为?,azure,azure-iot-hub,Azure,Azure Iot Hub,添加以下功能,这些功能在设备从IoT Hub接收到SetTemperature和Set湿度命令时执行: EXECUTE_COMMAND_RESULT SetTemperature(Thermostat* thermostat, int temperature) { (void)printf("Received temperature %d\r\n", temperature); thermostat->Temperature = temperature; return

添加以下功能,这些功能在设备从IoT Hub接收到SetTemperature和Set湿度命令时执行:

 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;
 }
 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);
 }
添加以下向物联网中心发送消息的功能:

 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;
 }
 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);
 }
有关详细信息,请参见给定链接

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


如果您想学习关于如何使用其他硬件设备(如Raspberry Pi或Intel Edison with Azure IoT Hub)的深入教程,请查看Get started文件夹中的IoT Hub教程集。

您的问题到底是什么?看起来您只是复制并粘贴了已发布教程的一部分,没有任何问题。如何部署链接中给出的代码。