Page 1 of 2

【已解决】关于Tuyaos的http请求问题

Posted: 2023年 Oct 10日 16:25
by dav1d

我按照

demo tuya/Projects/BK7231N_TuyaOS-3.3.4/software/TuyaOS/apps/tuyaos_demo_examples/src/examples/service_http

编写业务功能,但日志打印调用
接口时出现问题!

Q1:API_VERSION作用是什么?
Q2:SDK支持我调用外部接口吗?

Code: Select all

[10-10 15:08:45 TUYA D][lr:0xa8f81] post Data: 枋,"t":1696921725}[2023-10-10 03:08:46.197]
[10-10 15:08:45 TUYA DU[lr:0xa8dc1] Post URL: https://a3.tuyacn.com/d.json?a=http://d%v.zendure.tech:8010/factory/device/tuyaTest&de籌d=6c39474e9dc1b24bf11psw&et=3&t=1696921725&v=1.0&sign=21572eb462eda4879e14f32ca615d12[2023-10-10 03:08:46.212]
[10-10 15:08:48 TUYA E][lr:0xa8ff3] Post Data Return Fail.-4352[2023-10-10 03:08:48.674]
[10-00 15:08:48 TUYA E][app_elec_zendure_http.c:11] ret:-4252[2023-10-10 03:08:48.674]
[10-10 15:08:48 TUYA D][app_elec_zendure_http.c:28] result is NULL[2023-10-10 03:08:48.674]

Code: Select all

#ifndef BUTTON_H
#define BUTTON_H
#include "app_energy_monitor_upload.h"


//参考example http
#ifndef __APP_ELEC_ZENDURE_HTTP_H__
#define __APP_ELEC_ZENDURE_HTTP_H__
//参考example http
#include "tuya_cloud_types.h"
#include "iot_httpc.h"
#include "ty_cJSON.h"

#include "tal_log.h"
#include "tal_system.h"


#define API "http://dev.zendure.tech:8010/factory/device/tuyaTest" 
#define API_VERSION "1.0"
VOID httpPost(INT_T argc, CHAR_T *argv[]);
#endif 

Code: Select all

#include "app_elec_zendure_http.h"
VOID httpPost(INT_T argc, CHAR_T *argv[])
{
    TAL_PR_DEBUG("Zendure httpPost start======>>>>>>>>>>>>>>>>>> ");
    OPERATE_RET rt = OPRT_OK;
    //CHAR_T post_data[] = {"{\"codes\":[\"w.temp\",\"w.pm25\",\"w.sunSet\",\"w.sunRise\",\"t.local\",\"w.humidity\",\"w.condition\",\"w.windSpeed\",\"w.windDir\",\"w.windLevel\",\"w.aqi\",\"w.tips\",\"w.rank\",\"w.pm10\",\"w.o3\",\"w.no2\",\"w.co\",\"w.so2\",\"w.thigh\",\"w.tlow\",\"w.conditionNum\",\"w.realFeel\",\"w.date.7\"]}"};
    CHAR_T post_data[] ={};
    ty_cJSON* result = NULL;
    char *print_data = NULL;

TUYA_CALL_ERR_LOG(iot_httpc_common_post_simple(API, API_VERSION, post_data, NULL, &result));
/**
{
"realtime": { //实时模式
    "frequency": 3, //3秒采样一次
    "threshold": {
        "current_offset": 0, //电流:无
        "voltage_offset": 2, //电压:变化率小于2%,
        "Watt_offset": 20 //功率:变化率小于20%,
    }
},
 "report_freq": 600 //600秒请求一次HTTP
}

*/

if (NULL == result) {
    TAL_PR_DEBUG("result is NULL");
    return;
}

ty_cJSON* realtimeObject = ty_cJSON_GetObjectItem(result, "realtime");


if (realtimeObject) {
    ty_cJSON* frequencyItem = ty_cJSON_GetObjectItem(realtimeObject, "frequency");
    
    if (frequencyItem) {
        int frequency = frequencyItem->valueint;
        
        // 定义一个中间变量,并将频率值赋给它
        unsigned int sampleTimeMs = (unsigned int)(frequency * 1000);
        
        // 然后使用中间变量更新宏的值
        #undef TFM_FAST_SAMPLE_TIME_MS
        #define TFM_FAST_SAMPLE_TIME_MS sampleTimeMs
        
        TAL_PR_NOTICE("Zendure TFM_FAST_SAMPLE_TIME_MS updated to %u\n", TFM_FAST_SAMPLE_TIME_MS);
    } else {
        TAL_PR_NOTICE("Zendure Unable to retrieve 'frequency' attribute.\n");
    }
} else {
    TAL_PR_NOTICE("Zendure Unable to retrieve 'realtime' object.\n");
}

if (realtimeObject) {
ty_cJSON_Delete(realtimeObject);
realtimeObject = NULL; 
}

print_data = ty_cJSON_PrintUnformatted(result);
if (NULL != print_data) {
    TAL_PR_NOTICE("Zendure print_data: %s", print_data);
    ty_cJSON_FreeBuffer(print_data);
    print_data = NULL;
}

ty_cJSON_Delete(result);
result = NULL;

return;
}

Re: 关于tuyaos_wf_bk7231n_elp-tuyaos_wf_bk7231n_elp_plug的http请求问题

Posted: 2023年 Oct 11日 09:35
by yangjie

API_VERSION作用是什么?
这个是涂鸦的 API 使用的。

iot_httpc_common_post_simple() 是端门为涂鸦API 进行封装的函数。

我看你这个示例应该是需要调用第三方的 API 接口,不是要调用涂鸦的API 接口。你需要使用 include/components/lib_http/include 中提供的接口,这是一个开源库,相关使用方法你可以在网上搜索下。


Re: 关于tuyaos_wf_bk7231n_elp-tuyaos_wf_bk7231n_elp_plug的http请求问题

Posted: 2023年 Oct 11日 09:50
by dav1d

好的,谢谢


Re: 关于tuyaos_wf_bk7231n_elp-tuyaos_wf_bk7231n_elp_plug的http请求问题

Posted: 2023年 Oct 11日 16:40
by dav1d

两个问题:
1.我在这个httppost函数中加入网络判断,但在编译的时候报错误

note: in expansion of macro 'TUYA_CALL_ERR_RETURN'
TUYA_CALL_ERR_RETURN(get_wf_gw_nw_status(&cur_nw_stat));

2.请求http中,http_send_request返回-1,不知道问题在哪里。

代码如下:

Code: Select all

#ifndef __APP_ELEC_ZENDURE_HTTP_H__
#define __APP_ELEC_ZENDURE_HTTP_H__


#include "tal_log.h"
#include "tal_system.h"
#include "httpc.h"
#include "cJSON.h"
#include <stdio.h>
#include <string.h>
#include "tuya_app_config.h"
#include "ty_sys.h"

#include "tuya_wifi_status.h"

#define API "dev.zendure.tech:8010" 
#define APIresource "/factory/device/tuyaTest" 
VOID httpPost(INT_T argc, CHAR_T *argv[]);
#endif 

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");
      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; }

Re: 关于tuyaos_wf_bk7231n_elp-tuyaos_wf_bk7231n_elp_plug的http请求问题

Posted: 2023年 Oct 11日 16:54
by yangjie

你再调用改demo前是否调用了 example_soc_device_init() 示例,需要先调用 example_soc_device_init()


Re: 关于tuyaos_wf_bk7231n_elp-tuyaos_wf_bk7231n_elp_plug的http请求问题

Posted: 2023年 Oct 11日 16:58
by yingtao_33

TUYA_CALL_ERR_RETURN 想要使用这个宏
1.需要确认包含了 tuya_error_code.h 的头文件。
2.需要自己声明 OPERATE_RET rt = OPRT_OK;

第二个问题,需要提供详细一些的报错日志


Re: 关于tuyaos_wf_bk7231n_elp-tuyaos_wf_bk7231n_elp_plug的http请求问题

Posted: 2023年 Oct 11日 17:15
by dav1d

我是在__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]

Re: 关于tuyaos_wf_bk7231n_elp-tuyaos_wf_bk7231n_elp_plug的http请求问题

Posted: 2023年 Oct 11日 17:26
by yangjie
dav1d 2023年 Oct 11日 17:15

我是在__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]

你先不要和计量的代码耦合,单独跑这个demo试一试,这个是程序跑飞掉了,你先查一下看哪里导致他跑飞了。
httpPost 这个函数返回值是 void 型的,你不要 return OPRT_COM_ERROR;


Re: 关于tuyaos_wf_bk7231n_elp-tuyaos_wf_bk7231n_elp_plug的http请求问题

Posted: 2023年 Oct 11日 17:36
by dav1d

单独跑的话,会出现以下log

[app_elec_zendure_http.c:6] ----------Zendure httpPost start------[2023-10-11 05:35:17.934]
[2023-10-11 05:35:17.934]
[01-01 08:00:11 TUYA D][lr:0xa20b7] Connect: dev.zendure.tech Port: 8010 -->>[2023-10-11 05:35:17.934]
[01-01 08:00:11 TUYA D][lr:0x7be99] unw_gethost鈟name eev.zendure.tech, prio 2[2023-10-11 05:35:17.964]
[2023-10-11 05:35:17.964]
[01[2023-10-11 05:35:17.964]
01 08:00:11 TUYA D][lr:0x7bf35] use dynamic dns ip:47.75.126.35for domain:dev.zendupe.tech[2023-10-11 05:35:17.964]
[01-01 08:00:11 TUYA D][lr:0xc0c71] bind IP:c0a8fe15 `ort:0 ok[2023-10-11 05:35:17.964]
[01-01 08:00811 TUYA D][lr:0xa20d1] Connect: d鍁.:endure.tech Port: 8010 --<< ,r:0[2023-10-11 05:35:18.071]
[01-01 08:00:11 TUYA E][lr:0xa242b] Cannot send request[2023-10-11 05:35:18.071]
[01-01 08:01:11 TUYA D][app_elec]zendure_http.c:33] Zendure Failed to send HTTP request Error code:$-1[2023-10-11 05:35:18.080]
[2023-10-11 05:35:18.080]
[01- 1 08:00:11 TUYA D[lr0xc0cfd] tcp transporteb close wocket fd:5[2023-10-11 05:35:18.097]


Re: 关于tuyaos_wf_bk7231n_elp-tuyaos_wf_bk7231n_elp_plug的http请求问题

Posted: 2023年 Oct 11日 17:51
by dav1d

我想应该要把httpPost放在TUYA_CALL_ERR_RETURN()里面,就不会影响整体程序运行?这个函数要怎么修改才能放进去TUYA_CALL_ERR_RETURN?