Toggle navigation
首页
问答
文章
积分商城
专家
专区
更多专区...
文档中心
返回主站
搜索
提问
会员
中心
登录
注册
Network
阿里云JSON数据解析问题-part2
发布于 2019-10-26 14:01:42 浏览:2186
订阅该版
* 本帖最后由 aozima 于 2019-10-29 09:36 编辑 * ![data解析.png](/uploads/201910/26/135238p2sr64vmpr36um2m.png) 前几天出差,上周的遗留问题没有解决,我在查询了相关资料后,了解到RTT有CJSON库,就在ENV工具里配置了,CJSON的函数如下 ![json2.png](/uploads/201910/26/140002hv0zto3iivoizv4s.png) 但是在调用CJSON函数的时候遇到了问题 ![JSON解析.png](/uploads/201910/26/140023fhxxsc66wq6s7khm.png) 请问这个获取根目录的函数应该数据哪个参数? 下面是mqtt_sample的源码 ``` /* * Copyright (c) 2006-2018 RT-Thread Development Team. All rights reserved. * License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * [http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0) * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ #include
#include
#include
#include
#include "cJSON.h" #include "iot_import.h" #include "iot_export.h" #include "rtthread.h" #if defined(MQTT_ID2_AUTH) && defined(ON_DAILY) #define PRODUCT_KEY "9rx2yMNV5l0" #define DEVICE_NAME "sh_online_sample_mqtt" #define DEVICE_SECRET "v9mqGzepKEphLhXmAoiaUIR2HZ7XwTky" #elif defined(ON_DAILY) #define PRODUCT_KEY "gsYfsxQJgeD" #define DEVICE_NAME "DailyEnvDN" #define DEVICE_SECRET "y1vzFkEgcuXnvkAfm627pwarx4HRNikX" #elif defined(MQTT_ID2_AUTH) #define PRODUCT_KEY "micKUvuzOps" #define DEVICE_NAME "00AAAAAABBBBBB4B645F5800" #define DEVICE_SECRET "v9mqGzepKEphLhXmAoiaUIR2HZ7XwTky" #else #ifdef PKG_USING_ALI_IOTKIT_PRODUCT_KEY #define PRODUCT_KEY PKG_USING_ALI_IOTKIT_PRODUCT_KEY #else #define PRODUCT_KEY "yfTuLfBJTiL" #endif #ifdef PKG_USING_ALI_IOTKIT_DEVICE_NAME #define DEVICE_NAME PKG_USING_ALI_IOTKIT_DEVICE_NAME #else #define DEVICE_NAME "TestDeviceForDemo" #endif #ifdef PKG_USING_ALI_IOTKIT_DEVICE_SECRET #define DEVICE_SECRET PKG_USING_ALI_IOTKIT_DEVICE_SECRET #else #define DEVICE_SECRET "fSCl9Ns5YPnYN8Ocg0VEel1kXFnRlV6c" #endif #endif #ifdef PKG_USING_ALI_IOTKIT_IS_LINKDEVELOP /* ALINK TSL Device attribute report */ #define ALINK_PROPERTY_POST_PUB "/sys/"PRODUCT_KEY"/"DEVICE_NAME"/thing/event/property/post" #define ALINK_PROPERTY_POST_REPLY_SUB "/sys/"PRODUCT_KEY"/"DEVICE_NAME"/thing/event/property/post_reply" #define ALINK_PROPERTY_SET_REPLY_SUB "/sys/"PRODUCT_KEY"/"DEVICE_NAME"/thing/event/property/set_reply" #define ALINK_SERVICE_SET_SUB "/sys/"PRODUCT_KEY"/"DEVICE_NAME"/thing/service/property/set" #else #define TOPIC_UPDATE "/"PRODUCT_KEY"/"DEVICE_NAME"/update" #define TOPIC_ERROR "/"PRODUCT_KEY"/"DEVICE_NAME"/update/error" #define TOPIC_GET "/"PRODUCT_KEY"/"DEVICE_NAME"/get" #define TOPIC_DATA "/"PRODUCT_KEY"/"DEVICE_NAME"/data" #endif /* These are pre-defined topics format*/ #define TOPIC_UPDATE_FMT "/%s/%s/update" #define TOPIC_ERROR_FMT "/%s/%s/update/error" #define TOPIC_GET_FMT "/%s/%s/get" #define TOPIC_DATA_FMT "/%s/%s/data" #define MQTT_MSGLEN (1024) #define EXAMPLE_TRACE(fmt, ...) \ do { \ HAL_Printf("%s|%03d :: ", __func__, __LINE__); \ HAL_Printf(fmt, ##__VA_ARGS__); \ HAL_Printf("%s", "
"); \ } while(0) static char __product_key[PRODUCT_KEY_LEN + 1]; static char __device_name[DEVICE_NAME_LEN + 1]; static char __device_secret[DEVICE_SECRET_LEN + 1]; static int user_argc; static char *user_param = NULL; static void *pclient; static uint8_t is_running = 0; static char* rt_strlwr(char *str) { if(str == NULL) return NULL; char *p = str; while (*p != '\0') { if(*p >= 'A' && *p <= 'Z') *p = (*p) + 0x20; p++; } return str; } static void event_handle(void *pcontext, void *pclient, iotx_mqtt_event_msg_pt msg) { iotx_mqtt_topic_info_pt topic_info = (iotx_mqtt_topic_info_pt)msg->msg; uintptr_t packet_id = (uintptr_t)(msg->msg); if (topic_info == NULL) { rt_kprintf("Topic info is null! Exit."); return; } switch (msg->event_type) { case IOTX_MQTT_EVENT_UNDEF: EXAMPLE_TRACE("undefined event occur."); break; case IOTX_MQTT_EVENT_DISCONNECT: EXAMPLE_TRACE("MQTT disconnect."); break; case IOTX_MQTT_EVENT_RECONNECT: EXAMPLE_TRACE("MQTT reconnect."); break; case IOTX_MQTT_EVENT_SUBCRIBE_SUCCESS: EXAMPLE_TRACE("subscribe success, packet-id=%u", (unsigned int)packet_id); break; case IOTX_MQTT_EVENT_SUBCRIBE_TIMEOUT: EXAMPLE_TRACE("subscribe wait ack timeout, packet-id=%u", (unsigned int)packet_id); break; case IOTX_MQTT_EVENT_SUBCRIBE_NACK: EXAMPLE_TRACE("subscribe nack, packet-id=%u", (unsigned int)packet_id); break; case IOTX_MQTT_EVENT_UNSUBCRIBE_SUCCESS: EXAMPLE_TRACE("unsubscribe success, packet-id=%u", (unsigned int)packet_id); break; case IOTX_MQTT_EVENT_UNSUBCRIBE_TIMEOUT: EXAMPLE_TRACE("unsubscribe timeout, packet-id=%u", (unsigned int)packet_id); break; case IOTX_MQTT_EVENT_UNSUBCRIBE_NACK: EXAMPLE_TRACE("unsubscribe nack, packet-id=%u", (unsigned int)packet_id); break; case IOTX_MQTT_EVENT_PUBLISH_SUCCESS: EXAMPLE_TRACE("publish success, packet-id=%u", (unsigned int)packet_id); break; case IOTX_MQTT_EVENT_PUBLISH_TIMEOUT: EXAMPLE_TRACE("publish timeout, packet-id=%u", (unsigned int)packet_id); break; case IOTX_MQTT_EVENT_PUBLISH_NACK: EXAMPLE_TRACE("publish nack, packet-id=%u", (unsigned int)packet_id); break; case IOTX_MQTT_EVENT_PUBLISH_RECVEIVED: EXAMPLE_TRACE("topic message arrived but without any related handle: topic=%.*s, topic_msg=%.*s", topic_info->topic_len, topic_info->ptopic, topic_info->payload_len, topic_info->payload); break; case IOTX_MQTT_EVENT_BUFFER_OVERFLOW: EXAMPLE_TRACE("buffer overflow, %s", msg->msg); break; default: EXAMPLE_TRACE("Should NOT arrive here."); break; } } static void _demo_message_arrive(void *pcontext, void *pclient, iotx_mqtt_event_msg_pt msg) { cJSON* root=cJSON_Parse((const char)* ptopic_info); iotx_mqtt_topic_info_pt ptopic_info = (iotx_mqtt_topic_info_pt) msg->msg; /* print topic name and topic message X*/ EXAMPLE_TRACE("----"); EXAMPLE_TRACE("packetId: %d", ptopic_info->packet_id); EXAMPLE_TRACE("Topic: '%.*s' (Length: %d)", ptopic_info->topic_len, ptopic_info->ptopic, ptopic_info->topic_len); EXAMPLE_TRACE("Payload: '%.*s' (Length: %d)", ptopic_info->payload_len, ptopic_info->payload, ptopic_info->payload_len); EXAMPLE_TRACE("----"); // char * red =strstr(ptopic_info->payload,"\\params\\RGBColor\"Red\":"); // red +=strlen("\"Red\":"); // if(*(red+1)=='}') // { // data=*red-'0'; // } // else if(*(red+2)=='}') // { // data = (*red-'0')*10+(*(red+1)-'0'); // } // else if(*(red+3)=='}') // { // data = (*red-'0')*100+(*(red+1)-'0')*10+(*(red+2)-'0'); // } // EXAMPLE_TRACE("Red:%d",data); // EXAMPLE_TRACE("----"); } #ifndef MQTT_ID2_AUTH static void mqtt_client(void) { int rc = 0; iotx_conn_info_pt pconn_info; iotx_mqtt_param_t mqtt_params; char *msg_buf = NULL, *msg_readbuf = NULL; IOT_OpenLog("mqtt"); IOT_SetLogLevel(IOT_LOG_DEBUG); if (NULL == (msg_buf = (char *)HAL_Malloc(MQTT_MSGLEN))) { EXAMPLE_TRACE("not enough memory"); rc = -1; goto do_exit; } if (NULL == (msg_readbuf = (char *)HAL_Malloc(MQTT_MSGLEN))) { EXAMPLE_TRACE("not enough memory"); rc = -1; goto do_exit; } HAL_GetProductKey(__product_key); HAL_GetDeviceName(__device_name); HAL_GetDeviceSecret(__device_secret); /* Device AUTH */ if (0 != IOT_SetupConnInfo(__product_key, __device_name, __device_secret, (void **)&pconn_info)) { EXAMPLE_TRACE("AUTH request failed!"); rc = -1; goto do_exit; } /* Initialize MQTT parameter */ memset(&mqtt_params, 0x0, sizeof(mqtt_params)); mqtt_params.port = pconn_info->port; mqtt_params.host = pconn_info->host_name; mqtt_params.client_id = pconn_info->client_id; mqtt_params.username = pconn_info->username; mqtt_params.password = pconn_info->password; mqtt_params.pub_key = pconn_info->pub_key; mqtt_params.request_timeout_ms = 2000; mqtt_params.clean_session = 0; mqtt_params.keepalive_interval_ms = 60000; mqtt_params.pread_buf = msg_readbuf; mqtt_params.read_buf_size = MQTT_MSGLEN; mqtt_params.pwrite_buf = msg_buf; mqtt_params.write_buf_size = MQTT_MSGLEN; mqtt_params.handle_event.h_fp = event_handle; mqtt_params.handle_event.pcontext = NULL; /* Convert uppercase letters in host to lowercase */ rt_kprintf("host: %s
", rt_strlwr((char*)mqtt_params.host)); /* Construct a MQTT client with specify parameter */ pclient = IOT_MQTT_Construct(&mqtt_params); if (NULL == pclient) { EXAMPLE_TRACE("MQTT construct failed"); rc = -1; goto do_exit; } #ifdef PKG_USING_ALI_IOTKIT_IS_LINKDEVELOP /* Subscribe the specific topic */ rc = IOT_MQTT_Subscribe(pclient, ALINK_SERVICE_SET_SUB, IOTX_MQTT_QOS1, _demo_message_arrive, NULL); #else rc = IOT_MQTT_Subscribe(pclient, TOPIC_DATA, IOTX_MQTT_QOS1, _demo_message_arrive, NULL); #endif if (rc < 0) { IOT_MQTT_Destroy(&pclient); EXAMPLE_TRACE("IOT_MQTT_Subscribe() failed, rc = %d", rc); rc = -1; goto do_exit; } #ifdef PKG_USING_ALI_IOTKIT_IS_LINKDEVELOP /* Subscribe the specific topic */ rc = IOT_MQTT_Subscribe(pclient, ALINK_PROPERTY_POST_REPLY_SUB, IOTX_MQTT_QOS1, _demo_message_arrive, NULL); if (rc < 0) { IOT_MQTT_Destroy(&pclient); EXAMPLE_TRACE("IOT_MQTT_Subscribe() failed, rc = %d", rc); rc = -1; goto do_exit; } #endif IOT_MQTT_Yield(pclient, 200); do { /* handle the MQTT packet received from TCP or SSL connection */ IOT_MQTT_Yield(pclient, 200); HAL_SleepMs(2000); } while (is_running); IOT_MQTT_Yield(pclient, 200); #ifdef PKG_USING_ALI_IOTKIT_IS_LINKDEVELOP IOT_MQTT_Unsubscribe(pclient, ALINK_PROPERTY_POST_REPLY_SUB); IOT_MQTT_Unsubscribe(pclient, ALINK_SERVICE_SET_SUB); #else IOT_MQTT_Unsubscribe(pclient, TOPIC_DATA); #endif IOT_MQTT_Yield(pclient, 200); IOT_MQTT_Destroy(&pclient); do_exit: if (NULL != msg_buf) { HAL_Free(msg_buf); } if (NULL != msg_readbuf) { HAL_Free(msg_readbuf); } if (NULL != user_param) HAL_Free(user_param); user_param = NULL; IOT_DumpMemoryStats(IOT_LOG_DEBUG); IOT_CloseLog(); is_running = 0; EXAMPLE_TRACE("out of sample!"); } #endif /* MQTT_ID2_AUTH */ #ifdef MQTT_ID2_AUTH #include "tfs.h" static char __device_id2[TFS_ID2_LEN + 1]; static void mqtt_client_secure() { int rc = 0, msg_len, cnt = 0; void *pclient; iotx_conn_info_pt pconn_info; iotx_mqtt_param_t mqtt_params; iotx_mqtt_topic_info_t topic_msg; char msg_pub[128]; char *msg_buf = NULL, *msg_readbuf = NULL; char topic_update[IOTX_URI_MAX_LEN] = {0}; char topic_error[IOTX_URI_MAX_LEN] = {0}; char topic_get[IOTX_URI_MAX_LEN] = {0}; char topic_data[IOTX_URI_MAX_LEN] = {0}; IOT_OpenLog("mqtt"); IOT_SetLogLevel(IOT_LOG_DEBUG); if (NULL == (msg_buf = (char *)HAL_Malloc(MQTT_MSGLEN))) { EXAMPLE_TRACE("not enough memory"); rc = -1; goto do_exit; } if (NULL == (msg_readbuf = (char *)HAL_Malloc(MQTT_MSGLEN))) { EXAMPLE_TRACE("not enough memory"); rc = -1; goto do_exit; } HAL_GetProductKey(__product_key); HAL_GetID2(__device_id2); /* Device AUTH */ rc = IOT_SetupConnInfoSecure(__product_key, __device_id2, __device_id2, (void **)&pconn_info); if (rc != 0) { EXAMPLE_TRACE("AUTH request failed!"); goto do_exit; } HAL_Snprintf(topic_update,IOTX_URI_MAX_LEN,TOPIC_UPDATE_FMT,__product_key,__device_id2); HAL_Snprintf(topic_error,IOTX_URI_MAX_LEN,TOPIC_ERROR_FMT,__product_key,__device_id2); HAL_Snprintf(topic_get,IOTX_URI_MAX_LEN,TOPIC_GET_FMT,__product_key,__device_id2); HAL_Snprintf(topic_data,IOTX_URI_MAX_LEN,TOPIC_DATA_FMT,__product_key,__device_id2); /* Initialize MQTT parameter */ memset(&mqtt_params, 0x0, sizeof(mqtt_params)); mqtt_params.port = pconn_info->port; mqtt_params.host = pconn_info->host_name; mqtt_params.client_id = pconn_info->client_id; mqtt_params.username = pconn_info->username; mqtt_params.password = pconn_info->password; mqtt_params.pub_key = pconn_info->pub_key; mqtt_params.request_timeout_ms = 2000; mqtt_params.clean_session = 0; mqtt_params.keepalive_interval_ms = 60000; mqtt_params.pread_buf = msg_readbuf; mqtt_params.read_buf_size = MQTT_MSGLEN; mqtt_params.pwrite_buf = msg_buf; mqtt_params.write_buf_size = MQTT_MSGLEN; mqtt_params.handle_event.h_fp = event_handle; mqtt_params.handle_event.pcontext = NULL; /* Construct a MQTT client with specify parameter */ pclient = IOT_MQTT_ConstructSecure(&mqtt_params); if (NULL == pclient) { EXAMPLE_TRACE("MQTT construct failed"); rc = -1; goto do_exit; } /* Subscribe the specific topic */ rc = IOT_MQTT_Subscribe(pclient, topic_data, IOTX_MQTT_QOS1, _demo_message_arrive, NULL); if (rc < 0) { IOT_MQTT_Destroy(&pclient); EXAMPLE_TRACE("IOT_MQTT_Subscribe() failed, rc = %d", rc); rc = -1; goto do_exit; } HAL_SleepMs(1000); /* Initialize topic information */ memset(&topic_msg, 0x0, sizeof(iotx_mqtt_topic_info_t)); strcpy(msg_pub, "message: hello! start!"); topic_msg.qos = IOTX_MQTT_QOS1; topic_msg.retain = 0; topic_msg.dup = 0; topic_msg.payload = (void *)msg_pub; topic_msg.payload_len = strlen(msg_pub); rc = IOT_MQTT_Publish(pclient, topic_data, &topic_msg); EXAMPLE_TRACE("rc = IOT_MQTT_Publish() = %d", rc); do { /* Generate topic message */ cnt++; msg_len = snprintf(msg_pub, sizeof(msg_pub), "{\"attr_name\":\"temperature\", \"attr_value\":\"%d\"}", cnt); if (msg_len < 0) { EXAMPLE_TRACE("Error occur! Exit program"); rc = -1; break; } topic_msg.payload = (void *)msg_pub; topic_msg.payload_len = msg_len; rc = IOT_MQTT_Publish(pclient, topic_data, &topic_msg); if (rc < 0) { EXAMPLE_TRACE("error occur when publish"); rc = -1; break; } EXAMPLE_TRACE("packet-id=%u, publish topic msg='0x%02x%02x%02x%02x'...", (uint32_t)rc, msg_pub[0], msg_pub[1], msg_pub[2], msg_pub[3] ); /* handle the MQTT packet received from TCP or SSL connection */ IOT_MQTT_Yield(pclient, 200); /* infinite loop if running with 'loop' argument */ if (user_argc >= 2 && user_param && !strcmp("loop", user_param)) { HAL_SleepMs(2000); cnt = 0; } } while (cnt < 1); IOT_MQTT_Unsubscribe(pclient, TOPIC_DATA); HAL_SleepMs(200); IOT_MQTT_Destroy(&pclient); do_exit: if (NULL != msg_buf) { HAL_Free(msg_buf); } if (NULL != msg_readbuf) { HAL_Free(msg_readbuf); } if (NULL != user_param) HAL_Free(user_param); user_param = NULL; IOT_DumpMemoryStats(IOT_LOG_DEBUG); IOT_CloseLog(); EXAMPLE_TRACE("out of sample!"); } #endif /* MQTT_ID2_AUTH*/ static int ali_mqtt_test_pub(void) { int rc = 0; static uint16_t pub_msg_cnt = 0; uint8_t rgb_switch = 0, rand_num_r = 0, rand_num_g = 0, rand_num_b = 0; char msg_pub[512]; iotx_mqtt_topic_info_t topic_msg; if (!is_running) { HAL_Printf("MQTT test is not running! Please start MQTT first by using the \"ali_mqtt_test start\" command"); return 0; } if (user_param && !strcmp("open", user_param)) { rgb_switch = 1; } else if (user_param && !strcmp("close", user_param)) { rgb_switch = 0; } else { return 0; } srand((int)(rt_tick_get()) / (pub_msg_cnt + 1)); rand_num_r = (uint8_t)(rand()%255); srand((int)(rt_tick_get()) / (pub_msg_cnt + 2)); rand_num_g = (uint8_t)(rand()%255); srand((int)(rt_tick_get()) / (pub_msg_cnt + 3)); rand_num_b = (uint8_t)(rand()%255); /* Initialize topic information */ memset(msg_pub, 0x0, sizeof(msg_pub)); snprintf(msg_pub, sizeof(msg_pub), "{\"id\" : \"%d\",\"version\":\"1.0\",\"params\" : " "{\"RGBColor\" : {\"Red\":%d,\"Green\":%d,\"Blue\":%d}," "\"LightSwitch\" : %d}," "\"method\":\"thing.event.property.post\"}", ++pub_msg_cnt, rand_num_r, rand_num_g, rand_num_b, rgb_switch); memset(&topic_msg, 0x0, sizeof(iotx_mqtt_topic_info_t)); topic_msg.qos = IOTX_MQTT_QOS1; topic_msg.retain = 0; topic_msg.dup = 0; topic_msg.payload = (void *)msg_pub; topic_msg.payload_len = strlen(msg_pub); #ifdef PKG_USING_ALI_IOTKIT_IS_LINKDEVELOP rc = IOT_MQTT_Publish(pclient, ALINK_PROPERTY_POST_PUB, &topic_msg); if (rc < 0) { IOT_MQTT_Destroy(&pclient); EXAMPLE_TRACE("error occur when publish"); rc = -1; return rc; } EXAMPLE_TRACE("
publish message:topic: %s
payload: %s
rc = %d", ALINK_PROPERTY_POST_PUB, topic_msg.payload, rc); #else rc = IOT_MQTT_Publish(pclient, TOPIC_UPDATE, &topic_msg); if (rc < 0) { IOT_MQTT_Destroy(&pclient); EXAMPLE_TRACE("error occur when publish"); rc = -1; return rc; } EXAMPLE_TRACE("
publish message:topic: %s
payload: \%s
rc = %d", TOPIC_UPDATE, topic_msg.payload, rc); rc = IOT_MQTT_Publish(pclient, TOPIC_DATA, &topic_msg); if (rc < 0) { IOT_MQTT_Destroy(&pclient); EXAMPLE_TRACE("error occur when publish"); rc = -1; return rc; } EXAMPLE_TRACE("
publish message:topic: %s
payload: \%s
rc = %d", TOPIC_DATA, topic_msg.payload, rc); #endif return 0; } static int ali_mqtt_main(int argc, char **argv) { rt_thread_t tid; user_argc = argc; if (2 == user_argc) { if (!strcmp("start", argv[1])) { if (1 == is_running) { HAL_Printf("MQTT test is already running! Please stop running first by using the \"ali_mqtt_test stop\" command
"); return 0; } is_running = 1; } else if (!strcmp("stop", argv[1])) { if (0 == is_running) { HAL_Printf("MQTT test is already stopped!
"); return 0; } is_running = 0; // stop mqtt test return 0; } else { HAL_Printf("Input param error! Example: ali_mqtt_test start/stop or ali_mqtt_test pub open/close
"); return 0; } } else if(3 == user_argc) { if (!strcmp("pub", argv[1])) { user_param = (char*)rt_strdup((const char*)argv[2]); HAL_Printf("param:%s
", user_param); // publish ali_mqtt_test_pub(); return 0; } else { HAL_Printf("Input param error! Example: ali_mqtt_test start/stop or ali_mqtt_test pub open/close
"); return 0; } } else { HAL_Printf("Input param error! Example: ali_mqtt_test start/stop or ali_mqtt_test pub open/close
"); return 0; } #ifdef IOTX_PRJ_VERSION HAL_Printf("iotkit-embedded sdk version: %s
", IOTX_PRJ_VERSION); #endif HAL_SetProductKey(PRODUCT_KEY); HAL_SetDeviceName(DEVICE_NAME); HAL_SetDeviceSecret(DEVICE_SECRET); #ifndef MQTT_ID2_AUTH tid = rt_thread_create("ali-mqtt", (void (*)(void *))mqtt_client, NULL, 6 * 1024, RT_THREAD_PRIORITY_MAX / 2 - 1, 10); #else tid = rt_thread_create("ali-mqtt", mqtt_client_secure, NULL, 6 * 1024, RT_THREAD_PRIORITY_MAX / 2 - 1, 10); #endif if (tid != RT_NULL) rt_thread_startup(tid); return 0; } #ifdef RT_USING_FINSH #include
MSH_CMD_EXPORT_ALIAS(ali_mqtt_main, ali_mqtt_test, Example: ali_mqtt_test start/pub [open/close]/stop); #endif ```
查看更多
10
个回答
默认排序
按发布时间排序
flyboy
2019-10-26
Do my self();
第一步应该是把这个做参数解析,ptopic_info->payload_len
coulson
2019-10-27
这家伙很懒,什么也没写!
>第一步应该是把这个做参数解析,ptopic_info->payload_len --- 能否详细说一下,我的微信15518189521
coulson
2019-10-27
这家伙很懒,什么也没写!
>第一步应该是把这个做参数解析,ptopic_info->payload_len --- cJSON* root=cJSON_Parse(ptopic_info->payload); 我是这样做的,但是通过cJSON* itemName = cJSON_GetObjectItem(root, "parms");后得到值是空的
bigmagic
2019-10-28
这家伙很懒,什么也没写!
代码太长了,应该放json解析的关键代码,这样看起来才明白一些。第三张图片,cJSON_Parse存放的是json格式的数据串。
coulson
2019-10-28
这家伙很懒,什么也没写!
[i=s] 本帖最后由 coulson 于 2019-10-28 11:25 编辑 [/i] [attach]11854[/attach]
coulson
2019-10-28
这家伙很懒,什么也没写!
>代码太长了,应该放json解析的关键代码,这样看起来才明白一些。第三张图片,cJSON_Parse存放的是json格式 ... --- 下面是解析部分的代码,我之前看错了,以为cJSON_Parse()是获取json字符串的跟目录,昨天发现不是,但是我参考网上的资料获取json字符串里的代码还是不正确,能帮我看看吗,私聊也可以,我的weixin15518189521
coulson
2019-10-29
这家伙很懒,什么也没写!
>第一步应该是把这个做参数解析,ptopic_info->payload_len --- 输入ptopic_info-> payload_len这个参数编译出错,只有ptopic_info-> payload是正常的
flyboy
2019-10-29
Do my self();
>输入ptopic_info-> payload_len这个参数编译出错,只有ptopic_info-> payload是正常的 > ... --- 嗯嗯,我当时打错了,确实应该是这个 ptopic_info-> payload
flyboy
2019-10-29
Do my self();
>下面是解析部分的代码,我之前看错了,以为cJSON_Parse()是获取json字符串的跟目录,昨天发现不是,但 ... --- 解析不对的话,可以多换几个API试试,cjson 一共没几个API,可以都处理一边这块内存,看哪个能解析出来。
coulson
2019-10-30
这家伙很懒,什么也没写!
>解析不对的话,可以多换几个API试试,cjson 一共没几个API,可以都处理一边这块内存,看哪个能解析出来。 ... --- 好的,经过反复测试,JSON的数据解析问题已经解决了,非常感谢
撰写答案
登录
注册新账号
关注者
0
被浏览
2.2k
关于作者
coulson
这家伙很懒,什么也没写!
提问
36
回答
106
被采纳
1
关注TA
发私信
相关问题
1
lwip1.4.1连接经常会断开无法连接上,可以ping通
2
LPC1768:RTT+LWIP+webserver用IE刷网页出现硬件中断错误(已经解决)
3
求一些LWIP开发的经验,目前ping一直不稳定。
4
stm32f207+dp83848无法ping通
5
RTT下的LWIP传递机制
6
rtt内lwip的socket是否是线程安全?
7
Lwip+enc28j60无法ping通
8
坑爹的rtconfig.h lwip关掉了checksum
9
花了一个晚上,把RT2.0的LWIP、网卡驱动、文件系统整合起来了,发现一点小问题
10
lwip例程中udp发送时如何指定源端口发送到指定目的地端口
推荐文章
1
RT-Thread应用项目汇总
2
玩转RT-Thread系列教程
3
国产MCU移植系列教程汇总,欢迎查看!
4
机器人操作系统 (ROS2) 和 RT-Thread 通信
5
五分钟玩转RT-Thread新社区
6
【技术三千问】之《玩转ART-Pi》,看这篇就够了!干货汇总
7
关于STM32H7开发板上使用SDIO接口驱动SD卡挂载文件系统的问题总结
8
STM32的“GPU”——DMA2D实例详解
9
RT-Thread隐藏的宝藏之completion
10
【ART-PI】RT-Thread 开启RTC 与 Alarm组件
最新文章
1
在RT-Thread Studio中构建前执行python命令
2
研究一了一段时间RTT,直接标准版上手太难,想用nano,但又舍不得组件
3
CherryUSB开发笔记(一):FSDEV USB IP核的 HID Remote WakeUp (USB HID 远程唤醒) 2025-01-18 V1.1
4
RT-thread 缩写字典
5
RT Thread 源码分析笔记 :线程和调度器
热门标签
RT-Thread Studio
串口
Env
LWIP
SPI
AT
Bootloader
Hardfault
CAN总线
FinSH
ART-Pi
USB
DMA
文件系统
RT-Thread
SCons
RT-Thread Nano
线程
MQTT
STM32
RTC
FAL
rt-smart
I2C_IIC
ESP8266
UART
WIZnet_W5500
ota在线升级
PWM
cubemx
flash
freemodbus
BSP
packages_软件包
潘多拉开发板_Pandora
定时器
ADC
flashDB
GD32
socket
编译报错
中断
Debug
rt_mq_消息队列_msg_queue
SFUD
msh
keil_MDK
ulog
MicroPython
C++_cpp
本月问答贡献
出出啊
1517
个答案
342
次被采纳
小小李sunny
1444
个答案
290
次被采纳
张世争
813
个答案
177
次被采纳
crystal266
547
个答案
161
次被采纳
whj467467222
1222
个答案
149
次被采纳
本月文章贡献
聚散无由
2
篇文章
14
次点赞
catcatbing
2
篇文章
4
次点赞
Wade
2
篇文章
2
次点赞
Ghost_Girls
1
篇文章
4
次点赞
xiaorui
1
篇文章
1
次点赞
回到
顶部
发布
问题
分享
好友
手机
浏览
扫码手机浏览
投诉
建议
回到
底部