添加以下在设备从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);
}
更多指定链接