2017-01-30 51 views
-1

https://docs.microsoft.com/en-us/azure/iot-suite/iot-suite-connecting-devices#create-a-c-sample-solution-on-windows如何將物聯網設備連接到遠程監控預配置解決方案(Windows)?如何實現和指定IoT集線器設備的行爲?

添加時,該設備接收從的IoT集線器的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集線器:

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

更多在給定鏈接

+0

究竟是什麼,你的問題?看起來你只是複製並粘貼已發佈的教程的一部分,而沒有描述任何問題。 –

+0

如何部署鏈接中給出的代碼。 –

回答

0

您在此指的article顯示瞭如何在使用Visual Studio的Windows桌面機器上構建和運行此示例代碼。還有兩個其他同等文章向您展示如何在Linux機器或mbed設備上運行相同的代碼。

如果您想深入瞭解如何將其他硬件設備(如Raspberry Pi或Intel Edison)與Azure IoT Hub一起使用,請參閱中的IoT Hub教程集合。入門指南文件夾here

相關問題