temp fix network manager log verbosity

This commit is contained in:
Sebastien L
2021-12-29 15:08:24 -05:00
parent f076a7260e
commit a93bd3c187
5 changed files with 33 additions and 118 deletions

View File

@@ -658,7 +658,7 @@ esp_err_t network_get_hostname(const char** hostname) {
return esp_netif_get_hostname(get_connected_interface(), hostname);
}
void network_set_timer(uint16_t duration) {
void network_set_timer(uint16_t duration, const char * tag) {
if (duration > 0) {
if (!NM.state_timer) {
ESP_LOGD(TAG, "Starting new pulse check timer with period of %u ms.", duration);

View File

@@ -82,6 +82,7 @@ typedef struct
uint16_t dhcp_timeout;
uint16_t wifi_dhcp_fail_ms;
queue_message * event_parameters;
const char * timer_tag;
} network_t;
@@ -308,7 +309,7 @@ void network_manager_initialise_mdns();
* @brief Register a callback to a custom function when specific network manager states are reached.
*/
bool network_is_wifi_prioritized();
void network_set_timer(uint16_t duration);
void network_set_timer(uint16_t duration, const char * tag);
void network_set_hostname(esp_netif_t * netif);
esp_err_t network_get_ip_info_for_netif(esp_netif_t* netif, tcpip_adapter_ip_info_t* ipInfo);
void network_start_stop_dhcp(esp_netif_t* netif, bool start);
@@ -327,7 +328,8 @@ void network_manager_format_from_to_states(esp_log_level_t level, const char* pr
void network_manager_format_state_machine(esp_log_level_t level, const char* prefix, state_machine_t * state_machine, bool show_source, const char * caller) ;
char* network_manager_alloc_get_mac_string(uint8_t mac[6]);
#if defined(LOG_LOCAL_LEVEL) && LOG_LOCAL_LEVEL >=ESP_LOG_VERBOSE
#if defined(LOG_LOCAL_LEVEL)
#if LOG_LOCAL_LEVEL >=5
#define NETWORK_PRINT_TRANSITION(begin, prefix, source,target, event, print_source,caller ) network_manager_format_from_to_states(ESP_LOG_VERBOSE, prefix, source,target, event, print_source,caller )
#define NETWORK_DEBUG_STATE_MACHINE(begin, cb_prefix,state_machine,print_from,caller) network_manager_format_state_machine(ESP_LOG_DEBUG,cb_prefix,state_machine,print_from,caller)
#define NETWORK_EXECUTE_CB(mch) network_execute_cb(mch,__FUNCTION__);
@@ -335,14 +337,17 @@ char* network_manager_alloc_get_mac_string(uint8_t mac[6]);
#define network_exit_handler_print(State_Machine, begin) network_manager_format_state_machine(ESP_LOG_DEBUG,begin?"EXIT START":"END END",State_Machine,false,__FUNCTION__)
#define network_handler_print(State_Machine, begin) network_manager_format_state_machine(ESP_LOG_DEBUG,begin?"HANDLER START":"HANDLER END",State_Machine,false,__FUNCTION__)
#elif defined(LOG_LOCAL_LEVEL) && LOG_LOCAL_LEVEL >= ESP_LOG_DEBUG
#elif LOG_LOCAL_LEVEL >= 4
#define network_handler_entry_print(State_Machine, begin) if(begin) network_manager_format_state_machine(ESP_LOG_DEBUG,begin?"BEGIN ENTRY":"END ENTRY",State_Machine,false,"")
#define network_exit_handler_print(State_Machine, begin) if(begin) network_manager_format_state_machine(ESP_LOG_DEBUG,begin?"BEGIN EXIT":"END EXIT",State_Machine,false,"")
#define network_handler_print(State_Machine, begin) if(begin) network_manager_format_state_machine(ESP_LOG_DEBUG,begin?"HANDLER START":"HANDLER END",State_Machine,false,"")
#define NETWORK_PRINT_TRANSITION(begin, prefix, source,target, event, print_source,caller ) if(begin) network_manager_format_from_to_states(ESP_LOG_DEBUG, prefix, source,target, event, print_source,caller )#define NETWORK_EXECUTE_CB(mch) network_execute_cb(mch,__FUNCTION__);
#define NETWORK_DEBUG_STATE_MACHINE(begin, cb_prefix,state_machine,print_from,caller) if(begin) network_manager_format_state_machine(ESP_LOG_DEBUG,cb_prefix,state_machine,print_from,caller)
#else
#endif
#endif
#ifndef NETWORK_PRINT_TRANSITION
#define network_exit_handler_print(nm, begin)
#define network_handler_entry_print(State_Machine, begin)
#define network_handler_print(State_Machine, begin)

View File

@@ -362,7 +362,7 @@ static state_machine_result_t ETH_STARTING_STATE_exit_handler(state_machine_t* c
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);
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;
@@ -370,6 +370,7 @@ static state_machine_result_t NETWORK_ETH_ACTIVE_STATE_entry_handler(state_machi
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__);
@@ -387,7 +388,7 @@ static state_machine_result_t NETWORK_ETH_ACTIVE_STATE_handler(state_machine_t*
result= local_traverse_state(State_Machine, &Eth_Active_State[ETH_ACTIVE_CONNECTED_STATE],__FUNCTION__);
break;
case EN_TIMER:
ESP_LOGW(TAG, "Ethernet link timeout. Rebooting to wifi");
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__);
@@ -411,7 +412,7 @@ static state_machine_result_t NETWORK_ETH_ACTIVE_STATE_handler(state_machine_t*
}
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);
network_set_timer(0,NULL);
network_exit_handler_print(State_Machine,false);
return EVENT_HANDLED;
}
@@ -457,7 +458,7 @@ static state_machine_result_t ETH_CONNECTING_NEW_STATE_handler(state_machine_t*
}
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);
network_set_timer(0,NULL);
network_exit_handler_print(State_Machine,false);
return EVENT_HANDLED;
}
@@ -468,7 +469,7 @@ static state_machine_result_t ETH_CONNECTING_NEW_STATE_exit_handler(state_machin
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);
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);
@@ -482,7 +483,7 @@ static state_machine_result_t ETH_ACTIVE_LINKDOWN_STATE_handler(state_machine_t*
}
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);
network_set_timer(0,NULL);
network_exit_handler_print(State_Machine,false);
return EVENT_HANDLED;
@@ -494,7 +495,7 @@ static state_machine_result_t ETH_ACTIVE_LINKDOWN_STATE_exit_handler(state_machi
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);
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);
@@ -719,7 +720,7 @@ static state_machine_result_t WIFI_CONFIGURING_CONNECT_STATE_handler(state_machi
case EN_CONNECTED:
result=EVENT_HANDLED;
ESP_LOGD(TAG,"Wifi was connected. Waiting for IP address");
network_set_timer(nm->dhcp_timeout);
network_set_timer(nm->dhcp_timeout,"DHCP Timeout");
break;
case EN_GOT_IP:
network_status_update_ip_info(UPDATE_CONNECTION_OK);
@@ -739,7 +740,7 @@ static state_machine_result_t WIFI_CONFIGURING_CONNECT_STATE_exit_handler(state_
network_exit_handler_print(State_Machine,true);
FREE_AND_NULL(((network_t *)State_Machine)->event_parameters->disconnected_event);
network_set_timer(0);
network_set_timer(0,NULL);
network_exit_handler_print(State_Machine,false);
return EVENT_HANDLED;
}
@@ -825,7 +826,7 @@ static state_machine_result_t WIFI_CONNECTING_STATE_entry_handler(state_machine_
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);
network_set_timer(nm->STA_duration,"Wifi Polling timeout");
NETWORK_EXECUTE_CB(State_Machine);
network_handler_entry_print(State_Machine,false);
return EVENT_HANDLED;
@@ -833,6 +834,7 @@ static state_machine_result_t WIFI_CONNECTING_STATE_entry_handler(state_machine_
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:
@@ -841,6 +843,7 @@ static state_machine_result_t WIFI_CONNECTING_STATE_handler(state_machine_t* con
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:
@@ -899,7 +902,7 @@ static state_machine_result_t WIFI_CONNECTING_NEW_STATE_handler(state_machine_t*
}
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);
network_set_timer(0,NULL);
FREE_AND_NULL(((network_t *)State_Machine)->event_parameters->disconnected_event);
network_exit_handler_print(State_Machine,false);
@@ -950,7 +953,7 @@ static state_machine_result_t WIFI_CONNECTING_NEW_FAILED_STATE_handler(state_mac
}
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);
network_set_timer(0,NULL);
FREE_AND_NULL(((network_t *)State_Machine)->event_parameters->disconnected_event);
network_exit_handler_print(State_Machine,false);
@@ -967,7 +970,7 @@ static state_machine_result_t WIFI_CONNECTED_STATE_entry_handler(state_machine_t
network_handler_entry_print(State_Machine,true);
nm->last_connected = esp_timer_get_time();
// cancel timeout pulse
network_set_timer(0);
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.");
@@ -1077,7 +1080,7 @@ static state_machine_result_t WIFI_LOST_CONNECTION_STATE_entry_handler(state_mac
}
/* keep polling for existing connection */
network_set_timer(nm->STA_duration);
network_set_timer(nm->STA_duration, "Wifi Polling timeout");
ESP_LOGD(TAG, " STA search slow polling of %d", nm->STA_duration);
}
}
@@ -1088,6 +1091,7 @@ static state_machine_result_t WIFI_LOST_CONNECTION_STATE_entry_handler(state_mac
}
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) {
@@ -1095,6 +1099,7 @@ static state_machine_result_t WIFI_LOST_CONNECTION_STATE_handler(state_machine_t
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: