工具/软件:Code Composer Studio
我目前在 TI CC-3235微控制器上使用 azure-IoT-SDK-c。 我尝试使用 Azure Direct 方法在微控制器上调用方法(blinkLED1)。 Azure IoT Hub 给我一个错误提示"未注册"、如下所示:
{"message":"Device {\"Message\":\"{\\\"errorCode\\\":404103,\\\"trackingId\\\":\\\"c1763a63a5b54381aa555198de1e884c-TimeStamp:07/01/2020 12:03:39\\\",\\\"message\\\":\\\"Timed out waiting for device to connect.\\\",\\\"info\\\":{\\\"timeout\\\":\\\"00:03:45\\\"},\\\"timestampUtc\\\":\\\"2020-07-01T12:03:39.1927271Z\\\"}\",\"ExceptionMessage\":\"\"} not registered"}
下面的代码是对来自 TI/Microsoft 的示例代码的修改。 微控制器 C 代码如下:
{
(空) userContextCallback;
(无效)有效载荷;
display_printf (display、0、0、"\r\n 调用的设备方法");
Display_printf (display、0、0、"设备方法名称:%s"、method_name);
display_printf (display、0、0、"设备方法有效载荷:%.*s"、(int)大小、(const char*)有效载荷);
INT STATUS = 200;
char* Response_string ="{\"RESPONSE\":\"这是器件的响应\"};
Display_printf (display、0、0、"\r\n 响应状态:%d"、STATUS);
display_printf (display、0、0、"响应有效载荷:%s\r\n、RESPONSE_string);
if (strcmp ("blinkLED1"、method_name)=0){
const char deviceMethodResponse[]="{\"RESPONSE\":\"LED Blink1 Received\""}";
display_printf (display、0、0、"\r\n 调用的设备方法");
*RESP_SIZE = sizeof (deviceMethodResponse)-1;
*响应=malloc (* RESP_SIZE);
(void) memcpy (*响应、deviceMethodResponse、* RESP_SIZE);
状态= 200;
}
*RESP_SIZE = strlen (RESPONSE_string);
如果((*响应= malloc (* RESP_SIZE)= NULL)
{
状态=-1;
}
其他
{
(void) memcpy (*响应、RESPONSE_string、* RESP_SIZE);
}
G_continueRunning = false;
返回状态;
}
TI 示例参考:https://dev.ti.com/tirex/explore/node?node=ANXoNQGeQjExMVJXpE5vjg__9QUeYYT__LATEST
Azure IoT SDK C 参考: https://github.com/Azure/azure-iot-sdk-c/tree/master/iothub_client/samples/iothub_client_device_twin_and_methods_sample