Skip to content

Commit 48b2e47

Browse files
committed
Merge branch 'fix/start_br_web_server_after_ipv4_got' into 'main'
fix(web server): start web server after wifi ipv4/ethernet address is got See merge request espressif/esp-thread-br!117
2 parents 33bec80 + 14c2544 commit 48b2e47

File tree

4 files changed

+30
-18
lines changed

4 files changed

+30
-18
lines changed

.gitlab-ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ build_idf_otcli_examples:
159159

160160
build_docs:
161161
stage: build
162-
image: $CI_DOCKER_REGISTRY/esp-idf-doc-env-v5.0:2-3
162+
image: $CI_DOCKER_REGISTRY/esp-idf-doc-env-v5.1:1-1
163163
variables:
164164
ESP_DOCS_LATEST_BRANCH_NAME: "main"
165165
artifacts:
@@ -177,7 +177,7 @@ build_docs:
177177

178178
.deploy_docs_template:
179179
stage: docs
180-
image: $CI_DOCKER_REGISTRY/esp-idf-doc-env-v5.0:2-3
180+
image: $CI_DOCKER_REGISTRY/esp-idf-doc-env-v5.1:1-1
181181
needs:
182182
- build_docs
183183
variables:

components/esp_ot_br_server/frontend/static/restful.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -488,8 +488,8 @@ function http_server_thread_network_commissioner() {
488488
Topology
489489
-------------------------------------------------------------------- */
490490
function ctrl_thread_network_topology(arg) {
491-
var node_info;
492-
var topology_info;
491+
var node_info = undefined;
492+
var topology_info = undefined;
493493
if (arg == "Running" || arg == "Suspend") {
494494

495495
$.ajax({
@@ -502,6 +502,9 @@ function ctrl_thread_network_topology(arg) {
502502
success : function(msg) {
503503
console_show_response_result(msg);
504504
node_info = msg;
505+
if (node_info != undefined && topology_info != undefined) {
506+
handle_thread_networks_topology_package(node_info, topology_info);
507+
}
505508
},
506509
error : function(msg) { console.log(msg) }
507510
})
@@ -515,7 +518,9 @@ function ctrl_thread_network_topology(arg) {
515518
success : function(msg) {
516519
console_show_response_result(msg);
517520
topology_info = msg;
518-
handle_thread_networks_topology_package(node_info, topology_info);
521+
if (node_info != undefined && topology_info != undefined) {
522+
handle_thread_networks_topology_package(node_info, topology_info);
523+
}
519524
},
520525
error : function(msg) { console.log(msg) }
521526
})
@@ -693,6 +698,9 @@ function draw_thread_topology_graph(arg) {
693698
topology = arg;
694699
d3.selectAll("svg > *").remove();
695700
scale = topology.graph_info.nodes.length;
701+
if (scale > 8) {
702+
scale = 8;
703+
}
696704
len = 150 * Math.sqrt(scale);
697705

698706
// Topology graph

components/esp_ot_br_server/src/esp_br_web.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,21 +1200,24 @@ void disconnect_handler(void *arg, esp_event_base_t event_base, int32_t event_id
12001200
*server = NULL;
12011201
}
12021202

1203-
/*-----------------------------------------------------
1204-
Note:FreeRTOS task
1205-
-----------------------------------------------------*/
1206-
static void ot_task_br_web(void *arg)
1203+
static bool is_br_web_server_started = false;
1204+
static void handler_got_ip_event(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data)
12071205
{
1208-
esp_netif_t *netif = esp_openthread_get_backbone_netif();
1209-
esp_netif_ip_info_t ip_info;
1210-
char ipv4_address[SERVER_IPV4_LEN];
1211-
esp_netif_get_ip_info(netif, &ip_info);
1212-
sprintf((char *)ipv4_address, IPSTR, IP2STR(&ip_info.ip));
1213-
start_esp_br_http_server((const char *)arg, (char *)ipv4_address);
1214-
vTaskDelete(NULL);
1206+
if (!is_br_web_server_started) {
1207+
ip_event_got_ip_t *event = (ip_event_got_ip_t *)event_data;
1208+
char ipv4_address[SERVER_IPV4_LEN];
1209+
sprintf((char *)ipv4_address, IPSTR, IP2STR(&event->ip_info.ip));
1210+
if (start_esp_br_http_server((const char *)arg, (char *)ipv4_address) != NULL) {
1211+
is_br_web_server_started = true;
1212+
} else {
1213+
ESP_LOGE(WEB_TAG, "Fail to start web server");
1214+
}
1215+
} else {
1216+
ESP_LOGW(WEB_TAG, "Web server had already been started");
1217+
}
12151218
}
12161219

12171220
void esp_br_web_start(char *base_path)
12181221
{
1219-
xTaskCreate(ot_task_br_web, "ot_task_br_web", 4096, base_path, 4, NULL);
1222+
ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &handler_got_ip_event, base_path));
12201223
}

examples/basic_thread_border_router/main/esp_ot_br.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,10 @@ void app_main(void)
101101
ESP_ERROR_CHECK(mdns_init());
102102
ESP_ERROR_CHECK(mdns_hostname_set("esp-ot-br"));
103103
esp_set_ota_server_cert((char *)server_cert_pem_start);
104-
launch_openthread_border_router(&platform_config, &rcp_update_config);
105104

106105
#if CONFIG_OPENTHREAD_BR_START_WEB
107106
esp_br_web_start("/spiffs");
108107
#endif
108+
109+
launch_openthread_border_router(&platform_config, &rcp_update_config);
109110
}

0 commit comments

Comments
 (0)