diff --git a/ezlopi-cloud/ezlopi-cloud-network/ezlopi_cloud_network.c b/ezlopi-cloud/ezlopi-cloud-network/ezlopi_cloud_network.c index 48e5cc77e..3a5c5e4b6 100644 --- a/ezlopi-cloud/ezlopi-cloud-network/ezlopi_cloud_network.c +++ b/ezlopi-cloud/ezlopi-cloud-network/ezlopi_cloud_network.c @@ -25,23 +25,45 @@ void network_get(cJSON* cj_request, cJSON* cj_response) cJSON* wifi_properties = cJSON_CreateObject(); if (wifi_properties) { - cJSON_Delete(ethernet_ipv4); - ethernet_ipv4 = NULL; + char tmp_string[64]; + cJSON_AddStringToObject(wifi_properties, ezlopi__id_str, ezlopi_wifi_str); + cJSON_AddStringToObject(wifi_properties, ezlopi_enabled_str, ezlopi_auto_str); + + uint8_t mac_addr[6]; + esp_read_mac(mac_addr, ESP_MAC_WIFI_STA); + snprintf(tmp_string, sizeof(tmp_string), "%02x:%02x:%02x:%02x:%02x:%02x", MAC_ADDR_EXPANDED(mac_addr)); + cJSON_AddStringToObject(wifi_properties, ezlopi_hwaddr_str, tmp_string); + cJSON_AddBoolToObject(wifi_properties, ezlopi_internetAvailable_str, true); + cJSON_AddStringToObject(wifi_properties, ezlopi_network_str, ezlopi_wan_str); + cJSON_AddStringToObject(wifi_properties, ezlopi_status_str, ezlopi_up_str); + cJSON_AddStringToObject(wifi_properties, ezlopi_type_str, ezlopi_wifi_str); + + cJSON* wifi_ipv4 = cJSON_CreateObject(); + if (wifi_ipv4) + { + esp_netif_ip_info_t* ip_info = ezlopi_wifi_get_ip_infos(); + snprintf(tmp_string, sizeof(tmp_string), IPSTR, IP2STR(&ip_info->gw)); + cJSON_AddStringToObject(wifi_ipv4, ezlopi_ip_str, tmp_string); + snprintf(tmp_string, sizeof(tmp_string), IPSTR, IP2STR(&ip_info->ip)); + cJSON_AddStringToObject(wifi_ipv4, ezlopi_mask_str, tmp_string); + snprintf(tmp_string, sizeof(tmp_string), IPSTR, IP2STR(&ip_info->netmask)); + cJSON_AddStringToObject(wifi_ipv4, ezlopi_gateway_str, tmp_string); + cJSON_AddStringToObject(wifi_ipv4, ezlopi_mode_str, ezlopi_dhcp_str); + + if (!cJSON_AddItemToObjectCS(wifi_properties, ezlopi_ipv4_str, wifi_ipv4)) + { + cJSON_Delete(wifi_ipv4); + wifi_ipv4 = NULL; + } + } + + if (!cJSON_AddItemToArray(interfaces_array, wifi_properties)) + { + cJSON_Delete(wifi_properties); + } } } - cJSON_AddStringToObject(ethernet_properties, ezlopi_network_str, ezlopi_wan_str); - cJSON_AddStringToObject(ethernet_properties, ezlopi_status_str, ezlopi_down_str); - cJSON_AddStringToObject(ethernet_properties, ezlopi_type_str, ezlopi_ethernet_str); - if (!cJSON_AddItemToArray(interface_array, ethernet_properties)) - { - cJSON_Delete(ethernet_properties); - } } - else - { - ret = 1; - } - return ret; } static int get_wifi_properties(cJSON* interface_array) @@ -100,20 +122,21 @@ static int get_wifi_properties(cJSON* interface_array) } return ret; } +} - void network_wifi_scan_start(cJSON * cj_request, cJSON * cj_response) - { - ezlopi_wifi_scan_start(); - cJSON_AddItemReferenceToObject(cj_response, ezlopi_id_str, cJSON_GetObjectItem(cj_request, ezlopi_id_str)); - cJSON_AddItemReferenceToObject(cj_response, ezlopi_method_str, cJSON_GetObjectItem(cj_request, ezlopi_method_str)); - cJSON* cjson_result = cJSON_AddObjectToObject(cj_response, ezlopi_result_str); - } +void network_wifi_scan_start(cJSON* cj_request, cJSON* cj_response) +{ + ezlopi_wifi_scan_start(); + cJSON_AddItemReferenceToObject(cj_response, ezlopi_id_str, cJSON_GetObjectItem(cj_request, ezlopi_id_str)); + cJSON_AddItemReferenceToObject(cj_response, ezlopi_method_str, cJSON_GetObjectItem(cj_request, ezlopi_method_str)); + cJSON* cjson_result = cJSON_AddObjectToObject(cj_response, ezlopi_result_str); +} - void network_wifi_scan_stop(cJSON * cj_request, cJSON * cj_response) - { - ezlopi_wifi_scan_stop(); - cJSON_AddItemReferenceToObject(cj_response, ezlopi_id_str, cJSON_GetObjectItem(cj_request, ezlopi_id_str)); - cJSON_AddItemReferenceToObject(cj_response, ezlopi_method_str, cJSON_GetObjectItem(cj_request, ezlopi_method_str)); - cJSON* cjson_result = cJSON_AddObjectToObject(cj_response, ezlopi_result_str); - } +void network_wifi_scan_stop(cJSON* cj_request, cJSON* cj_response) +{ + ezlopi_wifi_scan_stop(); + cJSON_AddItemReferenceToObject(cj_response, ezlopi_id_str, cJSON_GetObjectItem(cj_request, ezlopi_id_str)); + cJSON_AddItemReferenceToObject(cj_response, ezlopi_method_str, cJSON_GetObjectItem(cj_request, ezlopi_method_str)); + cJSON* cjson_result = cJSON_AddObjectToObject(cj_response, ezlopi_result_str); +} diff --git a/ezlopi-core/ezlopi-core-wifi/ezlopi_core_wifi.c b/ezlopi-core/ezlopi-core-wifi/ezlopi_core_wifi.c index 165199e25..78ea87e56 100644 --- a/ezlopi-core/ezlopi-core-wifi/ezlopi_core_wifi.c +++ b/ezlopi-core/ezlopi-core-wifi/ezlopi_core_wifi.c @@ -222,7 +222,7 @@ static void __event_handler(void* arg, esp_event_base_t event_base, int32_t even else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_SCAN_DONE) { wifi_event_sta_scan_done_t* scan_event_param = (wifi_event_sta_scan_done_t*)event_data; - TRACE_B("status: %d, event data: %d", scan_event_param->status, scan_event_param->number); + TRACE_I("status: %d, event data: %d", scan_event_param->status, scan_event_param->number); if (scan_event_param->status == 0) { total_wifi_APs_available = scan_event_param->number; @@ -443,7 +443,7 @@ static void ezlopi_wifi_scanner_task(void* params) current_time = (xTaskGetTickCount() - start_time); if (current_time <= (5 * 60 * configTICK_RATE_HZ)) { - TRACE_B("Scanning time: %d", current_time); + TRACE_I("Scanning time: %d", current_time); // Scanning for available AP for about 30s. This is because, the scanning tends to prevent data TX/RX over wifi. if (current_time - previous_scan_time >= 30000) { @@ -455,7 +455,7 @@ static void ezlopi_wifi_scanner_task(void* params) } else { - TRACE_B("5 minutes passed, stopping scanner."); + TRACE_I("5 minutes passed, stopping scanner."); break; } vTaskDelay(1000 / portTICK_PERIOD_MS);