mirror of
https://github.com/openshwprojects/OpenBK7231T_App.git
synced 2026-02-09 18:05:38 +00:00
Logging update to include level and feature codes.
This commit is contained in:
@ -23,7 +23,7 @@ void start_tcp_http()
|
||||
(beken_thread_arg_t)0 );
|
||||
if(err != kNoErr)
|
||||
{
|
||||
os_printf("create \"TCP_server\" thread failed!\r\n");
|
||||
ADDLOG_ERROR(LOG_FEATURE_HTTP, "create \"TCP_server\" thread failed!\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
@ -68,7 +68,7 @@ static void tcp_client_thread( beken_thread_arg_t arg )
|
||||
|
||||
if ( request.receivedLen <= 0 )
|
||||
{
|
||||
os_printf( "TCP Client is disconnected, fd: %d", fd );
|
||||
ADDLOG_ERROR(LOG_FEATURE_HTTP, "TCP Client is disconnected, fd: %d", fd );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
@ -76,7 +76,7 @@ static void tcp_client_thread( beken_thread_arg_t arg )
|
||||
// returns length to be sent if any
|
||||
int lenret = HTTP_ProcessPacket(&request);
|
||||
if (lenret > 0){
|
||||
addLog( "TCP sending reply len %i\n",lenret );
|
||||
ADDLOG_DEBUG(LOG_FEATURE_HTTP, "TCP sending reply len %i\n",lenret );
|
||||
send( fd, reply, lenret, 0 );
|
||||
}
|
||||
|
||||
@ -84,7 +84,7 @@ static void tcp_client_thread( beken_thread_arg_t arg )
|
||||
|
||||
exit:
|
||||
if ( err != kNoErr )
|
||||
addLog( "TCP client thread exit with err: %d", err );
|
||||
ADDLOG_ERROR(LOG_FEATURE_HTTP, "TCP client thread exit with err: %d", err );
|
||||
|
||||
if ( buf != NULL )
|
||||
os_free( buf );
|
||||
@ -128,7 +128,7 @@ static void tcp_server_thread( beken_thread_arg_t arg )
|
||||
if ( client_fd >= 0 )
|
||||
{
|
||||
os_strcpy( client_ip_str, inet_ntoa( client_addr.sin_addr ) );
|
||||
addLog( "TCP Client %s:%d connected, fd: %d", client_ip_str, client_addr.sin_port, client_fd );
|
||||
ADDLOG_DEBUG(LOG_FEATURE_HTTP, "TCP Client %s:%d connected, fd: %d", client_ip_str, client_addr.sin_port, client_fd );
|
||||
if ( kNoErr
|
||||
!= rtos_create_thread( NULL, BEKEN_APPLICATION_PRIORITY,
|
||||
"TCP Clients",
|
||||
@ -144,7 +144,7 @@ static void tcp_server_thread( beken_thread_arg_t arg )
|
||||
}
|
||||
|
||||
if ( err != kNoErr )
|
||||
addLog( "Server listerner thread exit with err: %d", err );
|
||||
ADDLOG_ERROR(LOG_FEATURE_HTTP, "Server listerner thread exit with err: %d", err );
|
||||
|
||||
close( tcp_listen_fd );
|
||||
rtos_delete_thread( NULL );
|
||||
|
||||
@ -613,7 +613,7 @@ int HTTP_ProcessPacket(http_request_t *request) {
|
||||
tuya_hal_wifi_all_ap_scan(&ar,&num);
|
||||
bk_printf("Scan returned %i networks\r\n",num);
|
||||
for(i = 0; i < num; i++) {
|
||||
sprintf(tmpA,"[%i/%i] SSID: %s, Channel: %i, Signal %i<br>",i,num,ar[i].ssid, ar[i].channel, ar[i].rssi);
|
||||
sprintf(tmpA,"[%i/%i] SSID: %s, Channel: %i, Signal %i<br>",i,(int)num,ar[i].ssid, ar[i].channel, ar[i].rssi);
|
||||
poststr(request,tmpA);
|
||||
}
|
||||
tuya_hal_wifi_release_ap(ar);
|
||||
|
||||
@ -60,6 +60,7 @@ static int http_rest_app(http_request_t *request){
|
||||
}
|
||||
|
||||
static int http_rest_get(http_request_t *request){
|
||||
ADDLOG_DEBUG(LOG_FEATURE_API, "GET of %s", request->url);
|
||||
if (!strcmp(request->url, "api/pins")){
|
||||
return http_rest_get_pins(request);
|
||||
}
|
||||
@ -120,9 +121,11 @@ static int http_rest_get_pins(http_request_t *request){
|
||||
|
||||
static int http_rest_post(http_request_t *request){
|
||||
char tmp[20];
|
||||
ADDLOG_DEBUG(LOG_FEATURE_API, "POST to %s", request->url);
|
||||
if (!strcmp(request->url, "api/pins")){
|
||||
return http_rest_post_pins(request);
|
||||
}
|
||||
|
||||
http_setup(request, httpMimeTypeHTML);
|
||||
poststr(request, "POST to ");
|
||||
poststr(request, request->url);
|
||||
@ -159,6 +162,7 @@ static int http_rest_post_pins(http_request_t *request){
|
||||
jsmn_init(p);
|
||||
r = jsmn_parse(p, json_str, json_len, t, TOKEN_COUNT);
|
||||
if (r < 0) {
|
||||
ADDLOG_ERROR(LOG_FEATURE_API, "Failed to parse JSON: %d", r);
|
||||
sprintf(tmp,"Failed to parse JSON: %d\n", r);
|
||||
poststr(request, tmp);
|
||||
poststr(request, NULL);
|
||||
@ -169,6 +173,7 @@ static int http_rest_post_pins(http_request_t *request){
|
||||
|
||||
/* Assume the top-level element is an object */
|
||||
if (r < 1 || t[0].type != JSMN_OBJECT) {
|
||||
ADDLOG_ERROR(LOG_FEATURE_API, "Object expected", r);
|
||||
sprintf(tmp,"Object expected\n");
|
||||
poststr(request, tmp);
|
||||
poststr(request, NULL);
|
||||
@ -210,6 +215,8 @@ static int http_rest_post_pins(http_request_t *request){
|
||||
}
|
||||
i += t[i + 1].size + 1;
|
||||
} else {
|
||||
ADDLOG_ERROR(LOG_FEATURE_API, "Unexpected key: %.*s", t[i].end - t[i].start,
|
||||
json_str + t[i].start);
|
||||
sprintf(tmp,"Unexpected key: %.*s\n", t[i].end - t[i].start,
|
||||
json_str + t[i].start);
|
||||
poststr(request, tmp);
|
||||
|
||||
Reference in New Issue
Block a user