<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[有没有大神帮忙看看xr806的http的get接口获取数较大的适合会容易出现下面问题]]></title><description><![CDATA[<p dir="auto">有没有大神帮忙看看，附件的代码，在执行之后，会出现获取的内容后半段是乱码的情况<br />
试用xr806芯片，开发板，采用example里面的httpc例程，适当修改如下，主要功能就是通过天气接口，获取天气json数据，然后调用cjson接口解析</p>
<pre><code>/*
 * Copyright (C) 2017 XRADIO TECHNOLOGY CO., LTD. All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions
 *  are met:
 *    1. Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *    2. Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the
 *       distribution.
 *    3. Neither the name of XRADIO TECHNOLOGY CO., LTD. nor the names of
 *       its contributors may be used to endorse or promote products derived
 *       from this software without specific prior written permission.
 *
 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include &lt;stdio.h&gt;
#include "kernel/os/os.h"
#include "common/framework/platform_init.h"
#include "net/wlan/wlan.h"
#include "common/framework/net_ctrl.h"
#include "net/HTTPClient/HTTPCUsr_api.h"
#include "mbedtls/mbedtls.h"


#include "cjson/cJSON.h"



#define  DEMO_TEST_FUNC_TIME		1
#define  DEMO_TEST_FUNC_WEATHER		2

#define  DEMO_TEST_FUNC				DEMO_TEST_FUNC_WEATHER

#define HTTPC_DEMO_THREAD_STACK_SIZE (16 * 1024) /* ssl need more stack */
static OS_Thread_t httpc_demo_thread;

#if (DEMO_TEST_FUNC == DEMO_TEST_FUNC_WEATHER)
#	define HTTPC_DEMO_URL "http://t.weather.sojson.com/api/weather/city/101210101"
#else
#	define HTTPC_DEMO_URL "http://quan.suning.com/getSysTime.do"
#endif

static HTTPParameters httpc_demo_param;
char httpc_demo_buf[8192] = {0};


static void httpc_demo_download(char *url, int use_ssl)
{
	uint32_t download_len = 0;
	INT32 recv_len = 0;
	int32_t ret;
	uint32_t download_time = 0;

	memset(&amp;httpc_demo_param, 0, sizeof(httpc_demo_param));
	memcpy(httpc_demo_param.Uri, url, strlen(url));
	httpc_demo_param.nTimeout = 30; //timeout 30s for every get

	download_time = OS_GetTicks();

	memset(httpc_demo_buf, 0, sizeof(httpc_demo_buf));

	while (1) {
		ret = HTTPC_get(&amp;httpc_demo_param, httpc_demo_buf, sizeof(httpc_demo_buf), &amp;recv_len);

		if (ret != HTTP_CLIENT_SUCCESS) {
			break;
		}
		download_len += recv_len;
		printf("%.*s", sizeof(httpc_demo_buf), httpc_demo_buf);

		printf("\n\nhttp get return value: %d, len=%u\n\n", ret, download_len);
	}
	if (ret == HTTP_CLIENT_EOS) {
		download_time = OS_GetTicks() - download_time;
		printf("\n\n\ndownload complete, download_len %d, time %ds\n\n\n",
		       download_len, download_time/1000);

		cJSON* cjson = cJSON_Parse(httpc_demo_buf);//将JSON字符串转换成JSON结构体
		if(cjson == NULL)						//判断转换是否成功
		{
			printf("cjson error...\n\n");
		}
		else
		{
			printf("%s\n\n",cJSON_Print(cjson));//打包成功调用cJSON_Print打印输出

#if (DEMO_TEST_FUNC == DEMO_TEST_FUNC_WEATHER)
			char * city = cJSON_GetObjectItem(cjson,"city")-&gt;valuestring;	
			char * temp = cJSON_GetObjectItem(cjson,"wendu")-&gt;valuestring;	
			char * humi = cJSON_GetObjectItem(cjson,"shidu")-&gt;valuestring;	

			printf("城市: %s\n",city);
			printf("温度：%s\n",temp);
			printf("湿度：%s\n",humi);
#else
			char * time_1 = cJSON_GetObjectItem(cjson,"sysTime1")-&gt;valuestring;
			char * time_2 = cJSON_GetObjectItem(cjson,"sysTime2")-&gt;valuestring;

			printf("time_1: %s\n\n",time_1);
			printf("time_2: %s\n\n",time_2);
#endif
		}
	} else {
		printf("\n\ndownload error, ret=%d\n", ret);
	}
}

static void httpc_demo_fun(void *arg)
{
	while(1)
	{
		httpc_demo_download(HTTPC_DEMO_URL, 0);
		OS_MSleep(5000);
	}	

	OS_ThreadDelete(&amp;httpc_demo_thread);
}

static void net_cb(uint32_t event, uint32_t data, void *arg)
{
	uint16_t type = EVENT_SUBTYPE(event);

	switch (type) {
	case NET_CTRL_MSG_NETWORK_UP:
		if (!OS_ThreadIsValid(&amp;httpc_demo_thread)) {
			OS_ThreadCreate(&amp;httpc_demo_thread,
			                    "httpc_demo_thread",
			                    httpc_demo_fun,
			                    (void *)NULL,
			                    OS_THREAD_PRIO_APP,
			                    HTTPC_DEMO_THREAD_STACK_SIZE);
		}
		break;

	case NET_CTRL_MSG_NETWORK_DOWN:
		break;

	default:
		break;
	}

}

int main(void)
{
	observer_base *net_ob;

	platform_init();

	printf("httpc demo start\n\n");

	printf("use these commands to connect ap:\n\n");
	printf("1. config ssid and password : net sta config ssid password\n");
	printf("2. enable sta to connect ap : net sta enable\n\n");

	/* create an observer to monitor the net work state */
	net_ob = sys_callback_observer_create(CTRL_MSG_TYPE_NETWORK,
	                                     NET_CTRL_MSG_ALL,
	                                     net_cb,
	                                     NULL);
	if (net_ob == NULL)
		return -1;

	if (sys_ctrl_attach(net_ob) != 0)
		return -1;

	return 0;
}


</code></pre>
<p dir="auto"><img src="/assets/uploads/files/1697469286528-1bff697d-4e41-4cfc-ab03-2ab9f825f8b8-image.png" alt="1bff697d-4e41-4cfc-ab03-2ab9f825f8b8-image.png" class=" img-responsive img-markdown" width="231" height="387" /></p>
<p dir="auto">配网之后，拉取http数据，出现了后半段乱码的情形</p>
<p dir="auto"><img src="/assets/uploads/files/1697469392362-5117d7af-a5c3-4cb9-888d-43ae10c1854f-image.png" alt="5117d7af-a5c3-4cb9-888d-43ae10c1854f-image.png" class=" img-responsive img-markdown" width="1045" height="676" /></p>
<p dir="auto">判了一小段时间更是出现了heap问题<br />
<img src="/assets/uploads/files/1697469410638-96250826-7d51-4fe0-b0f6-f4cab5e7b48a-image.png" alt="96250826-7d51-4fe0-b0f6-f4cab5e7b48a-image.png" class=" img-responsive img-markdown" width="756" height="963" /></p>
<p dir="auto">但我看这个heap已经开到了200多KB了，应该不至于这么快出现问题<br />
<img src="/assets/uploads/files/1697469478276-d6f6d6bd-8975-48c5-b7de-85b4e6bc1b18-image.png" alt="d6f6d6bd-8975-48c5-b7de-85b4e6bc1b18-image.png" class=" img-responsive img-markdown" width="945" height="448" /></p>
<p dir="auto">请大神们帮忙把把关，把把脉，感激不尽！</p>
<p dir="auto"><a href="/assets/uploads/files/1697469234677-httpc.rar">httpc.rar</a></p>
]]></description><link>https://bbs.aw-ol.com/topic/4427/有没有大神帮忙看看xr806的http的get接口获取数较大的适合会容易出现下面问题</link><generator>RSS for Node</generator><lastBuildDate>Sat, 16 May 2026 17:59:48 GMT</lastBuildDate><atom:link href="https://bbs.aw-ol.com/topic/4427.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 16 Oct 2023 15:18:59 GMT</pubDate><ttl>60</ttl></channel></rss>