diff --git a/src/httpclient/http_client.c b/src/httpclient/http_client.c index 08022c3cd..593256819 100644 --- a/src/httpclient/http_client.c +++ b/src/httpclient/http_client.c @@ -79,7 +79,7 @@ static void httpclient_base64enc(char *out, const char *in) int httpclient_conn(httpclient_t *client) { if (0 != client->net.connect(&client->net)) { - log_err("establish connection failed"); + ADDLOG_ERROR(LOG_FEATURE_HTTP_CLIENT, "establish connection failed"); return ERROR_HTTP_CONN; } @@ -98,13 +98,13 @@ int httpclient_parse_url(const char *url, char *scheme, uint32_t max_scheme_len, char *fragment_ptr; if (host_ptr == NULL) { - log_err("Could not find host"); + ADDLOG_ERROR(LOG_FEATURE_HTTP_CLIENT, "Could not find host"); return ERROR_HTTP_PARSE; /* URL is invalid */ } if (max_scheme_len < host_ptr - scheme_ptr + 1) { /* including NULL-terminating char */ - log_err("Scheme str is too small (%u >= %u)", max_scheme_len, (uint32_t)(host_ptr - scheme_ptr + 1)); + ADDLOG_ERROR(LOG_FEATURE_HTTP_CLIENT, "Scheme str is too small (%u >= %u)", max_scheme_len, (uint32_t)(host_ptr - scheme_ptr + 1)); return ERROR_HTTP_PARSE; } os_memcpy(scheme, scheme_ptr, host_ptr - scheme_ptr); @@ -116,7 +116,7 @@ int httpclient_parse_url(const char *url, char *scheme, uint32_t max_scheme_len, path_ptr = os_strchr(host_ptr, '/'); if (NULL == path_ptr) { - log_err("invalid path"); + ADDLOG_ERROR(LOG_FEATURE_HTTP_CLIENT, "invalid path"); return -1; } @@ -126,7 +126,7 @@ int httpclient_parse_url(const char *url, char *scheme, uint32_t max_scheme_len, if (maxhost_len < host_len + 1) { /* including NULL-terminating char */ - log_err("Host str is too long (host_len(%d) >= max_len(%d))", host_len + 1, maxhost_len); + ADDLOG_ERROR(LOG_FEATURE_HTTP_CLIENT, "Host str is too long (host_len(%d) >= max_len(%d))", host_len + 1, maxhost_len); return ERROR_HTTP_PARSE; } os_memcpy(host, host_ptr, host_len); @@ -141,7 +141,7 @@ int httpclient_parse_url(const char *url, char *scheme, uint32_t max_scheme_len, if (max_path_len < path_len + 1) { /* including NULL-terminating char */ - log_err("Path str is too small (%d >= %d)", max_path_len, path_len + 1); + ADDLOG_ERROR(LOG_FEATURE_HTTP_CLIENT, "Path str is too small (%d >= %d)", max_path_len, path_len + 1); return ERROR_HTTP_PARSE; } os_memcpy(path, path_ptr, path_len); @@ -156,20 +156,20 @@ int httpclient_parse_host(const char *url, char *host, int *port, uint32_t maxho uint32_t host_len = 0; char *path_ptr; - log_err("Parse url %s\r\n", url); + ADDLOG_INFO(LOG_FEATURE_HTTP_CLIENT, "Parse url %s\r\n", url); if (!strncmp(url, "HTTPS://", 8)){ - log_err("HTTPS:// found -> port 443\r\n"); + ADDLOG_INFO(LOG_FEATURE_HTTP_CLIENT, "HTTPS:// found -> port 443\r\n"); *port = 443; } else { if (!strncmp(url, "HTTP://", 7)){ - log_err("HTTP:// found -> port 80\r\n"); + ADDLOG_INFO(LOG_FEATURE_HTTP_CLIENT, "HTTP:// found -> port 80\r\n"); *port = 80; } } if (host_ptr == NULL) { - log_err("Could not find host"); + ADDLOG_ERROR(LOG_FEATURE_HTTP_CLIENT, "Could not find host"); return ERROR_HTTP_PARSE; /* URL is invalid */ } host_ptr += 3; @@ -179,7 +179,7 @@ int httpclient_parse_host(const char *url, char *host, int *port, uint32_t maxho if (maxhost_len < host_len + 1) { /* including NULL-terminating char */ - log_err("Host str is too small (%d >= %d)", maxhost_len, host_len + 1); + ADDLOG_ERROR(LOG_FEATURE_HTTP_CLIENT, "Host str is too small (%d >= %d)", maxhost_len, host_len + 1); return ERROR_HTTP_PARSE; } os_memcpy(host, host_ptr, host_len); @@ -195,7 +195,7 @@ int httpclient_parse_host(const char *url, char *host, int *port, uint32_t maxho if (num == 1){ *port = p; } - log_err("Host split into %s port %d\r\n", host, *port); + ADDLOG_INFO(LOG_FEATURE_HTTP_CLIENT, "Host split into %s port %d\r\n", host, *port); } return SUCCESS_RETURN; @@ -263,11 +263,11 @@ int httpclient_send_auth(httpclient_t *client, char *send_buf, int *send_idx) httpclient_get_info(client, send_buf, send_idx, "Authorization: Basic ", 0); sprintf(base64buff, "%s:%s", client->auth_user, client->auth_password); - log_debug("bAuth: %s", base64buff) ; + ADDLOG_DEBUG(LOG_FEATURE_HTTP_CLIENT, "bAuth: %s", base64buff) ; httpclient_base64enc(b_auth, base64buff); b_auth[os_strlen(b_auth) + 1] = '\0'; b_auth[os_strlen(b_auth)] = '\n'; - log_debug("b_auth:%s", b_auth) ; + ADDLOG_DEBUG(LOG_FEATURE_HTTP_CLIENT, "b_auth:%s", b_auth) ; httpclient_get_info(client, send_buf, send_idx, b_auth, 0); return SUCCESS_RETURN; } @@ -292,28 +292,28 @@ int httpclient_send_header(httpclient_t *client, const char *url, int method, ht int rc = SUCCESS_RETURN; if (NULL == (host = (char *)os_malloc(HTTPCLIENT_MAX_HOST_LEN))) { - log_err("not enough memory"); + ADDLOG_ERROR(LOG_FEATURE_HTTP_CLIENT, "not enough memory"); return FAIL_RETURN; } if (NULL == (path = (char *)os_malloc(HTTPCLIENT_MAX_HOST_LEN))) { - log_err("not enough memory"); + ADDLOG_ERROR(LOG_FEATURE_HTTP_CLIENT, "not enough memory"); rc = FAIL_RETURN; goto GO_ERR_3; } if (NULL == (send_buf = (char *)os_malloc(HTTPCLIENT_SEND_BUF_SIZE))) { - log_err("not enough memory"); + ADDLOG_ERROR(LOG_FEATURE_HTTP_CLIENT, "not enough memory"); rc = FAIL_RETURN; goto GO_ERR_2; } if (NULL == (buf = (char *)os_malloc(HTTPCLIENT_SEND_BUF_SIZE))) { - log_err("not enough memory"); + ADDLOG_ERROR(LOG_FEATURE_HTTP_CLIENT, "not enough memory"); rc = FAIL_RETURN; goto GO_ERR_1; } /* First we need to parse the url (http[s]://host[:port][/[path]]) */ int res = httpclient_parse_url(url, scheme, sizeof(scheme), host, HTTPCLIENT_MAX_HOST_LEN, &port, path, HTTPCLIENT_MAX_HOST_LEN); if (res != SUCCESS_RETURN) { - log_err("httpclient_parse_url returned %d\r\n", res); + ADDLOG_ERROR(LOG_FEATURE_HTTP_CLIENT, "httpclient_parse_url returned %d\r\n", res); //return res; rc = res; goto GO_ERR; @@ -336,7 +336,7 @@ int httpclient_send_header(httpclient_t *client, const char *url, int method, ht snprintf(buf, HTTPCLIENT_SEND_BUF_SIZE, "%s %s HTTP/1.1\r\nHost: %s\r\n", meth, path, host); /* Write request */ ret = httpclient_get_info(client, send_buf, &len, buf, os_strlen(buf)); if (ret) { - log_err("Could not write request"); + ADDLOG_ERROR(LOG_FEATURE_HTTP_CLIENT, "Could not write request"); //return ERROR_HTTP_CONN; rc = ERROR_HTTP_CONN; goto GO_ERR; @@ -370,13 +370,13 @@ int httpclient_send_header(httpclient_t *client, const char *url, int method, ht //ret = httpclient_tcp_send_all(client->net.handle, send_buf, len); ret = client->net.write(&client->net, send_buf, len, 5000); if (ret > 0) { - log_debug("Written %d bytes\r\n", ret); + ADDLOG_DEBUG(LOG_FEATURE_HTTP_CLIENT, "Written %d bytes\r\n", ret); } else if (ret == 0) { - log_err("ret == 0,Connection was closed by server\r\n"); + ADDLOG_ERROR(LOG_FEATURE_HTTP_CLIENT, "ret == 0,Connection was closed by server\r\n"); //return ERROR_HTTP_CLOSED; /* Connection was closed by server */ rc = ERROR_HTTP_CLOSED; } else { - log_err("Connection error (send returned %d)\r\n", ret); + ADDLOG_ERROR(LOG_FEATURE_HTTP_CLIENT, "Connection error (send returned %d)\r\n", ret); //return ERROR_HTTP_CONN; rc = ERROR_HTTP_CONN; } @@ -396,17 +396,17 @@ int httpclient_send_userdata(httpclient_t *client, httpclient_data_t *client_dat int ret = 0; if (client_data->post_buf && client_data->post_buf_len) { - log_debug("client_data->post_buf: %s", client_data->post_buf); + ADDLOG_DEBUG(LOG_FEATURE_HTTP_CLIENT, "client_data->post_buf: %s", client_data->post_buf); { //ret = httpclient_tcp_send_all(client->handle, (char *)client_data->post_buf, client_data->post_buf_len); ret = client->net.write(&client->net, (char *)client_data->post_buf, client_data->post_buf_len, 5000); if (ret > 0) { - log_debug("Written %d bytes", ret); + ADDLOG_DEBUG(LOG_FEATURE_HTTP_CLIENT, "Written %d bytes", ret); } else if (ret == 0) { - log_err("ret == 0,Connection was closed by server"); + ADDLOG_ERROR(LOG_FEATURE_HTTP_CLIENT, "ret == 0,Connection was closed by server"); return ERROR_HTTP_CLOSED; /* Connection was closed by server */ } else { - log_err("Connection error (send returned %d)", ret); + ADDLOG_ERROR(LOG_FEATURE_HTTP_CLIENT, "Connection error (send returned %d)", ret); return ERROR_HTTP_CONN; } } @@ -437,13 +437,13 @@ int httpclient_recv(httpclient_t *client, char *buf, int min_len, int max_len, i //timeout return 0; } else if (-1 == ret) { - log_info("Connection closed.\r\n"); + ADDLOG_INFO(LOG_FEATURE_HTTP_CLIENT, "Connection closed.\r\n"); return ERROR_HTTP_CONN; } else { - log_err("Connection error (recv returned %d)\r\n", ret); + ADDLOG_ERROR(LOG_FEATURE_HTTP_CLIENT, "Connection error (recv returned %d)\r\n", ret); return ERROR_HTTP_CONN; } - log_info("httpclient_recv %u bytes has been read\r\n", *p_read_len); + ADDLOG_INFO(LOG_FEATURE_HTTP_CLIENT, "httpclient_recv %u bytes has been read\r\n", *p_read_len); return 0; } @@ -464,7 +464,7 @@ int httpclient_retrieve_content(httpclient_t *client, char *data, int len, uint3 //utils_time_countdown_ms(&timer, timeout_ms); /* Receive data */ - log_debug("Current data len: %d\r\n", len); + ADDLOG_DEBUG(LOG_FEATURE_HTTP_CLIENT, "Current data len: %d\r\n", len); client_data->is_more = true; @@ -704,7 +704,7 @@ int httpclient_response_parse(httpclient_t *client, char *data, int len, uint32_ char *crlf_ptr = os_strstr(data, "\r\n"); if (crlf_ptr == NULL) { - log_err("\r\n not found"); + ADDLOG_ERROR(LOG_FEATURE_HTTP_CLIENT, "\r\n not found"); return ERROR_HTTP_UNRESOLVED_DNS; } @@ -714,16 +714,16 @@ int httpclient_response_parse(httpclient_t *client, char *data, int len, uint32_ /* Parse HTTP response */ if (sscanf(data, "HTTP/%*d.%*d %d %*[^\r\n]", &(client->response_code)) != 1) { /* Cannot match string, error */ - log_err("Not a correct HTTP answer : %s\r\n", data); + ADDLOG_ERROR(LOG_FEATURE_HTTP_CLIENT, "Not a correct HTTP answer : %s\r\n", data); return ERROR_HTTP_UNRESOLVED_DNS; } if ((client->response_code < 200) || (client->response_code >= 400)) { /* Did not return a 2xx code; TODO fetch headers/(&data?) anyway and implement a mean of writing/reading headers */ - log_warning("Response code %d\r\n", client->response_code); + ADDLOG_WARN(LOG_FEATURE_HTTP_CLIENT, "Response code %d\r\n", client->response_code); } - log_debug("Reading headers%s\r\n", data); + ADDLOG_DEBUG(LOG_FEATURE_HTTP_CLIENT, "Reading headers%s\r\n", data); os_memmove(data, &data[crlf_pos + 2], len - (crlf_pos + 2) + 1); /* Be sure to move NULL-terminating char as well */ len -= (crlf_pos + 2); @@ -746,14 +746,14 @@ int httpclient_response_parse(httpclient_t *client, char *data, int len, uint32_ ret = httpclient_recv(client, data + len, 1, HTTPCLIENT_CHUNK_SIZE - len - 1, &new_trf_len, iotx_time_left(&timer)); len += new_trf_len; data[len] = '\0'; - log_debug("Read %d chars; In buf: [%s]\r\n", new_trf_len, data); + ADDLOG_DEBUG(LOG_FEATURE_HTTP_CLIENT, "Read %d chars; In buf: [%s]\r\n", new_trf_len, data); if (ret == ERROR_HTTP_CONN) { return ret; } else { continue; } } else { - log_debug("header len > chunksize\r\n"); + ADDLOG_DEBUG(LOG_FEATURE_HTTP_CLIENT, "header len > chunksize\r\n"); return ERROR_HTTP; } } @@ -770,7 +770,7 @@ int httpclient_response_parse(httpclient_t *client, char *data, int len, uint32_ n = sscanf(data, "%31[^:]: %31[^\r\n]", key, value); if (n == 2) { - log_debug("Read header : %s: %s\r\n", key, value); + ADDLOG_DEBUG(LOG_FEATURE_HTTP_CLIENT, "Read header : %s: %s\r\n", key, value); if (!os_strcmp(key, "Content-Length")) { sscanf(value, "%d", (int *)&(client_data->response_content_len)); client_data->retrieve_len = client_data->response_content_len; @@ -785,14 +785,14 @@ int httpclient_response_parse(httpclient_t *client, char *data, int len, uint32_ len -= (crlf_pos + 2); } else { - log_err("Could not parse header\r\n"); + ADDLOG_ERROR(LOG_FEATURE_HTTP_CLIENT, "Could not parse header\r\n"); return ERROR_HTTP; } } if(client->response_code != 200) { - os_printf("Could not found\r\n"); + ADDLOG_ERROR(LOG_FEATURE_HTTP_CLIENT, "Could not found\r\n"); return MQTT_SUB_INFO_NOT_FOUND_ERROR; } @@ -819,13 +819,13 @@ iotx_err_t httpclient_send_request(httpclient_t *client, const char *url, int me int ret = ERROR_HTTP_CONN; if (0 == client->net.handle) { - log_debug("not connection have been established"); + ADDLOG_ERROR(LOG_FEATURE_HTTP_CLIENT, "not connection have been established"); return ret; } ret = httpclient_send_header(client, url, method, client_data); if (ret != 0) { - log_err("httpclient_send_header is error,ret = %d", ret); + ADDLOG_ERROR(LOG_FEATURE_HTTP_CLIENT, "httpclient_send_header is error,ret = %d", ret); return ret; } @@ -846,7 +846,7 @@ iotx_err_t httpclient_recv_response(httpclient_t *client, uint32_t timeout_ms, h utils_time_countdown_ms(&timer, timeout_ms); if (0 == client->net.handle) { - log_debug("not connection have been established"); + ADDLOG_ERROR(LOG_FEATURE_HTTP_CLIENT, "not connection have been established"); return ret; } @@ -913,20 +913,20 @@ int httpclient_common(httpclient_t *client, const char *url, int port, const cha if (0 == client->net.handle) { //Establish connection if no. httpclient_parse_host(url, host, &port, sizeof(host)); - log_debug("host: '%s', port: %d\r\n", host, port); + ADDLOG_DEBUG(LOG_FEATURE_HTTP_CLIENT, "host: '%s', port: %d\r\n", host, port); iotx_net_init(&client->net, host, port, ca_crt); ret = httpclient_connect(client); if (0 != ret) { - log_err("httpclient_connect is error,ret = %d\r\n", ret); + ADDLOG_ERROR(LOG_FEATURE_HTTP_CLIENT, "httpclient_connect is error,ret = %d\r\n", ret); httpclient_close(client); return ret; } ret = httpclient_send_request(client, url, method, client_data); if (0 != ret) { - log_err("httpclient_send_request is error,ret = %d\r\n", ret); + ADDLOG_ERROR(LOG_FEATURE_HTTP_CLIENT, "httpclient_send_request is error,ret = %d\r\n", ret); httpclient_close(client); return ret; } @@ -939,7 +939,7 @@ int httpclient_common(httpclient_t *client, const char *url, int port, const cha || (0 != client_data->response_buf_len)) { ret = httpclient_recv_response(client, iotx_time_left(&timer), client_data); if (ret < 0) { - log_err("httpclient_recv_response is error,ret = %d\r\n", ret); + ADDLOG_ERROR(LOG_FEATURE_HTTP_CLIENT, "httpclient_recv_response is error,ret = %d\r\n", ret); httpclient_close(client); return ret; } @@ -947,7 +947,7 @@ int httpclient_common(httpclient_t *client, const char *url, int port, const cha if (! client_data->is_more) { //Close the HTTP if no more data. - log_info("close http channel\r\n"); + ADDLOG_INFO(LOG_FEATURE_HTTP_CLIENT, "close http channel\r\n"); httpclient_close(client); } return (ret >= 0) ? 0 : -1; @@ -1016,7 +1016,7 @@ static void httprequest_thread( beken_thread_arg_t arg ) goto exit; } - addLog("host: '%s', port: %d", host, port); + ADDLOG_INFO(LOG_FEATURE_HTTP_CLIENT, "host: '%s', port: %d", host, port); //rtos_delay_milliseconds(500); iotx_net_init(&client->net, host, port, ca_crt); @@ -1027,7 +1027,7 @@ static void httprequest_thread( beken_thread_arg_t arg ) //addLog("after httpclient_connect %d\r\n", ret); //rtos_delay_milliseconds(500); if (0 != ret) { - addLog("httpclient_connect is error,ret = %d", ret); + ADDLOG_ERROR(LOG_FEATURE_HTTP_CLIENT, "httpclient_connect is error,ret = %d", ret); httpclient_close(client); request->state = -1; if (request->data_callback){ @@ -1038,7 +1038,7 @@ static void httprequest_thread( beken_thread_arg_t arg ) ret = httpclient_send_request(client, url, method, client_data); if (0 != ret) { - addLog("httpclient_send_request is error,ret = %d", ret); + ADDLOG_ERROR(LOG_FEATURE_HTTP_CLIENT, "httpclient_send_request is error,ret = %d", ret); httpclient_close(client); request->state = -1; if (request->data_callback){ @@ -1069,7 +1069,7 @@ static void httprequest_thread( beken_thread_arg_t arg ) //addLog("httpclient_recv_response is ret = %d is_more %d", ret, client_data->is_more); //rtos_delay_milliseconds(500); if (ret < 0) { - addLog("httpclient_recv_response is error,ret = %d", ret); + ADDLOG_ERROR(LOG_FEATURE_HTTP_CLIENT, "httpclient_recv_response is error,ret = %d", ret); httpclient_close(client); request->state = -2; if (request->data_callback){ @@ -1090,7 +1090,7 @@ static void httprequest_thread( beken_thread_arg_t arg ) } } while (client_data->is_more); } else { - addLog("httpclient - no response buff"); + ADDLOG_ERROR(LOG_FEATURE_HTTP_CLIENT, "httpclient - no response buff"); } exit: //addLog("close http channel"); @@ -1117,7 +1117,7 @@ int async_request(httprequest_t *request){ (beken_thread_arg_t)request ); if(err != kNoErr) { - bk_printf("create \"httprequest\" thread failed!\r\n"); + ADDLOG_ERROR(LOG_FEATURE_HTTP_CLIENT, "create \"httprequest\" thread failed!\r\n"); return -1; } diff --git a/src/httpserver/http_tcp_server.c b/src/httpserver/http_tcp_server.c index 43390add7..28c34a4d9 100644 --- a/src/httpserver/http_tcp_server.c +++ b/src/httpserver/http_tcp_server.c @@ -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 ); diff --git a/src/httpserver/new_http.c b/src/httpserver/new_http.c index 5f079cfd8..435961f06 100644 --- a/src/httpserver/new_http.c +++ b/src/httpserver/new_http.c @@ -387,6 +387,18 @@ void misc_formatUpTimeString(int totalSeconds, char *o) { sprintf(o,"just %i seconds ",rem_seconds); } } + +int hprintf128(http_request_t *request, const char *fmt, ...){ + va_list argList; + BaseType_t taken; + char tmp[128]; + va_start(argList, fmt); + vsprintf(tmp, fmt, argList); + va_end(argList); + return postany(request, tmp, strlen(tmp)); +} + + int HTTP_ProcessPacket(http_request_t *request) { int i, j; char tmpA[128]; @@ -652,7 +664,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
",i,num,ar[i].ssid, ar[i].channel, ar[i].rssi); + sprintf(tmpA,"[%i/%i] SSID: %s, Channel: %i, Signal %i
",i,(int)num,ar[i].ssid, ar[i].channel, ar[i].rssi); poststr(request,tmpA); } tuya_hal_wifi_release_ap(ar); diff --git a/src/httpserver/new_http.h b/src/httpserver/new_http.h index fa4d97deb..2f9b4ed6a 100644 --- a/src/httpserver/new_http.h +++ b/src/httpserver/new_http.h @@ -40,6 +40,9 @@ void http_setup(http_request_t *request, const char *type); int poststr(http_request_t *request, const char *str); void misc_formatUpTimeString(int totalSeconds, char *o); +// poststr with format - for results LESS THAN 128 +int hprintf128(http_request_t *request, const char *fmt, ...); + enum { HTTP_ANY = -1, HTTP_GET = 0, diff --git a/src/httpserver/rest_interface.c b/src/httpserver/rest_interface.c index bc3b2773b..1a14237af 100644 --- a/src/httpserver/rest_interface.c +++ b/src/httpserver/rest_interface.c @@ -13,6 +13,9 @@ static int http_rest_app(http_request_t *request); static int http_rest_post_pins(http_request_t *request); static int http_rest_get_pins(http_request_t *request); +static int http_rest_post_logconfig(http_request_t *request); +static int http_rest_get_logconfig(http_request_t *request); + void init_rest(){ HTTP_RegisterCallback( "/api/", HTTP_GET, http_rest_get); HTTP_RegisterCallback( "/api/", HTTP_POST, http_rest_post); @@ -60,9 +63,14 @@ 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); } + if (!strcmp(request->url, "api/logconfig")){ + return http_rest_get_logconfig(request); + } + http_setup(request, httpMimeTypeHTML); poststr(request, "GET of "); @@ -74,7 +82,6 @@ static int http_rest_get(http_request_t *request){ static int http_rest_get_pins(http_request_t *request){ int i; - char tmp[20]; /*typedef struct pinsState_s { byte roles[32]; byte channels[32]; @@ -86,30 +93,27 @@ static int http_rest_get_pins(http_request_t *request){ poststr(request, "{\"rolenames\":["); for (i = 0; i < IOR_Total_Options; i++){ if (i){ - sprintf(tmp, ",\"%s\"", htmlPinRoleNames[i]); + hprintf128(request, ",\"%s\"", htmlPinRoleNames[i]); } else { - sprintf(tmp, "\"%s\"", htmlPinRoleNames[i]); + hprintf128(request, "\"%s\"", htmlPinRoleNames[i]); } - poststr(request, tmp); } poststr(request, "],\"roles\":["); for (i = 0; i < 32; i++){ if (i){ - sprintf(tmp, ",%d", g_pins.roles[i]); + hprintf128(request, ",%d", g_pins.roles[i]); } else { - sprintf(tmp, "%d", g_pins.roles[i]); + hprintf128(request, "%d", g_pins.roles[i]); } - poststr(request, tmp); } poststr(request, "],\"channels\":["); for (i = 0; i < 32; i++){ if (i){ - sprintf(tmp, ",%d", g_pins.channels[i]); + hprintf128(request, ",%d", g_pins.channels[i]); } else { - sprintf(tmp, "%d", g_pins.channels[i]); + hprintf128(request, "%d", g_pins.channels[i]); } - poststr(request, tmp); } poststr(request, "]}"); poststr(request, NULL); @@ -118,27 +122,35 @@ static int http_rest_get_pins(http_request_t *request){ -static int http_rest_post(http_request_t *request){ - char tmp[20]; - if (!strcmp(request->url, "api/pins")){ - return http_rest_post_pins(request); +//////////////////////////// +// log config +static int http_rest_get_logconfig(http_request_t *request){ + int i; + http_setup(request, httpMimeTypeJson); + hprintf128(request, "{\"level\":%d,", loglevel); + hprintf128(request, "\"features\":%d,", logfeatures); + poststr(request, "\"levelnames\":["); + for (i = 0; i < LOG_MAX; i++){ + if (i){ + hprintf128(request, ",\"%s\"", loglevelnames[i]); + } else { + hprintf128(request, "\"%s\"", loglevelnames[i]); + } } - http_setup(request, httpMimeTypeHTML); - poststr(request, "POST to "); - poststr(request, request->url); - poststr(request, "
Content Length:"); - sprintf(tmp, "%d", request->contentLength); - poststr(request, tmp); - poststr(request, "
Content:["); - poststr(request, request->bodystart); - poststr(request, "]
"); - poststr(request, htmlEnd); - poststr(request,NULL); + poststr(request, "],\"featurenames\":["); + for (i = 0; i < LOG_FEATURE_MAX; i++){ + if (i){ + hprintf128(request, ",\"%s\"", logfeaturenames[i]); + } else { + hprintf128(request, "\"%s\"", logfeaturenames[i]); + } + } + poststr(request, "]}"); + poststr(request, NULL); return 0; } -// currently crashes the MCU - maybe stack overflow? -static int http_rest_post_pins(http_request_t *request){ +static int http_rest_post_logconfig(http_request_t *request){ int i; int r; char tmp[64]; @@ -159,8 +171,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) { - sprintf(tmp,"Failed to parse JSON: %d\n", r); - poststr(request, tmp); + ADDLOG_ERROR(LOG_FEATURE_API, "Failed to parse JSON: %d", r); poststr(request, NULL); free(p); free(t); @@ -169,8 +180,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) { - sprintf(tmp,"Object expected\n"); - poststr(request, tmp); + ADDLOG_ERROR(LOG_FEATURE_API, "Object expected", r); poststr(request, NULL); free(p); free(t); @@ -183,33 +193,21 @@ static int http_rest_post_pins(http_request_t *request){ /* Loop over all keys of the root object */ for (i = 1; i < r; i++) { - if (jsoneq(json_str, &t[i], "roles") == 0) { - int j; - sprintf(tmp,"- Roles:\n"); - poststr(request, tmp); - if (t[i + 1].type != JSMN_ARRAY) { + if (jsoneq(json_str, &t[i], "level") == 0) { + if (t[i + 1].type != JSMN_PRIMITIVE) { continue; /* We expect groups to be an array of strings */ } - for (j = 0; j < t[i + 1].size; j++) { - jsmntok_t *g = &t[i + j + 2]; - sprintf(tmp," * %.*s\n", g->end - g->start, json_str + g->start); - poststr(request, tmp); - } + loglevel = atoi(json_str + t[i + 1].start); i += t[i + 1].size + 1; - } else if (jsoneq(json_str, &t[i], "channels") == 0) { - int j; - sprintf(tmp,"- Channels:\n"); - poststr(request, tmp); - if (t[i + 1].type != JSMN_ARRAY) { + } else if (jsoneq(json_str, &t[i], "features") == 0) { + if (t[i + 1].type != JSMN_PRIMITIVE) { continue; /* We expect groups to be an array of strings */ } - for (j = 0; j < t[i + 1].size; j++) { - jsmntok_t *g = &t[i + j + 2]; - sprintf(tmp," * %.*s\n", g->end - g->start, json_str + g->start); - poststr(request, tmp); - } + logfeatures = atoi(json_str + t[i + 1].start);; 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); @@ -221,3 +219,122 @@ static int http_rest_post_pins(http_request_t *request){ free(t); return 0; } + +///////////////////////////////////////////////// + + +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); + } + if (!strcmp(request->url, "api/logconfig")){ + return http_rest_post_logconfig(request); + } + + http_setup(request, httpMimeTypeHTML); + poststr(request, "POST to "); + poststr(request, request->url); + poststr(request, "
Content Length:"); + sprintf(tmp, "%d", request->contentLength); + poststr(request, tmp); + poststr(request, "
Content:["); + poststr(request, request->bodystart); + poststr(request, "]
"); + poststr(request, htmlEnd); + poststr(request,NULL); + return 0; +} + +// currently crashes the MCU - maybe stack overflow? +static int http_rest_post_pins(http_request_t *request){ + int i; + int r; + char tmp[64]; + int iChanged = 0; + + //https://github.com/zserge/jsmn/blob/master/example/simple.c + //jsmn_parser p; + jsmn_parser *p = malloc(sizeof(jsmn_parser)); + //jsmntok_t t[128]; /* We expect no more than 128 tokens */ +#define TOKEN_COUNT 128 + jsmntok_t *t = malloc(sizeof(jsmntok_t)*TOKEN_COUNT); + char *json_str = request->bodystart; + int json_len = strlen(json_str); + + http_setup(request, httpMimeTypeText); + memset(p, 0, sizeof(jsmn_parser)); + memset(t, 0, sizeof(jsmntok_t)*128); + + 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); + free(p); + free(t); + return 0; + } + + /* 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); + free(p); + free(t); + return 0; + } + + /* Loop over all keys of the root object */ + for (i = 1; i < r; i++) { + if (jsoneq(json_str, &t[i], "roles") == 0) { + int j; + if (t[i + 1].type != JSMN_ARRAY) { + continue; /* We expect groups to be an array of strings */ + } + for (j = 0; j < t[i + 1].size; j++) { + int roleval, pr; + jsmntok_t *g = &t[i + j + 2]; + roleval = atoi(json_str + g->start); + pr = PIN_GetPinRoleForPinIndex(i); + if(pr != roleval) { + PIN_SetPinRoleForPinIndex(i,roleval); + iChanged++; + } + } + i += t[i + 1].size + 1; + } else if (jsoneq(json_str, &t[i], "channels") == 0) { + int j; + if (t[i + 1].type != JSMN_ARRAY) { + continue; /* We expect groups to be an array of strings */ + } + for (j = 0; j < t[i + 1].size; j++) { + int chanval, pr; + jsmntok_t *g = &t[i + j + 2]; + chanval = atoi(json_str + g->start); + pr = PIN_GetPinChannelForPinIndex(j); + if(pr != chanval) { + PIN_SetPinChannelForPinIndex(j,chanval); + iChanged++; + } + } + 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); + } + } + if (iChanged){ + PIN_SaveToFlash(); + } + + poststr(request, NULL); + free(p); + free(t); + return 0; +} diff --git a/src/logging/logging.c b/src/logging/logging.c index e1fdfde3a..4e7b8e71b 100644 --- a/src/logging/logging.c +++ b/src/logging/logging.c @@ -2,16 +2,38 @@ // Trying to narrow down Boozeman crash. // Is the code with this define enabled crashing/freezing BK after few minutes for anybody? // #define DEBUG_USE_SIMPLE_LOGGER - -#ifdef DEBUG_USE_SIMPLE_LOGGER - #include "../new_common.h" #include "../httpserver/new_http.h" #include "str_pub.h" +#include "../logging/logging.h" SemaphoreHandle_t g_mutex = 0; static char tmp[1024]; +int loglevel = 4; // default to info +unsigned int logfeatures = 0xffffffff; +char *loglevelnames[] = { + "NONE:", + "Error:", + "Warn:", + "Info:", + "Debug:", + "All:" +}; + +char *logfeaturenames[] = { + "HTTP:",// = 0, + "MQTT:",// = 1, + "CFG:",// = 2, + "HTTP_CLIENT:",// = 3, + "OTA:",// = 4, + "PINS:",// = 5, + "MAIN:",// = 6, + "GEN:", // = 7 + "API:", // = 8 +}; + +#ifdef DEBUG_USE_SIMPLE_LOGGER void addLog(char *fmt, ...){ va_list argList; @@ -36,12 +58,42 @@ void addLog(char *fmt, ...){ } } -#else +void addLogAdv(int level, int feature, char *fmt, ...){ + va_list argList; + BaseType_t taken; + char *t = tmp; + if (!((1< loglevel){ + return; + } + if(g_mutex == 0) + { + g_mutex = xSemaphoreCreateMutex( ); + } + // TODO: semaphore -#include "../new_common.h" -#include "../logging/logging.h" -#include "../httpserver/new_http.h" -#include "str_pub.h" + taken = xSemaphoreTake( g_mutex, 100 ); + if (taken == pdTRUE) { + + va_start(argList, fmt); + vsprintf(tmp, fmt, argList); + va_end(argList); + strcpy(t, loglevelnames[level]); + t += strlen(t); + if (feature < sizeof(logfeaturenames)/sizeof(*logfeaturenames)){ + strcpy(t, logfeaturenames[feature]); + t += strlen(t); + } + + bk_printf(tmp); + bk_printf("\r"); + + xSemaphoreGive( g_mutex ); + } +} +#else static int http_getlog(http_request_t *request); static int http_getlograw(http_request_t *request); @@ -67,6 +119,8 @@ static struct tag_logMemory { SemaphoreHandle_t mutex; } logMemory; +int direct_serial_log = DEFAULT_DIRECT_SERIAL_LOG; + static int initialised = 0; static char tmp[1024]; @@ -85,27 +139,28 @@ static void initLog() { // adds a log to the log memory // if head collides with either tail, move the tails on. void addLog(char *fmt, ...){ + int len; va_list argList; + BaseType_t taken; // if not initialised, direct output if (!initialised) { initLog(); } - BaseType_t taken = xSemaphoreTake( logMemory.mutex, 100 ); + taken = xSemaphoreTake( logMemory.mutex, 100 ); va_start(argList, fmt); vsprintf(tmp, fmt, argList); va_end(argList); -//#define DIRECTLOG -#ifdef DIRECTLOG - bk_printf(tmp); - if (taken == pdTRUE){ - xSemaphoreGive( logMemory.mutex ); + if (direct_serial_log){ + bk_printf(tmp); + if (taken == pdTRUE){ + xSemaphoreGive( logMemory.mutex ); + } + return; } - return; -#endif - int len = strlen(tmp); + len = strlen(tmp); tmp[len++] = '\r'; tmp[len++] = '\n'; @@ -130,6 +185,73 @@ void addLog(char *fmt, ...){ } } + + + +// adds a log to the log memory +// if head collides with either tail, move the tails on. +void addLogAdv(int level, int feature, char *fmt, ...){ + char *t = tmp; + if (!((1< loglevel){ + return; + } + + va_list argList; + // if not initialised, direct output + if (!initialised) { + initLog(); + } + BaseType_t taken = xSemaphoreTake( logMemory.mutex, 100 ); + + strcpy(t, loglevelnames[level]); + t += strlen(t); + if (feature < sizeof(logfeaturenames)/sizeof(*logfeaturenames)){ + strcpy(t, logfeaturenames[feature]); + t += strlen(t); + } + + va_start(argList, fmt); + vsprintf(t, fmt, argList); + va_end(argList); + + int len = strlen(tmp); + tmp[len++] = '\r'; + tmp[len++] = '\n'; + +#ifdef DIRECTLOG + bk_printf(tmp); + if (taken == pdTRUE){ + xSemaphoreGive( logMemory.mutex ); + } + return; +#endif + + //bk_printf("addlog %d.%d.%d %d:%s\n", logMemory.head, logMemory.tailserial, logMemory.tailtcp, len,tmp); + + for (int i = 0; i < len; i++){ + logMemory.log[logMemory.head] = tmp[i]; + logMemory.head = (logMemory.head + 1) % LOGSIZE; + if (logMemory.tailserial == logMemory.head){ + logMemory.tailserial = (logMemory.tailserial + 1) % LOGSIZE; + } + if (logMemory.tailtcp == logMemory.head){ + logMemory.tailtcp = (logMemory.tailtcp + 1) % LOGSIZE; + } + if (logMemory.tailhttp == logMemory.head){ + logMemory.tailhttp = (logMemory.tailhttp + 1) % LOGSIZE; + } + } + + if (taken == pdTRUE){ + xSemaphoreGive( logMemory.mutex ); + } +} + + + static int getData(char *buff, int buffsize, int *tail) { if (!initialised) return 0; BaseType_t taken = xSemaphoreTake( logMemory.mutex, 100 ); diff --git a/src/logging/logging.h b/src/logging/logging.h index 0ba15a3c8..5ea3b0649 100644 --- a/src/logging/logging.h +++ b/src/logging/logging.h @@ -1,7 +1,56 @@ -// +/////////////////////////////////////////////////////////////////////////// // intent: To log to a RAM area, which is then sent to serial and/or TCP // +// +// use ADDLOG_XXX(, fmt, vars....) +// +// to log DIRECT to serial for debugging, +// set direct_serial_log = 1 +// or to use from boot, #define DEFAULT_DIRECT_SERIAL_LOG 1 +/////////////////////////////////////////////////////////////////////////// void addLog(char *fmt, ...); +void addLogAdv(int level, int feature, char *fmt, ...); + +#define ADDLOG_ERROR(x, y, ...) addLogAdv(LOG_ERROR, x, y, ##__VA_ARGS__) +#define ADDLOG_WARN(x, y, ...) addLogAdv(LOG_WARN, x, y, ##__VA_ARGS__) +#define ADDLOG_INFO(x, y, ...) addLogAdv(LOG_INFO, x, y, ##__VA_ARGS__) +#define ADDLOG_DEBUG(x, y, ...) addLogAdv(LOG_DEBUG, x, y, ##__VA_ARGS__) + +extern int loglevel; +extern char *loglevelnames[]; + +extern unsigned int logfeatures; +extern char *logfeaturenames[]; + +extern int direct_serial_log; + +// set to 1 to use only direct serial logging at startup - eg for boot issues +#define DEFAULT_DIRECT_SERIAL_LOG 0 +//#define DEFAULT_DIRECT_SERIAL_LOG 1 + +enum { + LOG_NONE = 0, + LOG_ERROR = 1, + LOG_WARN = 2, + LOG_INFO = 3, + LOG_DEBUG = 4, + LOG_ALL = 5, + LOG_MAX = 6 +} log_levels; + +enum { + LOG_FEATURE_HTTP = 0, + LOG_FEATURE_MQTT = 1, + LOG_FEATURE_CFG = 2, + LOG_FEATURE_HTTP_CLIENT = 3, + LOG_FEATURE_OTA = 4, + LOG_FEATURE_PINS = 5, + LOG_FEATURE_MAIN = 6, + LOG_FEATURE_GENERAL = 7, + LOG_FEATURE_API = 8, + // add in here - but also in names in logging.c + LOG_FEATURE_MAX = 9, +} log_features; diff --git a/src/user_main.c b/src/user_main.c index 3dd64ebae..5c55ee7de 100644 --- a/src/user_main.c +++ b/src/user_main.c @@ -49,14 +49,9 @@ #include "lwip/netdb.h" -#undef os_printf -#undef PR_DEBUG -#undef PR_NOTICE + #undef Malloc #undef Free -#define os_printf addLog -#define PR_DEBUG addLog -#define PR_NOTICE addLog #define Malloc os_malloc #define Free os_free @@ -65,8 +60,6 @@ static int g_secondsElapsed = 0; static int g_openAP = 0; -#define tcp_server_log(M, ...) os_printf("TCP", M, ##__VA_ARGS__) - int Time_getUpTimeSeconds() { return g_secondsElapsed; } @@ -91,7 +84,7 @@ int unw_recv(const int fd, void *buf, u32 nbytes) FD_SET( fd, &errfds ); ret = select( fd+1, &readfds, NULL, &errfds, NULL); - os_printf("select ret:%d, %d, %d\r\n", ret, FD_ISSET( fd, &readfds ), FD_ISSET( fd, &errfds )); + ADDLOG_DEBUG(LOG_FEATURE_MAIN, "select ret:%d, %d, %d\r\n", ret, FD_ISSET( fd, &readfds ), FD_ISSET( fd, &errfds )); if(ret > 0 && FD_ISSET( fd, &readfds )) return recv(fd,buf,nbytes,0); @@ -132,7 +125,7 @@ void connect_to_wifi(const char *oob_ssid,const char *connect_key) network_cfg.dhcp_mode = DHCP_CLIENT; network_cfg.wifi_retry_interval = 100; - bk_printf("ssid:%s key:%s\r\n", network_cfg.wifi_ssid, network_cfg.wifi_key); + ADDLOG_INFO(LOG_FEATURE_MAIN, "ssid:%s key:%s\r\n", network_cfg.wifi_ssid, network_cfg.wifi_key); bk_wlan_start(&network_cfg); #endif @@ -143,7 +136,7 @@ beken_timer_t led_timer; static void app_my_channel_toggle_callback(int channel, int iVal) { - PR_NOTICE("Channel has changed! Publishing change %i with %i \n",channel,iVal); + ADDLOG_INFO(LOG_FEATURE_MAIN, "Channel has changed! Publishing change %i with %i \n",channel,iVal); example_publish(mqtt_client,channel,iVal); } @@ -152,7 +145,7 @@ int loopsWithDisconnected = 0; static void app_led_timer_handler(void *data) { if(mqtt_client != 0 && mqtt_client_is_connected(mqtt_client) == 0) { - PR_NOTICE("Timer discovetrs disconnected mqtt %i\n",loopsWithDisconnected); + ADDLOG_INFO(LOG_FEATURE_MAIN, "Timer discovers disconnected mqtt %i\n",loopsWithDisconnected); loopsWithDisconnected++; if(loopsWithDisconnected > 10) { @@ -166,7 +159,7 @@ static void app_led_timer_handler(void *data) } g_secondsElapsed ++; - PR_NOTICE("Timer is %i free mem %d\n", g_secondsElapsed, xPortGetFreeHeapSize()); + ADDLOG_INFO(LOG_FEATURE_MAIN, "Timer is %i free mem %d\n", g_secondsElapsed, xPortGetFreeHeapSize()); // print network info if (!(g_secondsElapsed % 10)){ @@ -217,7 +210,7 @@ static int setup_wifi_open_access_point(void) os_strcpy((char *)wNetConfig.dns_server_ip_addr, APP_DRONE_DEF_NET_GW); - PR_NOTICE("no flash configuration, use default\r\n"); + ADDLOG_INFO(LOG_FEATURE_MAIN, "no flash configuration, use default\r\n"); mac = (u8*)&ap_info.bssid.array; // this is MAC for Access Point, it's different than Client one // see wifi_get_mac_address source @@ -243,14 +236,14 @@ static int setup_wifi_open_access_point(void) wNetConfig.wifi_retry_interval = 100; if(1) { - PR_NOTICE("set ip info: %s,%s,%s\r\n", + ADDLOG_INFO(LOG_FEATURE_MAIN, "set ip info: %s,%s,%s\r\n", wNetConfig.local_ip_addr, wNetConfig.net_mask, wNetConfig.dns_server_ip_addr); } if(1) { - PR_NOTICE("ssid:%s key:%s mode:%d\r\n", wNetConfig.wifi_ssid, wNetConfig.wifi_key, wNetConfig.wifi_mode); + ADDLOG_INFO(LOG_FEATURE_MAIN, "ssid:%s key:%s mode:%d\r\n", wNetConfig.wifi_ssid, wNetConfig.wifi_key, wNetConfig.wifi_mode); } bk_wlan_start(&wNetConfig); @@ -265,7 +258,7 @@ static int setup_wifi_open_access_point(void) void wl_status( void *ctxt ){ rw_evt_type stat = *((rw_evt_type*)ctxt); - bk_printf("wl_status %d\r\n", stat); + ADDLOG_INFO(LOG_FEATURE_MAIN, "wl_status %d\r\n", stat); switch(stat){ case RW_EVT_STA_IDLE: @@ -324,8 +317,8 @@ void user_main(void) wifi_ssid = CFG_GetWiFiSSID(); wifi_pass = CFG_GetWiFiPass(); - PR_NOTICE("Using SSID [%s]\r\n",wifi_ssid); - PR_NOTICE("Using Pass [%s]\r\n",wifi_pass); + ADDLOG_INFO(LOG_FEATURE_MAIN, "Using SSID [%s]\r\n",wifi_ssid); + ADDLOG_INFO(LOG_FEATURE_MAIN, "Using Pass [%s]\r\n",wifi_pass); #if 0 // you can use this if you bricked your module by setting wrong access point data @@ -344,7 +337,7 @@ void user_main(void) connect_to_wifi(wifi_ssid,wifi_pass); // register function to get callbacks about wifi changes. bk_wlan_status_register_cb(wl_status); - PR_NOTICE("Registered for wifi changes\r\n"); + ADDLOG_INFO(LOG_FEATURE_MAIN, "Registered for wifi changes\r\n"); } // NOT WORKING, I done it other way, see ethernetif.c @@ -352,15 +345,15 @@ void user_main(void) //demo_start_upd(); start_tcp_http(); - PR_NOTICE("Started http tcp server\r\n"); + ADDLOG_INFO(LOG_FEATURE_MAIN, "Started http tcp server\r\n"); PIN_Init(); - PR_NOTICE("Initialised pins\r\n"); + ADDLOG_INFO(LOG_FEATURE_MAIN, "Initialised pins\r\n"); PIN_SetGenericDoubleClickCallback(app_on_generic_dbl_click); CHANNEL_SetChangeCallback(app_my_channel_toggle_callback); - PR_NOTICE("Initialised other callbacks\r\n"); + ADDLOG_INFO(LOG_FEATURE_MAIN, "Initialised other callbacks\r\n"); // initialise rest interface @@ -374,7 +367,7 @@ void user_main(void) err = rtos_start_timer(&led_timer); ASSERT(kNoErr == err); - PR_NOTICE("started timer\r\n"); + ADDLOG_INFO(LOG_FEATURE_MAIN, "started timer\r\n"); } #undef Free