azure-iot-hub - 使用 Azure IOT 直接方法时直接方法失败
问题描述
我目前在 TI CC-3235 微控制器上使用 azure-iot-sdk-c。我尝试使用 Azure Direct 方法在微控制器上调用方法 (blinkLED1)。Azure IoT 中心给我一个错误,说“未注册”,如下所示:
{"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代码如下:
{
(void)userContextCallback;
(void)payload;
Display_printf(display, 0, 0, "\r\nDevice Method called");
Display_printf(display, 0, 0, "Device Method name: %s", method_name);
Display_printf(display, 0, 0, "Device Method payload: %.*s", (int)size, (const char*)payload);
int status = 200;
char* RESPONSE_STRING = "{ \"Response\": \"This is the response from the device\" }";
Display_printf(display, 0, 0, "\r\nResponse status: %d", status);
Display_printf(display, 0, 0, "Response payload: %s\r\n", RESPONSE_STRING);
if(strcmp("blinkLED1",method_name)==0){
const char deviceMethodResponse[] = "{\"Response\":\"LED Blink1 Received\"}";
Display_printf(display, 0, 0, "\r\nDevice Method called");
*resp_size = sizeof(deviceMethodResponse)-1;
*response = malloc(*resp_size);
(void)memcpy(*response, deviceMethodResponse, *resp_size);
status = 200;
}
*resp_size = strlen(RESPONSE_STRING);
if ((*response = malloc(*resp_size)) == NULL)
{
status = -1;
}
else
{
(void)memcpy(*response, RESPONSE_STRING, *resp_size);
}
g_continueRunning = false;
return status;
}
TI 示例参考:iothub_client_sample_device_method
Azure IoT SDK C 参考:在 Windows 上运行一个简单的设备 Twin C 示例
解决方案
推荐阅读
- c++ - 没有模板的左值不匹配(&&),但与模板匹配(T &&)?
- stored-procedures - 如何通过 ComsoDB 存储过程直接访问文档
- node.js - 安装 npm 时出现 403 禁止 - Ubuntu 14.0
- c# - 如何在二进制图像中找到最大的“斑点”
- python - 解析大图并获取内存错误
- postgresql - 使用交叉表的 PostgreSQL 查询
- bash - bash xargs 脚本中的“chmod:缺少操作数”
- arrays - 在swift中用2个不同的字符动态分隔一个字符串
- android - 在 PWA 中提示打开设备 GPS
- ios - ionic:缺少 iOS 项目的权利