Skip to content

Commit

Permalink
Merge branch 'fix/start_br_web_server_after_ipv4_got' into 'main'
Browse files Browse the repository at this point in the history
fix(web server): start web server after wifi ipv4/ethernet address is got

See merge request espressif/esp-thread-br!117
  • Loading branch information
chshu committed Jun 3, 2024
2 parents 33bec80 + 14c2544 commit 48b2e47
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 18 deletions.
4 changes: 2 additions & 2 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ build_idf_otcli_examples:

build_docs:
stage: build
image: $CI_DOCKER_REGISTRY/esp-idf-doc-env-v5.0:2-3
image: $CI_DOCKER_REGISTRY/esp-idf-doc-env-v5.1:1-1
variables:
ESP_DOCS_LATEST_BRANCH_NAME: "main"
artifacts:
Expand All @@ -177,7 +177,7 @@ build_docs:

.deploy_docs_template:
stage: docs
image: $CI_DOCKER_REGISTRY/esp-idf-doc-env-v5.0:2-3
image: $CI_DOCKER_REGISTRY/esp-idf-doc-env-v5.1:1-1
needs:
- build_docs
variables:
Expand Down
14 changes: 11 additions & 3 deletions components/esp_ot_br_server/frontend/static/restful.js
Original file line number Diff line number Diff line change
Expand Up @@ -488,8 +488,8 @@ function http_server_thread_network_commissioner() {
Topology
-------------------------------------------------------------------- */
function ctrl_thread_network_topology(arg) {
var node_info;
var topology_info;
var node_info = undefined;
var topology_info = undefined;
if (arg == "Running" || arg == "Suspend") {

$.ajax({
Expand All @@ -502,6 +502,9 @@ function ctrl_thread_network_topology(arg) {
success : function(msg) {
console_show_response_result(msg);
node_info = msg;
if (node_info != undefined && topology_info != undefined) {
handle_thread_networks_topology_package(node_info, topology_info);
}
},
error : function(msg) { console.log(msg) }
})
Expand All @@ -515,7 +518,9 @@ function ctrl_thread_network_topology(arg) {
success : function(msg) {
console_show_response_result(msg);
topology_info = msg;
handle_thread_networks_topology_package(node_info, topology_info);
if (node_info != undefined && topology_info != undefined) {
handle_thread_networks_topology_package(node_info, topology_info);
}
},
error : function(msg) { console.log(msg) }
})
Expand Down Expand Up @@ -693,6 +698,9 @@ function draw_thread_topology_graph(arg) {
topology = arg;
d3.selectAll("svg > *").remove();
scale = topology.graph_info.nodes.length;
if (scale > 8) {
scale = 8;
}
len = 150 * Math.sqrt(scale);

// Topology graph
Expand Down
27 changes: 15 additions & 12 deletions components/esp_ot_br_server/src/esp_br_web.c
Original file line number Diff line number Diff line change
Expand Up @@ -1200,21 +1200,24 @@ void disconnect_handler(void *arg, esp_event_base_t event_base, int32_t event_id
*server = NULL;
}

/*-----------------------------------------------------
Note:FreeRTOS task
-----------------------------------------------------*/
static void ot_task_br_web(void *arg)
static bool is_br_web_server_started = false;
static void handler_got_ip_event(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data)
{
esp_netif_t *netif = esp_openthread_get_backbone_netif();
esp_netif_ip_info_t ip_info;
char ipv4_address[SERVER_IPV4_LEN];
esp_netif_get_ip_info(netif, &ip_info);
sprintf((char *)ipv4_address, IPSTR, IP2STR(&ip_info.ip));
start_esp_br_http_server((const char *)arg, (char *)ipv4_address);
vTaskDelete(NULL);
if (!is_br_web_server_started) {
ip_event_got_ip_t *event = (ip_event_got_ip_t *)event_data;
char ipv4_address[SERVER_IPV4_LEN];
sprintf((char *)ipv4_address, IPSTR, IP2STR(&event->ip_info.ip));
if (start_esp_br_http_server((const char *)arg, (char *)ipv4_address) != NULL) {
is_br_web_server_started = true;
} else {
ESP_LOGE(WEB_TAG, "Fail to start web server");
}
} else {
ESP_LOGW(WEB_TAG, "Web server had already been started");
}
}

void esp_br_web_start(char *base_path)
{
xTaskCreate(ot_task_br_web, "ot_task_br_web", 4096, base_path, 4, NULL);
ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &handler_got_ip_event, base_path));
}
3 changes: 2 additions & 1 deletion examples/basic_thread_border_router/main/esp_ot_br.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,10 @@ void app_main(void)
ESP_ERROR_CHECK(mdns_init());
ESP_ERROR_CHECK(mdns_hostname_set("esp-ot-br"));
esp_set_ota_server_cert((char *)server_cert_pem_start);
launch_openthread_border_router(&platform_config, &rcp_update_config);

#if CONFIG_OPENTHREAD_BR_START_WEB
esp_br_web_start("/spiffs");
#endif

launch_openthread_border_router(&platform_config, &rcp_update_config);
}

0 comments on commit 48b2e47

Please sign in to comment.