浏览代码

Many many many changes to update the UI. It hurts...

Sebastien L 3 年之前
父节点
当前提交
a5da6bbcf1
共有 24 个文件被更改,包括 1333 次插入133 次删除
  1. 2 6
      .github/workflows/esp-idf-v4.3-build.yml
  2. 10 3
      Dockerfile
  3. 53 0
      buildFirmware.sh
  4. 1167 0
      components/wifi-manager/network_manager_handlers.c
  5. 0 0
      components/wifi-manager/webapp/dist/css/index.eb4a1bb223a59c656f2c.css
  6. 二进制
      components/wifi-manager/webapp/dist/css/index.eb4a1bb223a59c656f2c.css.gz
  7. 6 0
      components/wifi-manager/webapp/dist/css/index.f2de74635f23b31fbdce.css
  8. 二进制
      components/wifi-manager/webapp/dist/css/index.f2de74635f23b31fbdce.css.gz
  9. 0 0
      components/wifi-manager/webapp/dist/index.html
  10. 二进制
      components/wifi-manager/webapp/dist/index.html.gz
  11. 0 1
      components/wifi-manager/webapp/dist/js/index.0ff7b6.bundle.js
  12. 0 50
      components/wifi-manager/webapp/dist/js/index.0ff7b6.bundle.js.LICENSE.txt
  13. 二进制
      components/wifi-manager/webapp/dist/js/index.0ff7b6.bundle.js.gz
  14. 0 0
      components/wifi-manager/webapp/dist/js/index.7581c6.bundle.js
  15. 二进制
      components/wifi-manager/webapp/dist/js/index.7581c6.bundle.js.gz
  16. 0 0
      components/wifi-manager/webapp/dist/js/node_vendors.7581c6.bundle.js
  17. 二进制
      components/wifi-manager/webapp/dist/js/node_vendors.7581c6.bundle.js.gz
  18. 2 8
      components/wifi-manager/webapp/package.json
  19. 34 34
      components/wifi-manager/webapp/src/sass/main.scss
  20. 3 2
      components/wifi-manager/webapp/webapp.cmake
  21. 15 10
      components/wifi-manager/webapp/webpack.c
  22. 36 18
      components/wifi-manager/webapp/webpack.config.js
  23. 1 1
      components/wifi-manager/webapp/webpack.h
  24. 4 0
      docker/entrypoint.sh

+ 2 - 6
.github/workflows/esp-idf-v4.3-build.yml

@@ -42,11 +42,11 @@ jobs:
       with:
         path: |
           ~/build
-          ~/components/wifi-manager/webapp/node_modules
         key: ${{ runner.os }}-${{ matrix.node }}
     - name: Set build parameters
       run: |
         git update-index --chmod=+x ./server_certs/getcert.sh
+        git update-index --chmod=+x ./buildFirmware.sh
         git update-index --chmod=+x ./components/spotify/cspot/bell/nanopb/generator/protoc
         git update-index --chmod=+x ./components/spotify/cspot/bell/nanopb/generator/protoc-gen-nanopb
         git update-index --chmod=+x ./components/spotify/cspot/bell/nanopb/generator/*.py
@@ -91,13 +91,9 @@ jobs:
     - name: Build the firmware
       run: |
         env | grep "artifact\|tag\|GITHUB\|version\|NUMBER\|TARGET" >${TARGET_BUILD_NAME}-env.txt
-        echo "${tag}" >version.txt
         echo pulling custom docker image  ${DOCKER_IMAGE_NAME}
         docker pull ${DOCKER_IMAGE_NAME}
-        docker run --env-file=${TARGET_BUILD_NAME}-env.txt  -v $PWD:/project -w /project ${DOCKER_IMAGE_NAME} /bin/bash -c "pushd components/wifi-manager/webapp/ && npm install && npm run-script build && popd"
-        docker run --env-file=${TARGET_BUILD_NAME}-env.txt  -v $PWD:/project -w /project ${DOCKER_IMAGE_NAME} /bin/bash -c "cp build-scripts/${TARGET_BUILD_NAME}-sdkconfig.defaults sdkconfig"
-        docker run --env-file=${TARGET_BUILD_NAME}-env.txt  -v $PWD:/project -w /project ${DOCKER_IMAGE_NAME} /bin/bash -c "idf.py build -DDEPTH=${{ matrix.depth }} -DBUILD_NUMBER=${BUILD_NUMBER}-${{ matrix.depth }} "
-        docker run --env-file=${TARGET_BUILD_NAME}-env.txt  -v $PWD:/project -w /project ${DOCKER_IMAGE_NAME} /bin/bash -c "zip -r build_output.zip build && zip build/${artifact_file_name} partitions*.csv build/*.bin build/bootloader/bootloader.bin build/partition_table/partition-table.bin build/flash_project_args build/size_*.txt"
+        docker run --env-file=${TARGET_BUILD_NAME}-env.txt  -v $PWD:/project -w /project ${DOCKER_IMAGE_NAME} /bin/bash -c "./buildFirmware.sh"
     # - name: Build Mock firmware
     #   run: |
     #     mkdir -p build

+ 10 - 3
Dockerfile

@@ -2,7 +2,7 @@ FROM ubuntu:20.04
 
 
 ARG DEBIAN_FRONTEND=noninteractive
-
+ENV GCC_TOOLS_BASE=/opt/esp/tools/xtensa-esp32-elf/esp-2021r2-8.4.0/xtensa-esp32-elf/bin/xtensa-esp32-elf-
 # We need libpython2.7 due to GDB tools
 # we also need npm 8 for the webapp to work
 RUN : \
@@ -38,6 +38,10 @@ RUN : \
   && python -m pip install --upgrade \
     pip \
     virtualenv \
+  && cd /opt \  
+  && git clone https://github.com/HBehrens/puncover.git \
+  && cd puncover \
+  && python setup.py -q install \
   && :
 
 # To build the image for a branch or a tag of IDF, pass --build-arg IDF_CLONE_BRANCH_OR_TAG=name.
@@ -47,11 +51,13 @@ RUN : \
 #   IDF_CHECKOUT_REF=<some commit on release/vX.Y branch>.
 # The following commit contains the ldgen fix: eab738c79e063b3d6f4c345ea5e1d4f8caef725b
 # to build an image using that commit: docker build . --build-arg IDF_CHECKOUT_REF=eab738c79e063b3d6f4c345ea5e1d4f8caef725b -t sle118/squeezelite-esp32-idfv4-master
-# docker build . --build-arg IDF_CHECKOUT_REF=8bf14a9238329954c7c5062eeeda569529aedf75  -t sle118/squeezelite-esp32-idfv4-master
+# docker build . --build-arg IDF_CHECKOUT_REF=8bf14a92python setup.py -q install38329954c7c5062eeeda569529aedf75  -t sle118/squeezelite-esp32-idfv4-master
 # To run the image interactive (windows): docker run --rm -v %cd%:/project -w /project -it sle118/squeezelite-esp32-idfv4-master
 # to build the web app inside of the interactive session
 # pushd components/wifi-manager/webapp/ && npm install && npm run-script build && popd
-
+#
+# to run the docker with netwotrk port published on the host:
+# docker run --rm -p 5000:5000/tcp -v %cd%:/project -w /project -it sle118/squeezelite-esp32-idfv4-master
 
 ARG IDF_CLONE_URL=https://github.com/espressif/esp-idf.git
 ARG IDF_CLONE_BRANCH_OR_TAG=master
@@ -60,6 +66,7 @@ ARG IDF_CHECKOUT_REF=eab738c79e063b3d6f4c345ea5e1d4f8caef725b
 ENV IDF_PATH=/opt/esp/idf
 ENV IDF_TOOLS_PATH=/opt/esp
 
+
 RUN echo IDF_CHECKOUT_REF=$IDF_CHECKOUT_REF IDF_CLONE_BRANCH_OR_TAG=$IDF_CLONE_BRANCH_OR_TAG && \
     git clone --recursive \
       ${IDF_CLONE_BRANCH_OR_TAG:+-b $IDF_CLONE_BRANCH_OR_TAG} \

+ 53 - 0
buildFirmware.sh

@@ -0,0 +1,53 @@
+#!/bin/bash
+
+
+
+echo "Build process started"
+pushd components/wifi-manager/webapp/ 
+echo "Installing node.js dependencies"
+npm install 
+echo "Building webapp"
+npm run-script build 
+popd
+echo "Setting up build name and build number"
+if [ -z "${TARGET_BUILD_NAME}" ]
+then
+    export TARGET_BUILD_NAME="I2S-4MFlash"
+    echo "TARGET_BUILD_NAME is not set. Defaulting to ${TARGET_BUILD_NAME}"
+fi
+if [ -z "${BUILD_NUMBER}" ]
+then
+    export BUILD_NUMBER="500"
+    echo "BUILD_NUMBER is not set. Defaulting to ${BUILD_NUMBER}"
+fi
+if [ -z "$DEPTH" ]
+then
+    export DEPTH="16"
+    echo "DEPTH is not set. Defaulting to ${DEPTH}"
+fi
+if [ -z "$tag" ]
+then
+    branch_name="$(git rev-parse --abbrev-ref HEAD)"
+    branch_name="${branch_name//[^a-zA-Z0-9\-~!@_\.]/}"
+    app_name="${TARGET_BUILD_NAME}.${DEPTH}.dev-$(git log --pretty=format:'%h' --max-count=1).${branch_name}" 
+    echo "${app_name}">version.txt
+    echo "app_name is not set. Defaulting to ${app_name}"
+else
+    echo "${tag}" >version.txt
+fi
+
+echo "Copying target sdkconfig"
+cp build-scripts/${TARGET_BUILD_NAME}-sdkconfig.defaults sdkconfig
+echo "Building project"
+idf.py build -DDEPTH=${DEPTH} -DBUILD_NUMBER=${BUILD_NUMBER}-${DEPTH} 
+echo "Generating size report"
+idf.py size-components >build/size_components.txt
+idf.py size-components-squeezelite build/size_components_squeezelite.txt
+if [ -z "${artifact_file_name}" ]
+then
+    echo "No artifact file name set.  Will not generate zip file."
+else
+    echo "Generating build artifact zip file"
+    zip -r build_output.zip build
+    zip build/${artifact_file_name} partitions*.csv build/*.bin build/bootloader/bootloader.bin build/partition_table/partition-table.bin build/flash_project_args build/size_*.txt
+fi

+ 1167 - 0
components/wifi-manager/network_manager_handlers.c

@@ -0,0 +1,1167 @@
+#ifdef NETWORK_HANDLERS_LOG_LEVEL
+#define LOG_LOCAL_LEVEL NETWORK_HANDLERS_LOG_LEVEL
+#endif
+#include "network_manager.h"
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "network_ethernet.h"
+#include "network_status.h"
+#include "network_wifi.h"
+
+#include "dns_server.h"
+#include "esp_log.h"
+#include "esp_system.h"
+#include "freertos/FreeRTOS.h"
+#include "platform_esp32.h"
+
+#include "esp_netif.h"
+#include "freertos/task.h"
+
+#include "cJSON.h"
+#include "cmd_system.h"
+#include "esp_app_format.h"
+
+#include "esp_event.h"
+#include "esp_ota_ops.h"
+#include "esp_wifi.h"
+#include "esp_wifi_types.h"
+#include "lwip/api.h"
+#include "lwip/err.h"
+#include "lwip/ip4_addr.h"
+#include "lwip/netdb.h"
+#include "mdns.h"
+#include "messaging.h"
+
+#include "platform_config.h"
+#include "trace.h"
+
+#include "accessors.h"
+#include "esp_err.h"
+#include "tools.h"
+#include "http_server_handlers.h"
+#include "network_manager.h"
+
+static const char TAG[]="network_handlers";
+
+EXT_RAM_ATTR static state_t network_states[TOTAL_NM_STATE];
+EXT_RAM_ATTR static state_t Wifi_Active_State[TOTAL_WIFI_ACTIVE_STATE];
+EXT_RAM_ATTR static state_t Eth_Active_State[TOTAL_ETH_ACTIVE_STATE];
+EXT_RAM_ATTR static state_t Wifi_Configuring_State[TOTAL_WIFI_CONFIGURING_STATE];
+
+static void network_interface_coexistence(state_machine_t* state_machine);
+static state_machine_result_t local_traverse_state(state_machine_t* const state_machine,
+                                                   const state_t* const target_state, const char * caller) ;
+static state_machine_result_t local_switch_state(state_machine_t* state_machine,
+                                                 const state_t* const target_state, const char * caller);
+void network_execute_cb(state_machine_t* const state_machine, const char * caller);
+int get_root_id(const state_t *  state);
+const state_t* get_root( const state_t* const state);
+
+#define ADD_ROOT(name,...) ADD_ROOT_FORWARD_DECLARATION(name,...)
+#define ADD_ROOT_LEAF(name,...) ADD_ROOT_LEAF_FORWARD_DECLARATION(name,...)
+#define ADD_LEAF(name,...) ADD_LEAF_FORWARD_DECLARATION(name,...)
+ALL_NM_STATE
+ALL_ETH_STATE(, )
+ALL_WIFI_STATE(, )
+ALL_WIFI_CONFIGURING_STATE(, )
+#undef ADD_ROOT
+#undef ADD_ROOT_LEAF
+#undef ADD_LEAF
+
+/*
+ *  --------------------- Global variables ---------------------
+ */
+#define ADD_ROOT(NAME, CHILD) ADD_ROOT_(NAME, CHILD)
+#define ADD_LEAF(NAME, PARENT, LEVEL) ADD_LEAF_(NAME, PARENT, LEVEL)
+#define ADD_ROOT_LEAF(NAME) ADD_ROOT_LEAF_(NAME)
+
+#define ADD_ROOT_(NAME, CHILD)         \
+    [NAME] = {                         \
+        .Handler = NAME##_handler,     \
+        .Entry = NAME##_entry_handler, \
+        .Exit = NAME##_exit_handler,   \
+        .Level = 0,                    \
+        .Parent = NULL,                \
+        .Id = NAME,                    \
+        .Node = CHILD,                 \
+    },
+
+#define ADD_ROOT_LEAF_(NAME)           \
+    [NAME] = {                         \
+        .Handler = NAME##_handler,     \
+        .Entry = NAME##_entry_handler, \
+        .Exit = NAME##_exit_handler,   \
+        .Id = NAME,                    \
+        .Parent = NULL,              \
+    },
+
+#define ADD_LEAF_(NAME, PARENT, LEVEL) \
+    [NAME] = {                         \
+        .Handler = NAME##_handler,     \
+        .Entry = NAME##_entry_handler, \
+        .Exit = NAME##_exit_handler,   \
+        .Id = NAME,                    \
+        .Level = LEVEL,                \
+        .Parent = PARENT,              \
+    },
+
+static void network_initialize_state_machine_globals(){
+    static state_t loc_network_states[] =
+        {
+            ALL_NM_STATE};
+
+    static state_t loc_Wifi_Active_State[] = {
+        ALL_WIFI_STATE(&network_states[NETWORK_WIFI_ACTIVE_STATE], 1)
+    };
+    static state_t loc_Eth_Active_State[]={
+        ALL_ETH_STATE(&network_states[NETWORK_ETH_ACTIVE_STATE], 1)
+
+    };
+    static state_t loc_Wifi_Configuring_State[]={
+        ALL_WIFI_CONFIGURING_STATE(&network_states[NETWORK_WIFI_CONFIGURING_ACTIVE_STATE], 1)
+    };
+    memcpy(&network_states,&loc_network_states,sizeof(network_states));
+    memcpy(&Eth_Active_State,&loc_Eth_Active_State,sizeof(Eth_Active_State));
+    memcpy(&Wifi_Active_State,&loc_Wifi_Active_State,sizeof(Wifi_Active_State));
+    memcpy(&Wifi_Configuring_State,&loc_Wifi_Configuring_State,sizeof(Wifi_Configuring_State));
+}
+#undef ADD_ROOT
+#undef ADD_ROOT_LEAF
+#undef ADD_LEAF
+
+#define HANDLE_GLOBAL_EVENT(m)                   \
+    if (handle_global_event(m) == EVENT_HANDLED) \
+        return EVENT_HANDLED;
+
+static void network_connect_active_ssid(state_machine_t* const State_Machine) {
+    network_t* const nm = (network_t*)State_Machine;
+    if (network_wifi_connect_active_ssid() != ESP_OK) {
+        ESP_LOGE(TAG, "Oups.  Something went wrong!");
+        nm->wifi_connected = false;
+        ESP_LOGD(TAG, "Checking if ethernet interface is connected");
+        if (network_is_interface_connected(nm->eth_netif)) {
+            ESP_LOGD(TAG, "Ethernet connection is found.  Try to fallback there");
+            network_async(EN_ETHERNET_FALLBACK);
+        } else {
+            // returning to AP mode
+            nm->STA_duration = nm->sta_polling_min_ms;
+            ESP_LOGD(TAG, "No ethernet and no wifi configured. Go to configuration mode");
+            network_async_configure();
+        }
+    }
+}
+
+void initialize_network_handlers(state_machine_t* state_machine){
+    MEMTRACE_PRINT_DELTA();
+    network_initialize_state_machine_globals();
+    MEMTRACE_PRINT_DELTA();
+    NETWORK_INSTANTIATED_STATE_handler(state_machine);
+    MEMTRACE_PRINT_DELTA();
+}
+static state_machine_result_t handle_global_event(state_machine_t* state_machine) {
+    network_t * net_sm= ((network_t *)state_machine);
+    switch (net_sm->Machine.Event) {
+        case EN_UPDATE_STATUS:
+            // handle the event, but don't swicth
+            MEMTRACE_PRINT_DELTA_MESSAGE("handle EN_UPDATE_STATUS - start");
+            network_status_update_basic_info();
+            MEMTRACE_PRINT_DELTA_MESSAGE("handle EN_UPDATE_STATUS - end");
+            return EVENT_HANDLED;
+            /* code */
+            break;
+        case EN_REBOOT:
+            ESP_LOGD(TAG,"Called for reboot type %d",net_sm->event_parameters->rtype);
+            switch (net_sm->event_parameters->rtype) {
+                case OTA:
+                    ESP_LOGD(TAG, " Calling guided_restart_ota.");
+                    guided_restart_ota();
+                    break;
+                case RECOVERY:
+                    ESP_LOGD(TAG, " Calling guided_factory.");
+                    guided_factory();
+                    break;
+                case RESTART:
+                    ESP_LOGD(TAG, " Calling simple_restart.");
+                    simple_restart();
+                    break;
+
+                default:
+                    break;
+            }
+            return EVENT_UN_HANDLED;
+            break;
+        case EN_REBOOT_URL:
+            if (net_sm->event_parameters->strval) {
+                start_ota(net_sm->event_parameters->strval, NULL, 0);
+                FREE_AND_NULL(net_sm->event_parameters->strval);
+            }
+            return EVENT_UN_HANDLED;
+            break;
+
+        default:
+            break;
+    }
+    return EVENT_UN_HANDLED;
+}
+
+
+
+
+/********************************************************************************************* 
+ * INSTANTIATED_STATE
+ */
+static state_machine_result_t NETWORK_INSTANTIATED_STATE_entry_handler(state_machine_t* const State_Machine) {
+    network_handler_entry_print(State_Machine,true);
+    NETWORK_EXECUTE_CB(State_Machine);
+    network_handler_entry_print(State_Machine,false);
+    return EVENT_HANDLED;
+}
+static state_machine_result_t NETWORK_INSTANTIATED_STATE_handler(state_machine_t* const State_Machine) {
+    network_handler_print(State_Machine,true);
+    state_machine_result_t result = EVENT_UN_HANDLED;
+    network_t* const nm = (network_t *)State_Machine;
+    State_Machine->State = &network_states[NETWORK_INSTANTIATED_STATE];
+    State_Machine->Event = EN_START;
+    config_get_uint16t_from_str("pollmx",&nm->sta_polling_max_ms,600);
+    nm->sta_polling_max_ms = nm->sta_polling_max_ms * 1000;
+    config_get_uint16t_from_str("apdelay",&nm->ap_duration_ms,20);
+    nm->ap_duration_ms = nm->ap_duration_ms * 1000;
+    config_get_uint16t_from_str("pollmin",&nm->sta_polling_min_ms,15);
+    nm->sta_polling_min_ms = nm->sta_polling_min_ms*1000;
+    config_get_uint16t_from_str("ethtmout",&nm->eth_link_down_reboot_ms,30);
+    nm->eth_link_down_reboot_ms = nm->eth_link_down_reboot_ms*1000;
+    config_get_uint16t_from_str("dhcp_tmout",&nm->dhcp_timeout,30);
+    nm->dhcp_timeout = nm->dhcp_timeout*1000;
+    ESP_LOGI(TAG,"Network manager configuration: polling max %d, polling min %d, ap delay %d, dhcp timeout %d, eth timeout %d",
+        nm->sta_polling_max_ms,nm->sta_polling_min_ms,nm->ap_duration_ms,nm->dhcp_timeout, nm->eth_link_down_reboot_ms);
+    HANDLE_GLOBAL_EVENT(State_Machine);
+    if (State_Machine->Event == EN_START) {
+        result= local_traverse_state(State_Machine, &network_states[NETWORK_INITIALIZING_STATE],__FUNCTION__);
+    }
+    network_handler_print(State_Machine,false);
+    return result;
+}
+static state_machine_result_t NETWORK_INSTANTIATED_STATE_exit_handler(state_machine_t* const State_Machine) {
+    network_exit_handler_print(State_Machine,true);
+    network_exit_handler_print(State_Machine,false);
+    return EVENT_HANDLED;
+}
+
+/********************************************************************************************* 
+ * INITIALIZING_STATE
+ */
+static state_machine_result_t NETWORK_INITIALIZING_STATE_entry_handler(state_machine_t* const State_Machine) {
+    network_handler_entry_print(State_Machine,true);    
+    
+    MEMTRACE_PRINT_DELTA_MESSAGE(" Initializing tcp_ip adapter");
+    esp_netif_init();
+    MEMTRACE_PRINT_DELTA_MESSAGE(" Creating the default event loop");
+    ESP_ERROR_CHECK(esp_event_loop_create_default());
+    MEMTRACE_PRINT_DELTA_MESSAGE("Initializing network status");
+    init_network_status();
+    MEMTRACE_PRINT_DELTA_MESSAGE("Loading wifi global configuration");
+    network_wifi_global_init();
+    MEMTRACE_PRINT_DELTA_MESSAGE(" Registering event handler");
+    esp_event_handler_register(IP_EVENT, ESP_EVENT_ANY_ID, &network_ip_event_handler, NULL);
+    MEMTRACE_PRINT_DELTA_MESSAGE(" Initializing network done. Starting http server");
+    // send a message to start the connections
+    http_server_start(); 
+    MEMTRACE_PRINT_DELTA_MESSAGE("Executing Callback");
+    NETWORK_EXECUTE_CB(State_Machine);
+    network_handler_entry_print(State_Machine,false);
+    return EVENT_HANDLED;
+}
+
+static state_machine_result_t NETWORK_INITIALIZING_STATE_handler(state_machine_t* const State_Machine) {
+     
+    network_handler_print(State_Machine,true);
+    state_machine_result_t result = EVENT_UN_HANDLED;
+    HANDLE_GLOBAL_EVENT(State_Machine);
+    switch (State_Machine->Event) {
+        case EN_START:
+        if (network_is_wifi_prioritized()) {
+                ESP_LOGI(TAG, "WiFi connection is prioritized. Starting WiFi");
+                result= local_traverse_state(State_Machine, &Wifi_Active_State[WIFI_INITIALIZING_STATE],__FUNCTION__);
+            }
+            else if(is_recovery_running){
+                ESP_LOGI(TAG, "Running recovery. Skipping ethernet, starting WiFi");
+                result= local_traverse_state(State_Machine, &Wifi_Active_State[WIFI_INITIALIZING_STATE],__FUNCTION__);
+            }
+            else {
+                result= local_traverse_state(State_Machine, &Eth_Active_State[ETH_STARTING_STATE],__FUNCTION__);
+            }
+            break;
+        default:
+            result= EVENT_UN_HANDLED;
+    }
+    network_handler_print(State_Machine,false);
+    return result;
+}
+static state_machine_result_t NETWORK_INITIALIZING_STATE_exit_handler(state_machine_t* const State_Machine) {
+    network_exit_handler_print(State_Machine,true);
+    network_exit_handler_print(State_Machine,false);
+    return EVENT_HANDLED;
+}
+
+/********************************************************************************************* 
+ * ETH_STARTING_STATE
+ */
+static state_machine_result_t ETH_STARTING_STATE_entry_handler(state_machine_t* const State_Machine) {
+    network_handler_entry_print(State_Machine,true);
+    ESP_LOGD(TAG, "Looking for ethernet Interface");
+    network_t* const nm = (network_t *)State_Machine;
+    init_network_ethernet();
+    if (!network_ethernet_enabled()) {
+        network_async_fail();
+    } else {
+        nm->eth_netif = network_ethernet_get_interface();
+    }
+    NETWORK_EXECUTE_CB(State_Machine);
+    network_handler_entry_print(State_Machine,false);
+    return EVENT_HANDLED;
+}
+
+static state_machine_result_t ETH_STARTING_STATE_handler(state_machine_t* const State_Machine) {
+    state_machine_result_t result = EVENT_HANDLED;
+    network_handler_print(State_Machine,true);
+    HANDLE_GLOBAL_EVENT(State_Machine);
+    switch (State_Machine->Event) {
+        case EN_FAIL:
+            result= local_traverse_state(State_Machine, &Wifi_Active_State[WIFI_INITIALIZING_STATE],__FUNCTION__);
+            break;
+        case EN_SUCCESS:
+            result= local_traverse_state(State_Machine, &network_states[NETWORK_ETH_ACTIVE_STATE],__FUNCTION__);
+            break;
+        default:
+            ESP_LOGE(TAG, "No handler");
+            result= EVENT_UN_HANDLED;
+    }
+    network_handler_print(State_Machine,false);
+    return result;
+}
+static state_machine_result_t ETH_STARTING_STATE_exit_handler(state_machine_t* const State_Machine) {
+    network_exit_handler_print(State_Machine,true);
+    network_exit_handler_print(State_Machine,false);
+    return EVENT_HANDLED;
+}
+
+/********************************************************************************************* 
+ * NETWORK_ETH_ACTIVE_STATE
+ */
+static state_machine_result_t NETWORK_ETH_ACTIVE_STATE_entry_handler(state_machine_t* const State_Machine) {
+    network_handler_entry_print(State_Machine,true);
+    network_t* const nm = (network_t *)State_Machine;
+    network_set_timer(nm->eth_link_down_reboot_ms,"Ethernet link not detected" );
+    NETWORK_EXECUTE_CB(State_Machine);
+    network_handler_entry_print(State_Machine,false);
+    return EVENT_HANDLED;
+}
+static state_machine_result_t NETWORK_ETH_ACTIVE_STATE_handler(state_machine_t* const State_Machine) {
+    network_handler_print(State_Machine,true);
+    state_machine_result_t result = EVENT_UN_HANDLED;
+    network_t* const nm = (network_t *)State_Machine;
+    switch (State_Machine->Event) {
+        case EN_CONNECT_NEW:
+            result= local_traverse_state(State_Machine, &Eth_Active_State[ETH_CONNECTING_NEW_STATE],__FUNCTION__);
+            break;
+        case EN_LINK_UP:
+            result= local_traverse_state(State_Machine, &Eth_Active_State[ETH_ACTIVE_LINKUP_STATE],__FUNCTION__);
+            break;
+        case EN_LINK_DOWN:
+            result= local_traverse_state(State_Machine, &Eth_Active_State[ETH_ACTIVE_LINKDOWN_STATE],__FUNCTION__);
+            break;
+        case EN_ETH_GOT_IP:
+            result= local_traverse_state(State_Machine, &Eth_Active_State[ETH_ACTIVE_CONNECTED_STATE],__FUNCTION__);
+            break;
+        case EN_ETHERNET_FALLBACK:
+            result= local_traverse_state(State_Machine, &Eth_Active_State[ETH_ACTIVE_CONNECTED_STATE],__FUNCTION__);
+            break;
+        case EN_TIMER:
+            ESP_LOGW(TAG, "Timeout %s. Rebooting to wifi",STR_OR_ALT(nm->timer_tag,"Ethernet link not detected"));
+            network_prioritize_wifi(true);
+            simple_restart();
+            //result= local_traverse_state(State_Machine, &Wifi_Active_State[WIFI_INITIALIZING_STATE],__FUNCTION__);
+            break;
+        case EN_SCAN:
+            ESP_LOGW(TAG,"Wifi  scan cannot be executed in this state");
+            network_wifi_built_known_ap_list();
+            result = EVENT_HANDLED;
+            break;
+        case EN_DELETE: {
+            ESP_LOGD(TAG, "WiFi disconnected by user");
+            network_wifi_clear_config();
+            network_status_update_ip_info(UPDATE_USER_DISCONNECT);
+            result= EVENT_HANDLED;
+        } break;
+        default:
+            HANDLE_GLOBAL_EVENT(State_Machine);
+            result=EVENT_UN_HANDLED;
+    }
+    network_handler_print(State_Machine,false);
+    return result;
+}
+static state_machine_result_t NETWORK_ETH_ACTIVE_STATE_exit_handler(state_machine_t* const State_Machine) {
+    network_exit_handler_print(State_Machine,true);
+    network_set_timer(0,NULL);
+    network_exit_handler_print(State_Machine,false);
+    return EVENT_HANDLED;
+}
+
+
+
+/********************************************************************************************* 
+ * ETH_CONNECTING_NEW_STATE
+ */
+static state_machine_result_t ETH_CONNECTING_NEW_STATE_entry_handler(state_machine_t* const State_Machine) {
+    network_t* const nm = (network_t *)State_Machine;
+    network_handler_entry_print(State_Machine,true);
+    network_start_stop_dhcp_client(nm->wifi_netif, true);
+    network_wifi_connect(nm->event_parameters->ssid,nm->event_parameters->password);
+    FREE_AND_NULL(nm->event_parameters->ssid);
+    FREE_AND_NULL(nm->event_parameters->password);
+    NETWORK_EXECUTE_CB(State_Machine);
+    network_handler_entry_print(State_Machine,false);
+    return EVENT_HANDLED;
+}
+static state_machine_result_t ETH_CONNECTING_NEW_STATE_handler(state_machine_t* const State_Machine) {
+    HANDLE_GLOBAL_EVENT(State_Machine);
+    network_handler_print(State_Machine,true);
+    state_machine_result_t result = EVENT_HANDLED;
+    switch (State_Machine->Event) {
+        case EN_GOT_IP:
+            result= local_traverse_state(State_Machine, &network_states[WIFI_CONNECTED_STATE],__FUNCTION__);
+            break;
+        case EN_LOST_CONNECTION:
+            network_status_update_ip_info(UPDATE_FAILED_ATTEMPT);
+            messaging_post_message(MESSAGING_ERROR, MESSAGING_CLASS_SYSTEM, "Unable to connect to new WiFi access point.");
+            // no existing configuration, or wifi wasn't the active connection when connection
+            // attempt was made
+            network_async(EN_ETHERNET_FALLBACK);
+            result = EVENT_HANDLED;
+            break;
+
+        default:
+            result= EVENT_UN_HANDLED;
+    }
+    network_handler_print(State_Machine,false);
+    return result;
+}
+static state_machine_result_t ETH_CONNECTING_NEW_STATE_exit_handler(state_machine_t* const State_Machine) {
+    network_exit_handler_print(State_Machine,true);
+    network_set_timer(0,NULL);
+    network_exit_handler_print(State_Machine,false);
+    return EVENT_HANDLED;
+}
+
+/********************************************************************************************* 
+ * ETH_ACTIVE_LINKDOWN
+ */
+static state_machine_result_t ETH_ACTIVE_LINKDOWN_STATE_entry_handler(state_machine_t* const State_Machine) {
+    network_handler_entry_print(State_Machine,true);
+    network_t* const nm = (network_t *)State_Machine;
+    network_set_timer(nm->eth_link_down_reboot_ms, "Ethernet link down" );
+    NETWORK_EXECUTE_CB(State_Machine);
+    messaging_post_message(MESSAGING_WARNING, MESSAGING_CLASS_SYSTEM, "Ethernet link down.");
+    network_handler_entry_print(State_Machine,false);
+    return EVENT_HANDLED;
+}
+static state_machine_result_t ETH_ACTIVE_LINKDOWN_STATE_handler(state_machine_t* const State_Machine) {
+    network_handler_print(State_Machine,true);
+    HANDLE_GLOBAL_EVENT(State_Machine);
+    network_handler_print(State_Machine,false);
+    return EVENT_UN_HANDLED;
+}
+static state_machine_result_t ETH_ACTIVE_LINKDOWN_STATE_exit_handler(state_machine_t* const State_Machine) {
+    network_exit_handler_print(State_Machine,true);
+    network_set_timer(0,NULL);
+    network_exit_handler_print(State_Machine,false);
+    
+    return EVENT_HANDLED;
+}
+
+/********************************************************************************************* 
+ * ETH_ACTIVE_LINKUP_STATE
+ */
+static state_machine_result_t ETH_ACTIVE_LINKUP_STATE_entry_handler(state_machine_t* const State_Machine) {
+    network_handler_entry_print(State_Machine,true);
+    network_t* const nm = (network_t *)State_Machine;
+    network_set_timer(nm->dhcp_timeout, "DHCP timeout" );
+    NETWORK_EXECUTE_CB(State_Machine);
+    messaging_post_message(MESSAGING_INFO, MESSAGING_CLASS_SYSTEM, "Ethernet link up.");
+    network_handler_entry_print(State_Machine,false);
+    return EVENT_HANDLED;
+}
+static state_machine_result_t ETH_ACTIVE_LINKUP_STATE_handler(state_machine_t* const State_Machine) {
+    state_machine_result_t result = EVENT_UN_HANDLED;
+    network_handler_print(State_Machine,true);
+    HANDLE_GLOBAL_EVENT(State_Machine);
+    network_handler_print(State_Machine,false);
+    return result;
+}
+static state_machine_result_t ETH_ACTIVE_LINKUP_STATE_exit_handler(state_machine_t* const State_Machine) {
+    network_exit_handler_print(State_Machine,true);
+    network_exit_handler_print(State_Machine,false);
+    return EVENT_HANDLED;
+}
+
+/********************************************************************************************* 
+ * WIFI_UP_STATE
+ */
+static state_machine_result_t NETWORK_WIFI_ACTIVE_STATE_entry_handler(state_machine_t* const State_Machine) {
+    network_handler_entry_print(State_Machine,true);
+    NETWORK_EXECUTE_CB(State_Machine);
+    network_handler_entry_print(State_Machine,false);
+    return EVENT_HANDLED;
+}
+static state_machine_result_t NETWORK_WIFI_ACTIVE_STATE_handler(state_machine_t* const State_Machine) {
+    HANDLE_GLOBAL_EVENT(State_Machine);
+    network_handler_print(State_Machine,true);
+    state_machine_result_t result = EVENT_UN_HANDLED;
+    switch (State_Machine->Event)
+    {
+        case EN_LINK_UP:
+            ESP_LOGW(TAG, "Ethernet link up in wifi mode");
+            break;
+        case EN_ETH_GOT_IP:
+            network_interface_coexistence(State_Machine);
+            break;
+        case EN_GOT_IP:
+            network_status_update_ip_info(UPDATE_CONNECTION_OK);
+            result= local_traverse_state(State_Machine, &Wifi_Active_State[WIFI_CONNECTED_STATE],__FUNCTION__);
+            break;            
+        case EN_SCAN:
+            if (network_wifi_start_scan() == ESP_OK) {
+                result= EVENT_HANDLED;
+            }
+            break;
+        case EN_SCAN_DONE:
+            if(wifi_scan_done() == ESP_OK) {
+                result= EVENT_HANDLED;
+            }
+            break;
+        case EN_CONNECT_NEW:
+            result= local_traverse_state(State_Machine, &Wifi_Active_State[WIFI_CONNECTING_NEW_STATE],__FUNCTION__);
+            break;
+        case EN_DELETE:
+            result= local_traverse_state(State_Machine,&Wifi_Active_State[WIFI_USER_DISCONNECTED_STATE],__FUNCTION__);
+            break;
+        case EN_ETHERNET_FALLBACK:
+            result= local_traverse_state(State_Machine, &Eth_Active_State[ETH_ACTIVE_CONNECTED_STATE],__FUNCTION__);
+            break;            
+        default:
+            break;
+    }
+    network_handler_print(State_Machine,false);
+    return result;
+}
+static state_machine_result_t NETWORK_WIFI_ACTIVE_STATE_exit_handler(state_machine_t* const State_Machine) {
+    network_exit_handler_print(State_Machine,true);
+    network_exit_handler_print(State_Machine,false);
+    return EVENT_HANDLED;
+}
+
+/********************************************************************************************* 
+ * WIFI_INITIALIZING_STATE
+ */
+static state_machine_result_t WIFI_INITIALIZING_STATE_entry_handler(state_machine_t* const State_Machine) {
+    network_t* const nm = (network_t *)State_Machine;
+    network_handler_entry_print(State_Machine,true);
+    if(!nm->wifi_netif){
+        nm->wifi_netif = network_wifi_start();
+    }
+    if (!is_wifi_up()) {
+        messaging_post_message(MESSAGING_WARNING, MESSAGING_CLASS_SYSTEM, "Wifi not started. Load Configuration");
+        return EVENT_UN_HANDLED;
+    }
+    if (network_wifi_get_known_count()>0) {
+        ESP_LOGI(TAG, "Existing wifi config found. Attempting to connect.");
+        network_async_success();
+    } else {
+        /* no wifi saved: start soft AP! This is what should happen during a first run */
+        ESP_LOGW(TAG, "No saved wifi. Starting AP configuration mode.");
+        network_async_configure();
+    }
+    NETWORK_EXECUTE_CB(State_Machine);
+    network_handler_entry_print(State_Machine,false);
+    return EVENT_HANDLED;
+}
+
+static state_machine_result_t WIFI_INITIALIZING_STATE_handler(state_machine_t* const State_Machine) {
+    HANDLE_GLOBAL_EVENT(State_Machine);
+    network_handler_print(State_Machine,true);
+    state_machine_result_t result = EVENT_HANDLED;
+    switch (State_Machine->Event) {
+        case EN_CONFIGURE:
+            result= local_traverse_state(State_Machine, &Wifi_Configuring_State[WIFI_CONFIGURING_STATE],__FUNCTION__);
+            break;
+        case EN_SUCCESS:
+            result= local_switch_state(State_Machine, &Wifi_Active_State[WIFI_CONNECTING_STATE],__FUNCTION__);
+            break;
+        default:
+            result= EVENT_UN_HANDLED;
+    }
+    network_handler_print(State_Machine,false);
+    return result;
+}
+static state_machine_result_t WIFI_INITIALIZING_STATE_exit_handler(state_machine_t* const State_Machine) {
+    network_exit_handler_print(State_Machine,true);
+    network_exit_handler_print(State_Machine,false);
+    return EVENT_HANDLED;
+}
+
+
+/********************************************************************************************* 
+ * WIFI_CONFIGURING_ACTIVE_STATE
+ */
+static state_machine_result_t NETWORK_WIFI_CONFIGURING_ACTIVE_STATE_entry_handler(state_machine_t* const State_Machine) {
+    network_handler_entry_print(State_Machine,true);
+    network_t* const nm = (network_t *)State_Machine;
+    nm->wifi_ap_netif = network_wifi_config_ap();
+    dns_server_start(nm->wifi_ap_netif);
+    network_wifi_start_scan();
+    network_handler_entry_print(State_Machine,false);
+    return EVENT_HANDLED;
+}
+static state_machine_result_t NETWORK_WIFI_CONFIGURING_ACTIVE_STATE_handler(state_machine_t* const State_Machine) {
+    HANDLE_GLOBAL_EVENT(State_Machine);
+    network_handler_print(State_Machine,true);
+    state_machine_result_t result = EVENT_HANDLED;
+    switch (State_Machine->Event) {
+        case EN_SCAN:
+            if (network_wifi_start_scan() == ESP_OK) {
+                result= EVENT_HANDLED;
+            }
+            break;
+        case EN_SCAN_DONE:
+            ESP_LOGD(TAG,"Network configuration active, wifi scan completed");
+            if(wifi_scan_done() == ESP_OK) {
+                result= EVENT_HANDLED;
+            }
+            break;   
+        case EN_CONNECT_NEW:
+            result= local_traverse_state(State_Machine, &Wifi_Configuring_State[WIFI_CONFIGURING_CONNECT_STATE],__FUNCTION__);
+            break;
+        case EN_LINK_UP:
+            ESP_LOGW(TAG, "Ethernet link up in wifi mode");
+            break;
+        case EN_ETH_GOT_IP:
+            network_interface_coexistence(State_Machine);
+            break;
+        default:
+            result =EVENT_UN_HANDLED;
+    }
+    network_handler_print(State_Machine,false);
+    return result;
+}
+static state_machine_result_t NETWORK_WIFI_CONFIGURING_ACTIVE_STATE_exit_handler(state_machine_t* const State_Machine) {
+    network_exit_handler_print(State_Machine, true);
+    /* bring down DNS hijack */
+    ESP_LOGD(TAG, " Stopping DNS.");
+    dns_server_stop();    
+    ESP_LOGD(TAG, "Changing wifi mode to STA.");
+    network_wifi_set_sta_mode();
+    network_exit_handler_print(State_Machine, false);
+
+    return EVENT_HANDLED;
+}
+
+
+/********************************************************************************************* 
+ * WIFI_CONFIGURING_STATE
+ */
+static state_machine_result_t WIFI_CONFIGURING_STATE_entry_handler(state_machine_t* const State_Machine) {
+    network_handler_entry_print(State_Machine,true);
+    NETWORK_EXECUTE_CB(State_Machine);
+    network_handler_entry_print(State_Machine,false);
+    return EVENT_HANDLED;
+}
+static state_machine_result_t WIFI_CONFIGURING_STATE_handler(state_machine_t* const State_Machine) {
+    network_handler_print(State_Machine,true);
+    HANDLE_GLOBAL_EVENT(State_Machine);
+    network_handler_print(State_Machine,false);
+    return EVENT_UN_HANDLED;
+}
+static state_machine_result_t WIFI_CONFIGURING_STATE_exit_handler(state_machine_t* const State_Machine) {
+    network_exit_handler_print(State_Machine,true);
+    network_exit_handler_print(State_Machine,false);
+    return EVENT_HANDLED;
+}
+
+/********************************************************************************************* 
+ * WIFI_CONFIGURING_CONNECT_STATE
+ */
+static state_machine_result_t WIFI_CONFIGURING_CONNECT_STATE_entry_handler(state_machine_t* const State_Machine) {
+    network_t* const nm = (network_t *)State_Machine;
+    network_handler_entry_print(State_Machine,true);
+    network_start_stop_dhcp_client(nm->wifi_netif, true);
+    network_wifi_connect(nm->event_parameters->ssid,nm->event_parameters->password);
+    FREE_AND_NULL(nm->event_parameters->ssid);
+    FREE_AND_NULL(nm->event_parameters->password);
+    NETWORK_EXECUTE_CB(State_Machine);
+    network_handler_entry_print(State_Machine,false);
+    return EVENT_HANDLED;
+}
+static state_machine_result_t WIFI_CONFIGURING_CONNECT_STATE_handler(state_machine_t* const State_Machine) {
+    HANDLE_GLOBAL_EVENT(State_Machine);
+    network_handler_print(State_Machine,true);
+    network_t* const nm = (network_t *)State_Machine;
+    state_machine_result_t result = EVENT_HANDLED;
+    switch (State_Machine->Event) {
+        case EN_CONNECTED:
+            result=EVENT_HANDLED;
+            ESP_LOGI(TAG,"Wifi was connected. Waiting for IP address");
+            network_set_timer(nm->dhcp_timeout,"DHCP Timeout");
+            break;
+        case EN_GOT_IP:
+            network_status_update_ip_info(UPDATE_CONNECTION_OK); 
+            result= local_traverse_state(State_Machine, &Wifi_Configuring_State[WIFI_CONFIGURING_CONNECT_SUCCESS_STATE],__FUNCTION__);
+            break;
+        case EN_LOST_CONNECTION:
+            if(nm->event_parameters->disconnected_event->reason == WIFI_REASON_ASSOC_LEAVE) {
+                ESP_LOGI(TAG,"Wifi was disconnected from previous access point. Waiting to connect.");
+            }
+            else {
+                network_status_update_ip_info(UPDATE_FAILED_ATTEMPT);
+                result = local_traverse_state(State_Machine, &Wifi_Configuring_State[WIFI_CONFIGURING_STATE],__FUNCTION__);
+            }
+            break;
+        case EN_TIMER:
+            ESP_LOGW(TAG,"Connection timeout.  (%s)",STR_OR_ALT(nm->timer_tag, "Unknown"));
+            network_status_update_ip_info(UPDATE_FAILED_ATTEMPT);
+            result = local_traverse_state(State_Machine, &Wifi_Configuring_State[WIFI_CONFIGURING_STATE],__FUNCTION__);
+            break;
+        default:
+            result= EVENT_UN_HANDLED;
+    }
+    network_handler_print(State_Machine,false);
+    return result;
+}
+static state_machine_result_t WIFI_CONFIGURING_CONNECT_STATE_exit_handler(state_machine_t* const State_Machine) {
+    network_exit_handler_print(State_Machine,true);
+
+    FREE_AND_NULL(((network_t *)State_Machine)->event_parameters->disconnected_event);
+    network_set_timer(0,NULL);
+    network_exit_handler_print(State_Machine,false);
+    return EVENT_HANDLED;
+}
+
+/********************************************************************************************* 
+ * WIFI_CONFIGURING_CONNECT_SUCCESS_STATE
+ */
+static state_machine_result_t WIFI_CONFIGURING_CONNECT_SUCCESS_STATE_entry_handler(state_machine_t* const State_Machine) {
+    network_handler_entry_print(State_Machine,true);
+    network_status_update_ip_info(UPDATE_CONNECTION_OK);
+    ESP_LOGD(TAG, "Saving wifi configuration.");
+    network_wifi_save_sta_config();
+    NETWORK_EXECUTE_CB(State_Machine);
+    network_handler_entry_print(State_Machine,false);
+    return EVENT_HANDLED;
+}
+static state_machine_result_t WIFI_CONFIGURING_CONNECT_SUCCESS_STATE_handler(state_machine_t* const State_Machine) {
+    network_handler_print(State_Machine,true);
+    state_machine_result_t result = EVENT_HANDLED;
+    network_t* const nm = (network_t *)State_Machine;
+    switch (State_Machine->Event) {
+         case EN_UPDATE_STATUS:
+            network_status_update_basic_info();
+            network_set_timer(nm->ap_duration_ms,"Access point teardown"); // set a timer to tear down the AP mode
+            break;
+        case EN_TIMER:
+            network_status_update_basic_info();
+            result= local_traverse_state(State_Machine, &Wifi_Active_State[WIFI_CONNECTED_STATE],__FUNCTION__);
+            break;
+        default:
+            result= EVENT_UN_HANDLED;
+    }
+    // Process global handler at the end, since we want to overwrite
+    // UPDATE_STATUS with our own logic above
+    HANDLE_GLOBAL_EVENT(State_Machine);
+    network_handler_print(State_Machine,false);
+    return result;
+}
+static state_machine_result_t WIFI_CONFIGURING_CONNECT_SUCCESS_STATE_exit_handler(state_machine_t* const State_Machine) {
+    network_exit_handler_print(State_Machine,true);
+    network_set_timer(0,NULL);
+    network_exit_handler_print(State_Machine,false);
+    return EVENT_HANDLED;
+}
+
+
+
+
+/********************************************************************************************* 
+ * WIFI_CONNECTING_STATE
+ */
+static state_machine_result_t WIFI_CONNECTING_STATE_entry_handler(state_machine_t* const State_Machine) {
+    network_t* const nm = (network_t *)State_Machine;
+    network_handler_entry_print(State_Machine,true);
+    network_start_stop_dhcp_client(nm->wifi_netif, true);
+    network_connect_active_ssid(State_Machine);
+    nm->STA_duration = nm->sta_polling_min_ms;
+    /* create timer for background STA connection */
+    network_set_timer(nm->STA_duration,"Wifi Polling timeout");    
+    NETWORK_EXECUTE_CB(State_Machine);
+    network_handler_entry_print(State_Machine,false);
+    return EVENT_HANDLED;
+}
+static state_machine_result_t WIFI_CONNECTING_STATE_handler(state_machine_t* const State_Machine) {
+    HANDLE_GLOBAL_EVENT(State_Machine);
+    state_machine_result_t result = EVENT_HANDLED;
+    network_t* const nm = (network_t *)State_Machine;
+    network_handler_print(State_Machine,true);
+    switch (State_Machine->Event) {
+        case EN_CONNECTED:
+            // nothing to do here. Let's wait for IP address 
+            break;
+        case EN_TIMER:
+            // try connecting again.
+            // todo: implement multi-ap logic
+            ESP_LOGI(TAG, "Timer: %s ",STR_OR_ALT(nm->timer_tag,"Ethernet link not detected"));
+            network_connect_active_ssid(State_Machine);
+            break;
+        default:
+            result = EVENT_UN_HANDLED;
+    }
+    network_handler_print(State_Machine,false);
+    return result;
+}
+static state_machine_result_t WIFI_CONNECTING_STATE_exit_handler(state_machine_t* const State_Machine) {
+    network_exit_handler_print(State_Machine,true);
+    network_exit_handler_print(State_Machine,false);
+    return EVENT_HANDLED;
+}
+
+/********************************************************************************************* 
+ * WIFI_CONNECTING_NEW_STATE
+ */
+static state_machine_result_t WIFI_CONNECTING_NEW_STATE_entry_handler(state_machine_t* const State_Machine) {
+    network_t* const nm = (network_t *)State_Machine;
+    network_handler_entry_print(State_Machine,true);
+    network_start_stop_dhcp_client(nm->wifi_netif, true);
+    network_wifi_connect(nm->event_parameters->ssid,nm->event_parameters->password);
+    FREE_AND_NULL(nm->event_parameters->ssid);
+    FREE_AND_NULL(nm->event_parameters->password);
+    NETWORK_EXECUTE_CB(State_Machine);
+    network_handler_entry_print(State_Machine,false);
+    return EVENT_HANDLED;
+}
+static state_machine_result_t WIFI_CONNECTING_NEW_STATE_handler(state_machine_t* const State_Machine) {
+    HANDLE_GLOBAL_EVENT(State_Machine);
+    network_handler_print(State_Machine,true);
+    state_machine_result_t result = EVENT_HANDLED;
+    switch (State_Machine->Event) {
+        case EN_GOT_IP:
+            network_status_update_ip_info(UPDATE_CONNECTION_OK); 
+            result= local_traverse_state(State_Machine, &Wifi_Active_State[WIFI_CONNECTED_STATE],__FUNCTION__);
+            break;
+        case EN_CONNECTED:
+            ESP_LOGD(TAG,"Successfully connected to the new access point. Waiting for IP Address");
+            result = EVENT_HANDLED;
+            break;
+        case EN_LOST_CONNECTION:
+            if(((network_t *)State_Machine)->event_parameters->disconnected_event->reason == WIFI_REASON_ASSOC_LEAVE){
+                ESP_LOGD(TAG,"Successfully disconnected from the existing access point. ");
+                return EVENT_HANDLED;
+            }
+            ESP_LOGW(TAG,"Trying to connect failed");
+            result = local_traverse_state(State_Machine, &Wifi_Active_State[WIFI_CONNECTING_NEW_FAILED_STATE],__FUNCTION__);
+            break;
+
+        default:
+            result= EVENT_UN_HANDLED;
+    }
+    network_handler_print(State_Machine,false);
+    return result;
+}
+static state_machine_result_t WIFI_CONNECTING_NEW_STATE_exit_handler(state_machine_t* const State_Machine) {
+    network_exit_handler_print(State_Machine,true);
+    network_set_timer(0,NULL);
+    FREE_AND_NULL(((network_t *)State_Machine)->event_parameters->disconnected_event);
+    network_exit_handler_print(State_Machine,false);
+    
+    return EVENT_HANDLED;
+}
+
+
+
+/********************************************************************************************* 
+ * WIFI_CONNECTING_NEW_FAILED_STATE
+ */
+static state_machine_result_t WIFI_CONNECTING_NEW_FAILED_STATE_entry_handler(state_machine_t* const State_Machine) {
+    network_t* const nm = (network_t *)State_Machine;
+    network_handler_entry_print(State_Machine,true);
+    if (nm->wifi_connected ) {
+        // Wifi was already connected to an existing access point. Restore connection
+        network_connect_active_ssid(State_Machine);      
+    } 
+  
+    NETWORK_EXECUTE_CB(State_Machine);
+    network_handler_entry_print(State_Machine,false);
+    return EVENT_HANDLED;
+}
+static state_machine_result_t WIFI_CONNECTING_NEW_FAILED_STATE_handler(state_machine_t* const State_Machine) {
+    HANDLE_GLOBAL_EVENT(State_Machine);
+    network_handler_print(State_Machine,true);
+    state_machine_result_t result = EVENT_HANDLED;
+    switch (State_Machine->Event) {
+        case EN_GOT_IP:
+            network_status_update_ip_info(UPDATE_FAILED_ATTEMPT_AND_RESTORE); 
+            result= local_traverse_state(State_Machine, &Wifi_Active_State[WIFI_CONNECTED_STATE],__FUNCTION__);
+            break;
+        case EN_CONNECTED:
+            ESP_LOGD(TAG,"Successfully connected to the previous access point. Waiting for IP Address");
+            result = EVENT_HANDLED;
+            break;
+        case EN_LOST_CONNECTION:
+            network_status_update_ip_info(UPDATE_FAILED_ATTEMPT);
+            messaging_post_message(MESSAGING_ERROR, MESSAGING_CLASS_SYSTEM, "Unable to fall back to previous access point.");
+            result = EVENT_HANDLED;
+            break;
+
+        default:
+            result= EVENT_UN_HANDLED;
+    }
+    network_handler_print(State_Machine,false);
+    return result;
+}
+static state_machine_result_t WIFI_CONNECTING_NEW_FAILED_STATE_exit_handler(state_machine_t* const State_Machine) {
+    network_exit_handler_print(State_Machine,true);
+    network_set_timer(0,NULL);
+    FREE_AND_NULL(((network_t *)State_Machine)->event_parameters->disconnected_event);
+    network_exit_handler_print(State_Machine,false);
+    
+    return EVENT_HANDLED;
+}
+
+
+
+/********************************************************************************************* 
+ * WIFI_CONNECTED_STATE
+ */
+static state_machine_result_t WIFI_CONNECTED_STATE_entry_handler(state_machine_t* const State_Machine) {
+    network_t* const nm = (network_t *)State_Machine;
+    network_handler_entry_print(State_Machine,true);
+    nm->last_connected = esp_timer_get_time();
+    // cancel timeout pulse
+    network_set_timer(0,NULL);
+    ESP_LOGD(TAG, "Checking if wifi config changed.");
+    if (network_wifi_sta_config_changed()) {
+        ESP_LOGD(TAG, "Wifi Config changed. Saving it.");
+        network_wifi_save_sta_config();
+    }
+    ESP_LOGD(TAG, "Updating the ip info json.");
+    network_interface_coexistence(State_Machine);
+    nm->wifi_connected = true;
+    NETWORK_EXECUTE_CB(State_Machine);
+    network_handler_entry_print(State_Machine,false);
+    return EVENT_HANDLED;
+}
+static state_machine_result_t WIFI_CONNECTED_STATE_handler(state_machine_t* const State_Machine) {
+    HANDLE_GLOBAL_EVENT(State_Machine);
+    network_handler_print(State_Machine,true);
+    state_machine_result_t result = EVENT_HANDLED;
+    switch (State_Machine->Event) {
+        case EN_LOST_CONNECTION:
+            result= local_traverse_state(State_Machine, &Wifi_Active_State[WIFI_LOST_CONNECTION_STATE],__FUNCTION__);
+            break;
+        default:
+            result = EVENT_UN_HANDLED;
+            break;
+    }
+    network_handler_print(State_Machine,false);
+    return result;
+}
+static state_machine_result_t WIFI_CONNECTED_STATE_exit_handler(state_machine_t* const State_Machine) {
+    network_exit_handler_print(State_Machine,true);
+    FREE_AND_NULL(((network_t *)State_Machine)->event_parameters->disconnected_event);
+    network_exit_handler_print(State_Machine,false);
+    return EVENT_HANDLED;
+}
+
+
+/********************************************************************************************* 
+ * WIFI_USER_DISCONNECTED_STATE
+ */
+static state_machine_result_t WIFI_USER_DISCONNECTED_STATE_entry_handler(state_machine_t* const State_Machine) {
+    network_handler_entry_print(State_Machine,true);
+    ESP_LOGD(TAG, " WiFi disconnected by user");
+    network_wifi_clear_config();
+    network_status_update_ip_info(UPDATE_USER_DISCONNECT);
+    NETWORK_EXECUTE_CB(State_Machine);
+    network_handler_entry_print(State_Machine,false);
+    return EVENT_HANDLED;
+}
+static state_machine_result_t WIFI_USER_DISCONNECTED_STATE_handler(state_machine_t* const State_Machine) {
+    HANDLE_GLOBAL_EVENT(State_Machine);
+    network_handler_print(State_Machine,true);
+    state_machine_result_t result = EVENT_HANDLED;
+    switch (State_Machine->Event) {
+        case EN_LOST_CONNECTION:
+            // this is a success! we're actually asking to disconnect
+            result= local_traverse_state(State_Machine, &Wifi_Configuring_State[WIFI_CONFIGURING_STATE],__FUNCTION__);
+        break;
+        default:
+            result= EVENT_UN_HANDLED;
+    }
+    network_handler_print(State_Machine,false);
+    return result;
+}
+static state_machine_result_t WIFI_USER_DISCONNECTED_STATE_exit_handler(state_machine_t* const State_Machine) {
+    network_exit_handler_print(State_Machine,true);
+    network_exit_handler_print(State_Machine,false);
+    return EVENT_HANDLED;
+}
+
+/********************************************************************************************* 
+ * WIFI_LOST_CONNECTION_STATE
+ */
+static state_machine_result_t WIFI_LOST_CONNECTION_STATE_entry_handler(state_machine_t* const State_Machine) {
+    network_t* const nm = (network_t *)State_Machine;
+    network_handler_entry_print(State_Machine,true);
+    ESP_LOGE(TAG, " WiFi Connection lost.");
+    messaging_post_message(MESSAGING_WARNING, MESSAGING_CLASS_SYSTEM, "WiFi Connection lost");
+    network_status_update_ip_info(UPDATE_LOST_CONNECTION);
+    network_status_safe_reset_sta_ip_string();
+    if (nm->last_connected > 0)
+        nm->total_connected_time += ((esp_timer_get_time() - nm->last_connected) / (1000 * 1000));
+    nm->last_connected = 0;
+    nm->num_disconnect++;
+    ESP_LOGW(TAG, " Wifi disconnected. Number of disconnects: %d, Average time connected: %d", nm->num_disconnect, nm->num_disconnect > 0 ? (nm->total_connected_time / nm->num_disconnect) : 0);
+    if (nm->retries < WIFI_MANAGER_MAX_RETRY) {
+        nm->retries++;
+        ESP_LOGD(TAG, " Retrying connection connection, %d/%d.", nm->retries, WIFI_MANAGER_MAX_RETRY);
+        network_connect_active_ssid( State_Machine);
+    } else {
+        /* In this scenario the connection was lost beyond repair */
+        nm->retries = 0;
+        ESP_LOGD(TAG,"Checking if ethernet interface is connected");
+        if (network_is_interface_connected(nm->eth_netif)) {
+            ESP_LOGW(TAG, "Cannot connect to Wifi. Falling back to Ethernet ");
+            network_async(EN_ETHERNET_FALLBACK);
+        } else {
+            network_status_update_ip_info(UPDATE_LOST_CONNECTION);
+            wifi_mode_t mode;
+            ESP_LOGW(TAG, " All connect retry attempts failed.");
+
+            /* put us in softAP mode first */
+            esp_wifi_get_mode(&mode);
+            if (WIFI_MODE_APSTA != mode) {
+                 nm->STA_duration = nm->sta_polling_min_ms;
+                network_async_configure();
+            } else if (nm->STA_duration < nm->sta_polling_max_ms) {
+                nm->STA_duration *= 1.25;
+            }
+
+            /* keep polling for existing connection */
+            network_set_timer(nm->STA_duration, "Wifi Polling timeout");
+            ESP_LOGD(TAG, " STA search slow polling of %d", nm->STA_duration);
+        }
+    }
+
+    NETWORK_EXECUTE_CB(State_Machine);
+    network_handler_entry_print(State_Machine,false);
+    return EVENT_HANDLED;
+}
+static state_machine_result_t WIFI_LOST_CONNECTION_STATE_handler(state_machine_t* const State_Machine) {
+    HANDLE_GLOBAL_EVENT(State_Machine);
+    network_t* const nm = (network_t *)State_Machine;
+    state_machine_result_t result = EVENT_HANDLED;
+    network_handler_print(State_Machine,true);
+    switch (State_Machine->Event) {
+        case EN_CONFIGURE:
+            result= local_traverse_state(State_Machine, &Wifi_Configuring_State[WIFI_CONFIGURING_STATE],__FUNCTION__);
+            break;
+        case EN_TIMER:
+            ESP_LOGI(TAG, "Timer: %s ",STR_OR_ALT(nm->timer_tag,"Lost connection"));
+            result= local_traverse_state(State_Machine, &Wifi_Active_State[WIFI_LOST_CONNECTION_STATE],__FUNCTION__);
+            break;
+        case EN_CONNECT:
+            result= local_traverse_state(State_Machine, &Wifi_Configuring_State[WIFI_CONNECTING_STATE],__FUNCTION__);
+            break;
+        default:
+            result= EVENT_UN_HANDLED;
+    }
+    network_handler_print(State_Machine,false);
+    return result;
+}
+static state_machine_result_t WIFI_LOST_CONNECTION_STATE_exit_handler(state_machine_t* const State_Machine) {
+    network_exit_handler_print(State_Machine,true);
+    network_exit_handler_print(State_Machine,false);
+    return EVENT_HANDLED;
+}
+
+
+/********************************************************************************************* 
+ * ETH_ACTIVE_CONNECTED_STATE
+ */
+static state_machine_result_t ETH_ACTIVE_CONNECTED_STATE_entry_handler(state_machine_t* const State_Machine) {
+    network_t* const nm = (network_t *)State_Machine;
+    network_handler_entry_print(State_Machine,true);
+    network_status_update_ip_info(UPDATE_ETHERNET_CONNECTED);
+    nm->ethernet_connected = true;
+    // start a wifi Scan so web ui is populated with available entries
+    NETWORK_EXECUTE_CB(State_Machine);
+    network_handler_entry_print(State_Machine,false);
+    return EVENT_HANDLED;
+}
+static state_machine_result_t ETH_ACTIVE_CONNECTED_STATE_handler(state_machine_t* const State_Machine) {
+    HANDLE_GLOBAL_EVENT(State_Machine);
+    state_machine_result_t result = EVENT_HANDLED;
+    network_handler_print(State_Machine,true);
+    switch (State_Machine->Event) {
+        case EN_TIMER:
+            ESP_LOGD(TAG, "Ignoring ethernet link up timer check");
+            result= EVENT_HANDLED;
+            break;
+        default:
+            result= EVENT_UN_HANDLED;
+    }
+    network_handler_print(State_Machine,false);
+    return result;
+}
+static state_machine_result_t ETH_ACTIVE_CONNECTED_STATE_exit_handler(state_machine_t* const State_Machine) {
+    network_exit_handler_print(State_Machine,true);
+    network_exit_handler_print(State_Machine,false);
+    return EVENT_HANDLED;
+}
+
+static state_machine_result_t local_switch_state(state_machine_t* state_machine,
+                                                 const state_t* const target_state, const char * caller) {
+    const state_t* source = state_machine->State;
+    NETWORK_PRINT_TRANSITION(true, "BEGIN SWITCH", ((network_t *)state_machine)->source_state, target_state, state_machine->Event, true,caller);
+    state_machine_result_t result = switch_state(state_machine, target_state);
+    NETWORK_PRINT_TRANSITION( false,"BEGIN SWITCH", ((network_t *)state_machine)->source_state, target_state, state_machine->Event, true,caller);
+    ((network_t *)state_machine)->source_state = source;
+    return result;
+}
+static state_machine_result_t local_traverse_state(state_machine_t* const state_machine,
+                                                   const state_t* const target_state, const char * caller) {
+    const state_t *  source = state_machine->State;
+    NETWORK_PRINT_TRANSITION( true,"BEGIN TRAVERSE", ((network_t *)state_machine)->source_state, target_state, state_machine->Event, true, caller);
+    state_machine_result_t result = traverse_state(state_machine, target_state);
+    NETWORK_PRINT_TRANSITION( false,"END TRAVERSE", ((network_t *)state_machine)->source_state, target_state, state_machine->Event, true,caller);
+    ((network_t *)state_machine)->source_state = source;
+    return result;
+}
+
+static void network_interface_coexistence(state_machine_t* state_machine) {
+    // this function is called whenever both wifi and ethernet are
+    // found to be active at the same time
+    network_t* nm = (network_t *)state_machine;
+    if (nm->wifi_connected && state_machine->Event == EN_ETH_GOT_IP) {
+        char* eth_reboot = config_alloc_get_default(NVS_TYPE_STR, "eth_boot", "N", 0);
+        network_prioritize_wifi(false);
+        if (strcasecmp(eth_reboot, "N")) {
+            ESP_LOGW(TAG, "Option eth_reboot set to reboot when ethernet is connected. Rebooting");
+            simple_restart();
+        } else {
+            ESP_LOGW(TAG, "Option eth_reboot set to not reboot when ethernet is connected. Using Wifi interface until next reboot");
+        }
+        FREE_AND_NULL(eth_reboot);
+    } else if (get_root(state_machine->State)->Id == NETWORK_ETH_ACTIVE_STATE){
+        messaging_post_message(MESSAGING_WARNING, MESSAGING_CLASS_SYSTEM, "Wifi Connected with Ethernet active. System reload needed");
+        simple_restart();
+    }
+}

文件差异内容过多而无法显示
+ 0 - 0
components/wifi-manager/webapp/dist/css/index.eb4a1bb223a59c656f2c.css


二进制
components/wifi-manager/webapp/dist/css/index.eb4a1bb223a59c656f2c.css.gz


文件差异内容过多而无法显示
+ 6 - 0
components/wifi-manager/webapp/dist/css/index.f2de74635f23b31fbdce.css


二进制
components/wifi-manager/webapp/dist/css/index.f2de74635f23b31fbdce.css.gz


文件差异内容过多而无法显示
+ 0 - 0
components/wifi-manager/webapp/dist/index.html


二进制
components/wifi-manager/webapp/dist/index.html.gz


文件差异内容过多而无法显示
+ 0 - 1
components/wifi-manager/webapp/dist/js/index.0ff7b6.bundle.js


+ 0 - 50
components/wifi-manager/webapp/dist/js/index.0ff7b6.bundle.js.LICENSE.txt

@@ -1,50 +0,0 @@
-/*!
-  * Bootstrap v5.1.3 (https://getbootstrap.com/)
-  * Copyright 2011-2021 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
-  * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
-  */
-
-/*!
- * @overview es6-promise - a tiny implementation of Promises/A+.
- * @copyright Copyright (c) 2014 Yehuda Katz, Tom Dale, Stefan Penner and contributors (Conversion to ES6 API by Jake Archibald)
- * @license   Licensed under MIT license
- *            See https://raw.githubusercontent.com/stefanpenner/es6-promise/master/LICENSE
- * @version   v4.2.8+1e68dce6
- */
-
-/*!
- * Sizzle CSS Selector Engine v2.3.6
- * https://sizzlejs.com/
- *
- * Copyright JS Foundation and other contributors
- * Released under the MIT license
- * https://js.foundation/
- *
- * Date: 2021-02-16
- */
-
-/*!
- * jQuery JavaScript Library v3.6.0
- * https://jquery.com/
- *
- * Includes Sizzle.js
- * https://sizzlejs.com/
- *
- * Copyright OpenJS Foundation and other contributors
- * Released under the MIT license
- * https://jquery.org/license
- *
- * Date: 2021-03-02T17:08Z
- */
-
-/*! < A task is querying the state of itself, so must be running. */
-
-/*! < The task being queried is in a read or pending ready list. */
-
-/*! < The task being queried is in the Blocked state. */
-
-/*! < The task being queried is in the Suspended state, or is in the Blocked state with an infinite time out. */
-
-/*! https://mths.be/he v1.2.0 by @mathias | MIT license */
-
-/*! js-cookie v3.0.1 | MIT */

二进制
components/wifi-manager/webapp/dist/js/index.0ff7b6.bundle.js.gz


文件差异内容过多而无法显示
+ 0 - 0
components/wifi-manager/webapp/dist/js/index.7581c6.bundle.js


二进制
components/wifi-manager/webapp/dist/js/index.7581c6.bundle.js.gz


文件差异内容过多而无法显示
+ 0 - 0
components/wifi-manager/webapp/dist/js/node_vendors.7581c6.bundle.js


二进制
components/wifi-manager/webapp/dist/js/node_vendors.7581c6.bundle.js.gz


+ 2 - 8
components/wifi-manager/webapp/package.json

@@ -3,7 +3,7 @@
   "version": "0.5.0",
   "main": "src/index.html",
   "repository": "git@github.com:sle118/squeezelite-esp32.git",
-  "author": "Andy K., Sebastien",
+  "author": "Sebastien L",
   "license": "MIT",
   "scripts": {
     "prod": "webpack serve --open  --mode=production",
@@ -11,13 +11,6 @@
     "watch": "webpack --progress --watch  --mode=development ",
     "dev": "webpack serve --open  --mode=development"
   },
-  "sideEffects": [
-    "**/*.css",
-    "**/*.scss",
-    "**/index.ejs",
-    "**/index.js",
-    "**/*.js"
-  ],
   "devDependencies": {
     "@babel/core": "^7.16.12",
     "@babel/plugin-transform-runtime": "^7.16.10",
@@ -59,6 +52,7 @@
     "postcss": "^8.4.5",
     "postcss-loader": "^6.2.1",
     "purgecss-webpack-plugin": "^4.1.3",
+    "purgecss-whitelister": "^2.4.0",
     "purify-css": "^1.2.5",
     "purifycss-webpack": "^0.7.0",
     "remixicon": "^2.5.0",

+ 34 - 34
components/wifi-manager/webapp/src/sass/main.scss

@@ -1,42 +1,42 @@
 
 @import "~bootswatch/dist/darkly/variables";
 @import "utils/variables";
-// @import "~bootstrap/scss/bootstrap";
-@import "~bootstrap/scss/functions";
-@import "~bootstrap/scss/variables";
-@import "~bootstrap/scss/mixins";
-@import "~bootstrap/scss/utilities";
+@import "~bootstrap/scss/bootstrap";
+// @import "~bootstrap/scss/functions";
+// @import "~bootstrap/scss/variables";
+// @import "~bootstrap/scss/mixins";
+// @import "~bootstrap/scss/utilities";
 
-// Layout & components
-@import "~bootstrap/scss/root";
-@import "~bootstrap/scss/reboot";
-@import "~bootstrap/scss/type";
-@import "~bootstrap/scss/images";
-@import "~bootstrap/scss/containers";
-@import "~bootstrap/scss/grid";
-@import "~bootstrap/scss/tables";
-@import "~bootstrap/scss/forms";
-@import "~bootstrap/scss/buttons";
-@import "~bootstrap/scss/transitions";
-@import "~bootstrap/scss/dropdown";
-@import "~bootstrap/scss/button-group";
-@import "~bootstrap/scss/nav";
-@import "~bootstrap/scss/navbar";
-@import "~bootstrap/scss/card";
-@import "~bootstrap/scss/badge";
-@import "~bootstrap/scss/alert";
-@import "~bootstrap/scss/progress";
-//@import "~bootstrap/scss/list-group";
-@import "~bootstrap/scss/close";
-@import "~bootstrap/scss/toasts";
-@import "~bootstrap/scss/modal";
-@import "~bootstrap/scss/tooltip";
-@import "~bootstrap/scss/placeholders";
+// // Layout & components
+// @import "~bootstrap/scss/root";
+// @import "~bootstrap/scss/reboot";
+// @import "~bootstrap/scss/type";
+// @import "~bootstrap/scss/images";
+// @import "~bootstrap/scss/containers";
+// @import "~bootstrap/scss/grid";
+// @import "~bootstrap/scss/tables";
+// @import "~bootstrap/scss/forms";
+// @import "~bootstrap/scss/buttons";
+// @import "~bootstrap/scss/transitions";
+// @import "~bootstrap/scss/dropdown";
+// @import "~bootstrap/scss/button-group";
+// @import "~bootstrap/scss/nav";
+// @import "~bootstrap/scss/navbar";
+// @import "~bootstrap/scss/card";
+// @import "~bootstrap/scss/badge";
+// @import "~bootstrap/scss/alert";
+// @import "~bootstrap/scss/progress";
+// //@import "~bootstrap/scss/list-group";
+// @import "~bootstrap/scss/close";
+// @import "~bootstrap/scss/toasts";
+// @import "~bootstrap/scss/modal";
+// @import "~bootstrap/scss/tooltip";
+// @import "~bootstrap/scss/placeholders";
 
-// Helpers
-@import "~bootstrap/scss/helpers";
+// // Helpers
+// @import "~bootstrap/scss/helpers";
 
-// Utilities
-@import "~bootstrap/scss/utilities/api";
+// // Utilities
+// @import "~bootstrap/scss/utilities/api";
 @import "~bootswatch/dist/darkly/bootswatch";
 @import "utils/style";     

+ 3 - 2
components/wifi-manager/webapp/webapp.cmake

@@ -1,4 +1,5 @@
-target_add_binary_data( __idf_wifi-manager webapp/dist/css/index.eb4a1bb223a59c656f2c.css.gz BINARY)
+target_add_binary_data( __idf_wifi-manager webapp/dist/css/index.f2de74635f23b31fbdce.css.gz BINARY)
 target_add_binary_data( __idf_wifi-manager webapp/dist/favicon-32x32.png BINARY)
 target_add_binary_data( __idf_wifi-manager webapp/dist/index.html.gz BINARY)
-target_add_binary_data( __idf_wifi-manager webapp/dist/js/index.0ff7b6.bundle.js.gz BINARY)
+target_add_binary_data( __idf_wifi-manager webapp/dist/js/index.7581c6.bundle.js.gz BINARY)
+target_add_binary_data( __idf_wifi-manager webapp/dist/js/node_vendors.7581c6.bundle.js.gz BINARY)

+ 15 - 10
components/wifi-manager/webapp/webpack.c

@@ -1,29 +1,34 @@
 // Automatically generated. Do not edit manually!.
 #include <inttypes.h>
-extern const uint8_t _index_eb4a1bb223a59c656f2c_css_gz_start[] asm("_binary_index_eb4a1bb223a59c656f2c_css_gz_start");
-extern const uint8_t _index_eb4a1bb223a59c656f2c_css_gz_end[] asm("_binary_index_eb4a1bb223a59c656f2c_css_gz_end");
+extern const uint8_t _index_f2de74635f23b31fbdce_css_gz_start[] asm("_binary_index_f2de74635f23b31fbdce_css_gz_start");
+extern const uint8_t _index_f2de74635f23b31fbdce_css_gz_end[] asm("_binary_index_f2de74635f23b31fbdce_css_gz_end");
 extern const uint8_t _favicon_32x32_png_start[] asm("_binary_favicon_32x32_png_start");
 extern const uint8_t _favicon_32x32_png_end[] asm("_binary_favicon_32x32_png_end");
 extern const uint8_t _index_html_gz_start[] asm("_binary_index_html_gz_start");
 extern const uint8_t _index_html_gz_end[] asm("_binary_index_html_gz_end");
-extern const uint8_t _index_0ff7b6_bundle_js_gz_start[] asm("_binary_index_0ff7b6_bundle_js_gz_start");
-extern const uint8_t _index_0ff7b6_bundle_js_gz_end[] asm("_binary_index_0ff7b6_bundle_js_gz_end");
+extern const uint8_t _index_7581c6_bundle_js_gz_start[] asm("_binary_index_7581c6_bundle_js_gz_start");
+extern const uint8_t _index_7581c6_bundle_js_gz_end[] asm("_binary_index_7581c6_bundle_js_gz_end");
+extern const uint8_t _node_vendors_7581c6_bundle_js_gz_start[] asm("_binary_node_vendors_7581c6_bundle_js_gz_start");
+extern const uint8_t _node_vendors_7581c6_bundle_js_gz_end[] asm("_binary_node_vendors_7581c6_bundle_js_gz_end");
 const char * resource_lookups[] = {
-	"/css/index.eb4a1bb223a59c656f2c.css.gz",
+	"/css/index.f2de74635f23b31fbdce.css.gz",
 	"/favicon-32x32.png",
 	"/index.html.gz",
-	"/js/index.0ff7b6.bundle.js.gz",
+	"/js/index.7581c6.bundle.js.gz",
+	"/js/node_vendors.7581c6.bundle.js.gz",
 ""
 };
 const uint8_t * resource_map_start[] = {
-	_index_eb4a1bb223a59c656f2c_css_gz_start,
+	_index_f2de74635f23b31fbdce_css_gz_start,
 	_favicon_32x32_png_start,
 	_index_html_gz_start,
-	_index_0ff7b6_bundle_js_gz_start
+	_index_7581c6_bundle_js_gz_start,
+	_node_vendors_7581c6_bundle_js_gz_start
 };
 const uint8_t * resource_map_end[] = {
-	_index_eb4a1bb223a59c656f2c_css_gz_end,
+	_index_f2de74635f23b31fbdce_css_gz_end,
 	_favicon_32x32_png_end,
 	_index_html_gz_end,
-	_index_0ff7b6_bundle_js_gz_end
+	_index_7581c6_bundle_js_gz_end,
+	_node_vendors_7581c6_bundle_js_gz_end
 };

+ 36 - 18
components/wifi-manager/webapp/webpack.config.js

@@ -17,6 +17,8 @@ const devserver = require('./webpack/webpack.dev.js');
 const fs = require('fs');
 const zlib = require("zlib");
 const PurgeCSSPlugin = require('purgecss-webpack-plugin')
+const whitelister = require('purgecss-whitelister');
+
 
 const PATHS = {
   src: path.join(__dirname, 'src')
@@ -129,11 +131,13 @@ module.exports = (env, options) => (
           },          
           {
             test: /\.js$/,
-            exclude: /(node_modules|bower_components)/,
+            //exclude: /(node_modules|bower_components)/,
             use: {
               loader: "babel-loader",
               options: {
                 presets: ["@babel/preset-env"],
+                plugins: ['@babel/plugin-transform-runtime']
+
               },
             },
           },
@@ -199,7 +203,11 @@ module.exports = (env, options) => (
           filename: "css/[name].[contenthash].css",
         }),
         new PurgeCSSPlugin({
-          paths: glob.sync(`${PATHS.src}/**/*`,  { nodir: true }),
+          keyframes: false,
+          paths: glob.sync(`${path.join(__dirname, 'src')}/**/*`, {
+            nodir: true
+          }),
+          whitelist: whitelister('bootstrap/dist/css/bootstrap.css')
         }),
         new webpack.ProvidePlugin({
           $: "jquery",
@@ -224,10 +232,9 @@ module.exports = (env, options) => (
           function (stats, arguments) {
 
             if (options.mode !== "production") return;
-            let wifiManagerPath=path.posix.resolve(process.cwd(),'..','..');
-            let buildCRootPath=path.posix.resolve(process.cwd(),'..','..','..','..');
-            let distPath = path.posix.resolve('dist');
-            let posixWebAppPath=path.posix.resolve(process.cwd(),'..');
+            let buildRootPath = path.join(process.cwd(),'..','..','..');
+            let wifiManagerPath=glob.sync(path.join(buildRootPath,'components/**/wifi-manager*'))[0];
+            let buildCRootPath=glob.sync(buildRootPath)[0];
             fs.appendFileSync('./dist/index.html.gz', 
               zlib.gzipSync(fs.readFileSync('./dist/index.html'), 
               {
@@ -285,7 +292,8 @@ extern const uint8_t * resource_map_end[];`;
                 
                 list.forEach(foundFile => {
                   let exportName = path.basename(foundFile).replace(/[\. \-]/gm, '_');
-                  let cmakeFileName = path.posix.relative(wifiManagerPath,foundFile);
+                  //take the full path of the file and make it relative to the build directory
+                  let cmakeFileName = path.posix.relative(wifiManagerPath,glob.sync(path.resolve(foundFile))[0]);
                   let httpRelativePath=path.posix.join('/',path.posix.relative('dist',foundFile));
                   exportDef += `extern const uint8_t _${exportName}_start[] asm("_binary_${exportName}_start");\nextern const uint8_t _${exportName}_end[] asm("_binary_${exportName}_end");\n`;
                   lookupDef += `\t"${httpRelativePath}",\n`;
@@ -314,9 +322,19 @@ extern const uint8_t * resource_map_end[];`;
       ],
       optimization: {
         minimize: true,
+        providedExports: true,
         minimizer: [
          
-          new TerserPlugin(),
+          new TerserPlugin({
+            terserOptions: {
+              format: {
+                  comments: false,
+              },
+            },
+            extractComments: false,
+          // enable parallel running
+            parallel: true,
+          }),
           new HtmlMinimizerPlugin(),
           new CssMinimizerPlugin(),
           new ImageMinimizerPlugin({
@@ -358,16 +376,16 @@ extern const uint8_t * resource_map_end[];`;
           //new BundleAnalyzerPlugin()
 
         ],
-        // splitChunks: {
-        //   cacheGroups: {
-        //     styles: {
-        //       name: 'styles',
-        //       test: /\.css$/,
-        //       chunks: 'all',
-        //       enforce: true
-        //     }
-        //   }
-        // }
+        splitChunks: {
+          cacheGroups: {
+              vendor: {
+                  name: "node_vendors",
+                  test: /[\\/]node_modules[\\/]/,
+                  chunks: "all",
+              }
+          }
+      }
+      
       },
       //   output: {
       //     filename: "[name].js",

+ 1 - 1
components/wifi-manager/webapp/webpack.h

@@ -1,6 +1,6 @@
 /***********************************
 webpack_headers
-dist/css/index.eb4a1bb223a59c656f2c.css.gz,dist/favicon-32x32.png,dist/index.html.gz,dist/js/index.0ff7b6.bundle.js.gz
+dist/css/index.f2de74635f23b31fbdce.css.gz,dist/favicon-32x32.png,dist/index.html.gz,dist/js/index.7581c6.bundle.js.gz,dist/js/node_vendors.7581c6.bundle.js.gz
 ***********************************/
 #pragma once
 #include <inttypes.h>

+ 4 - 0
docker/entrypoint.sh

@@ -6,4 +6,8 @@ echo "npm version is $(npm --version)"
 echo "node version is $(node --version)"
 echo "To build the web application, run:"
 echo "pushd components/wifi-manager/webapp/ && npm rebuild node-sass && npm run-script build && popd"
+echo ""
+echo "To run size statistics, run:"
+echo "puncover/runner.py --gcc_tools_base $GCC_TOOLS_BASE --elf ./build/recovery.elf --build_dir build --src_root ."
+echo ""
 exec "$@"

部分文件因为文件数量过多而无法显示