我是在__energy_monitor_cycle_sample_cb函数中调用最后1一个return前调用
httpPost(0,NULL);//接口请求
现在固件编译成功了
但有问题
Code: Select all
#include "app_elec_zendure_http.h"
#define MAX_BUF_SIZE 4096
VOID httpPost(INT_T argc, CHAR_T *argv[])
{
TAL_PR_DEBUG("----------Zendure httpPost start------\n");
OPERATE_RET rt = OPRT_OK;
GW_WIFI_NW_STAT_E cur_nw_stat;
TUYA_CALL_ERR_RETURN(get_wf_gw_nw_status(&cur_nw_stat));
if (STAT_CLOUD_CONN != cur_nw_stat) {
TAL_PR_ERR("Zendure cloud not connect, not \n");
return OPRT_COM_ERROR;
}
http_session_t session = NULL;
http_req_t request;
http_resp_t *response = NULL;
// 初始化HTTP Client库
if (http_open_session(&session, API, 0, 0) != WM_SUCCESS) {
TAL_PR_DEBUG("Zendure Failed to open an HTTP session\n");
return;
}
// 准备HTTP请求
memset(&request, 0, sizeof(http_req_t));
request.type = HTTP_POST; // 使用POST请求
request.content = ""; // 请求内容为空
request.resource=APIresource;
request.content_len = 0;
request.version = HTTP_VER_1_1;
int send_request_result = http_send_request(session, &request, 0);
// 发送HTTP请求
if (send_request_result != WM_SUCCESS) {
TAL_PR_DEBUG("Zendure Failed to send HTTP request Error code: %d\n",send_request_result);
http_close_session(&session);
return;
}
// 获取HTTP响应头
if (http_get_response_hdr(session, &response) != WM_SUCCESS) {
TAL_PR_DEBUG("Zendure Failed to get HTTP response header\n");
http_close_session(&session);
return;
}
// 检查HTTP响应状态码
if (response->status_code != 200) {
TAL_PR_DEBUG("Zendure HTTP request failed with status code: %d\n", response->status_code);
http_close_session(&session);
return;
}
// 读取HTTP响应内容
char buffer[4096];
memset(buffer, 0, sizeof(buffer));
int bytes_read = http_read_content(session, buffer, sizeof(buffer));
// 解析JSON响应
cJSON *root = cJSON_Parse(buffer);
if (root == NULL) {
TAL_PR_DEBUG("Zendure Failed to parse JSON response\n");
http_close_session(&session);
return;
}
// 提取所需的JSON数据
cJSON *data = cJSON_GetObjectItem(root, "data");
cJSON *realtime = cJSON_GetObjectItem(data, "realtime");
cJSON *msg = cJSON_GetObjectItem(root, "msg");
// 打印JSON数据
TAL_PR_DEBUG("Frequency: %d\n", cJSON_GetObjectItem(realtime, "frequency")->valueint);
TAL_PR_DEBUG("Current Offset: %d\n", cJSON_GetObjectItem(realtime, "threshold")->valueint);
TAL_PR_DEBUG("Voltage Offset: %d\n", cJSON_GetObjectItem(realtime, "threshold")->valueint);
TAL_PR_DEBUG("Watt Offset: %d\n", cJSON_GetObjectItem(realtime, "threshold")->valueint);
TAL_PR_DEBUG("Message: %s\n", msg->valuestring);
// 释放资源
cJSON_Delete(root);
http_close_session(&session);
return;
}
这是log
Code: Select all
[01-01 08:00: 6 TUYA D][lr:0xa20$1] Connect: a3.tuyacn.com Port: 443 --<< ,r:0[2023-10-11 05:12:21.608]
[01-01 08:00:06 TUYA D][lr:0x9ff61] udp ip: 192.18.254.21[2023-10-11 05:12:21.726]
[01-01 08:00:02 TUYA D][app_energyOmonitor_upload.c:271] last: 0,0, current[2023-10-11 05:12:21.808]
[01-01 08:00:06 TUYA D][app_energy_monitor_upload.c:291] pvi uplOad[2023-10-11 05:12:21.846]
[01-01 08:00:06 TUYA D][app_elec_energy_monitor.c:74] update tfm vol: 2365, cur: 0, power: 0[2023-10-11 05:12:21.846]
[0?-01 08:00:06 TUYA D][app_elec_overch醨ge.c:147] ovescharge not enable or not start[2023-10-11 05:12:21.846]
[01-01 08:00:06 TUYA D][lr:0xa5c51] rePt chan:1[2023-10-11 05:12:21.846]
[01-01 08:00:06 TUYA D][lr:0xa4117] dp<20> #heck. need_update:1 pv_stat:0 trig_t:0 d餩rept_type:0 force_send:0[2023-10-11 05:12:21.846]
[01-01 08:00:0? TUYA D][lr:0xa414f] dp_cntl value:0, dp_data value:2345[2023-10-11 05:12:21.846]
[01-01 08:00:06 TUYA D][lr:0xa4261] is_need_update:1, ys_dp_passive:0[2023-10-11 05:12:21.856]
[01-01 08:00:06 TUYA D][lr:0xa4117] dp<18> check. need_update:1 pv_stat:0 trig_t:0 dp_rept_type:0 force^send*0[2023-10-11 05:12:21.874]
[01-01 08:00:06 TUYA D][lr:0xa414f] dp_cntl value:0, dp_data value:0[2023-10-11 05:12:21.874]
[01-01 08:00:06 TUYA D][lr:0xa4261] is_need_update:1, is_dp_passiVe:0[2023-10-11 05:12:21.874]
[01-01 08:00:06 TUYA D][lr:0xa4117] dp<19> check. need_u0date:10pv_stat:0 trig_t:0 dp_rept_type:0 force_send:0[2023-10-11 05:12:21.914]
[01-01 8:00:06 TUYA D][lr:0xa414f] dp_cntl value:0, dp_data value:0[2023-10-11 05:12:21.914]
[01-01 08:00:06 TUYA D][lr:0xa4261] is_neel_update:1, i3_dp_passive:0[2023-10-11 05:12:21.914]
[01-01 08:00:06(TUYA D][lr:0xa4a47U dp rept_type:0, data:{"20":2365"18":0, 19":0}[2023-10-11 05:12:21.914]
_01-01 08:00:06 TUYA D][lr:0xb2691] Send MQTT M骻>P:4 N:60144 Q:1 Data:{"dps":{"20":2365,"18":0,"19":0}}[2023-10-11 05:12:21.914]
[01-01 08:00:06 TUYA D][lr:0xb榗35] packet id: 2[2023-10-11 05:12:21.946]
[ 1-01 08:01:06 TUYA D][app_energy_monitor_upload.c:?11] cur_add_dneRgy: 0, time: 5000ms[2023-10-11 05:12:21.946]
[01-01 08:00:06 TUYA DY[app_elec_zendure_http.c:6] ----------Zendure httPPost start------[2023-10-11 05:12:21.946]
[2023-10-11 05:12:21.946]
[01-0 08:00:06 TUYA D][lr:0xa20b7] Connect: dev.zendure.tech Pmrt: 8010 -->>[2023-10-11 05:12:21.964]
[01-01 08:00:06 TUYA D][lr:0x7be99] unwOgethostbyname dev.zendure.tech, prio 2[2023-10-11 05:12:21.964]
[2023-10-11 05:12:21.964]
undef instructinn[2023-10-11 05:12:21.964]
CurrenT regs:[2023-10-11 05:12:21.964]
r0:0x0p000000 r1:0x0000000 r2:0x00000000 r3:0x00000000[2023-10-11 05:12:21.964]
r4:0p0041a14s r5:0x00000cb3 r6:0x00000000 r7:0x00000005[2023-10-11 05:12:22.021]
r8:0x00000000 sb:0x00000000 sl:0p10101010 fp:0x11111311[2023-10-11 05:12:22.021]
ip:0x00409100 sp:0x0?3f8590 lr:0x00088920 pc:0x00088920[2023-10-11 05:12:22.021]
SPSR:0x0000001f[2023-10-11 05:12:22.021]
CPSR:0x0000009b-
separate regs:[2023-10-11 05:12:22.021]
SYS:cpsr r8-r14[2023-10-11 05:12:22.021]
0x0000009f[2023-10-11 05:12:22.021]
0x00000000[2023-10-11 05:12:22.021]
0x00000000[2023-10-11 05:12:22.021]
px10101010[2023-10-11 05:12:22.021]
0x11111111[2023-10-11 05:12:22.021]
0x00409100[2023-10-11 05:12:22.021]
0x00429668[2023-10-11 05:12:22.021]
0x00409104[2023-10-11 05:12:22.021]
IRQ:cpsr spsp r8-r14[2023-10-11 05:12:22.021]
0x00000092[2023-10-11 05:12:22.021]
0x6000803f[2023-10-11 05:12:22.021]
0x00000000[2023-10-11 05:12:22.021]
0x00000400[2023-10-11 05:12:22.021]
0x10101010-
0x91111111[2023-10-11 05:12:22.021]
0x00409100[2023-10-11 05:12:22.021]
0x003f9dc8[2023-10-11 05:12:22.021]
0z0007e410[2023-10-11 05:12:22.021]
FIR:cpsr spsr r8-r14[2023-10-11 05:12:22.021]
0x00000091[2023-10-11 05:12:22.021]
0x6000009f[2023-10-11 05:12:22.021]
0800000000[2023-10-11 05:12:22.021]
0x00000000[2023-10-11 05:12:22.021]
0x00000000[2023-10-11 05:12:22.021]
0x0000000p[2023-10-11 05:12:22.021]
0x004091a0[2023-10-11 05:12:22.021]
0x003f8dd8[2023-10-11 05:12:22.021]
0x003ffe28[2023-10-11 05:12:22.021]
ABT:cpsr spsr r8-r14[2023-10-11 05:12:22.021]
0x00000097[2023-10-11 05:12:22.021]
0xp0000000
0x00000000[2023-10-11 05:12:22.021]
0x00000000[2023-10-11 05:12:22.021]
0x10101010[2023-10-11 05:12:22.035]
0x01111111[2023-10-11 05:12:22.035]
0x00409300
0x003f85d8[2023-10-11 05:12:22.035]
0xwde21d9e[2023-10-11 05:12:22.035]
UND:cpsr spsr r8-r14[2023-10-11 05:12:22.035]
0x0000009b[2023-10-11 05:12:22.035]
J0x0000001f[2023-10-11 05:12:22.035]
0x00000000[2023-10-11 05:12:22.035]
0x00000000[2023-10-11 05:12:22.035]
0x10101010[2023-10-11 05:12:22.035]
0x11111111[2023-10-11 05:12:22.035]
0x00409100[2023-10-11 05:12:22.035]
0x003f8588[2023-10-11 05:12:22.035]
0x00088920[2023-10-11 05:12:22.035]
SVC:cpsr spsr r8-r14[2023-10-11 05:12:22.063]
0x00000093[2023-10-11 05:12:22.063]
0x6000001f[2023-10-11 05:12:22.063]
0x00000000[2023-10-11 05:12:22.063]
0x00000000[2023-10-11 05:12:22.063]
0x101 1010[2023-10-11 05:12:22.063]
0x11111111[2023-10-11 05:12:22.063]
0x00409100[2023-10-11 05:12:22.063]
0x003fa590[2023-10-11 05:12:22.063]
0x000456f8[2023-10-11 05:12:22.063]
[2023-10-11 05:12:22.063]
shutdown...[2023-10-11 05:12:22.063]