add logger
This commit is contained in:
		
							parent
							
								
									b7d266e245
								
							
						
					
					
						commit
						8b1f8457b4
					
				| @ -10,6 +10,7 @@ idf_component_register( | |||||||
| 		./led.c | 		./led.c | ||||||
| 		./commands.c | 		./commands.c | ||||||
| 		./servos.c | 		./servos.c | ||||||
|  | 		./logger.c | ||||||
| 	INCLUDE_DIRS "./" | 	INCLUDE_DIRS "./" | ||||||
| 	PRIV_REQUIRES | 	PRIV_REQUIRES | ||||||
| 		# project components | 		# project components | ||||||
|  | |||||||
| @ -8,6 +8,7 @@ | |||||||
| #include <string.h> | #include <string.h> | ||||||
| 
 | 
 | ||||||
| #include "commands.h" | #include "commands.h" | ||||||
|  | #include "logger.h" | ||||||
| #include "utils.h" | #include "utils.h" | ||||||
| #include "led.h" | #include "led.h" | ||||||
| #include "servos.h" | #include "servos.h" | ||||||
| @ -144,13 +145,26 @@ int cmd_history(char* line, void* cli) | |||||||
| 	return 0; | 	return 0; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | int cmd_showlog(char* line, void* cli) | ||||||
|  | { | ||||||
|  | 	logger_printFullLog(cli); | ||||||
|  | 	return 0; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | int cmd_clearlog(char* line, void* cli) | ||||||
|  | { | ||||||
|  | 	logger_clearBuffer(); | ||||||
|  | 	return 0; | ||||||
|  | } | ||||||
| 
 | 
 | ||||||
| const CMD_t Commands[] = { | const CMD_t Commands[] = { | ||||||
| 	{ "history", &cmd_history }, | 	{ "history", &cmd_history }, | ||||||
| 	{ "d", &cmd_contrl }, | 	{ "d", &cmd_contrl }, | ||||||
| 	{ "shutdown", &cmd_shutdown }, | 	{ "shutdown", &cmd_shutdown }, | ||||||
| 	{ "status", &cmd_status }, | 	{ "status", &cmd_status }, | ||||||
| 	{ "led", &setLed } | 	{ "led", &setLed }, | ||||||
|  | 	{ "log", &cmd_showlog }, | ||||||
|  | 	{ "logclear", &cmd_clearlog } | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| CMDList_t* getCMDList() | CMDList_t* getCMDList() | ||||||
|  | |||||||
							
								
								
									
										51
									
								
								rx_esp32/src/logger.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										51
									
								
								rx_esp32/src/logger.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,51 @@ | |||||||
|  | #include <stdarg.h> | ||||||
|  | #include <stdint.h> | ||||||
|  | #include <stdio.h> | ||||||
|  | 
 | ||||||
|  | #include "logger.h" | ||||||
|  | 
 | ||||||
|  | #ifndef LOGGER_BUFFER_SIZE | ||||||
|  | #define LOGGER_BUFFER_SIZE 65536 | ||||||
|  | #endif | ||||||
|  | 
 | ||||||
|  | char Logger_buff[LOGGER_BUFFER_SIZE]; | ||||||
|  | uint16_t Logger_buff_wp = 0; | ||||||
|  | 
 | ||||||
|  | void logger_printf(const char *fmt, ...) | ||||||
|  | { | ||||||
|  | 	va_list args; | ||||||
|  | 	va_start(args, fmt); | ||||||
|  | 	int len = vsnprintf(&Logger_buff[Logger_buff_wp], LOGGER_BUFFER_SIZE-Logger_buff_wp, fmt, args); | ||||||
|  | 	va_end(args); | ||||||
|  | 
 | ||||||
|  | 	puts(&Logger_buff[Logger_buff_wp]); | ||||||
|  | 	Logger_buff_wp += len + 1; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void logger_printFullLog(CLI_t* cli) | ||||||
|  | { | ||||||
|  | 	uint16_t line = 0; | ||||||
|  | 	char str[20]; | ||||||
|  | 	snprintf(str, 20, "%03u: ", line); | ||||||
|  | 	CLI_stringOut(cli, str); | ||||||
|  | 	line++; | ||||||
|  | 	for (uint16_t i = 0; i < Logger_buff_wp-1; i++) | ||||||
|  | 	{ | ||||||
|  | 		if (Logger_buff[i] != '\0') | ||||||
|  | 		{ | ||||||
|  | 			CLI_charOut_save(cli, Logger_buff[i]); | ||||||
|  | 		} | ||||||
|  | 		else | ||||||
|  | 		{ | ||||||
|  | 			snprintf(str, 20, "\n%03u: ", line); | ||||||
|  | 			CLI_stringOut(cli, str); | ||||||
|  | 			line++; | ||||||
|  | 		} | ||||||
|  |    } | ||||||
|  |    printf("\n"); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void logger_clearBuffer() | ||||||
|  | { | ||||||
|  | 	Logger_buff_wp = 0; | ||||||
|  | } | ||||||
							
								
								
									
										26
									
								
								rx_esp32/src/logger.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								rx_esp32/src/logger.h
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,26 @@ | |||||||
|  | #ifndef LOGGER_H | ||||||
|  | #define LOGGER_H | ||||||
|  | 
 | ||||||
|  | #include <CLI/CLI.h> | ||||||
|  | 
 | ||||||
|  | typedef enum { | ||||||
|  | 	LOG_DEBUG, | ||||||
|  | 	LOG_INFO, | ||||||
|  | 	LOG_WARN, | ||||||
|  | 	LOG_ERROR, | ||||||
|  | 	LOG_CRITICAL | ||||||
|  | } logger_level_t; | ||||||
|  | 
 | ||||||
|  | #define CONSTANT_INT_TO_STR(str) #str | ||||||
|  | 
 | ||||||
|  | #define LOG_D(fmt, args...) logger_printf("DEBUG %30s:%3u  " fmt, __FILE__, __LINE__, ## args) | ||||||
|  | #define LOG_I(fmt, args...) logger_printf("INFO  %30s:%3u  " fmt, __FILE__, __LINE__, ## args) | ||||||
|  | #define LOG_W(fmt, args...) logger_printf("WARN  %30s:%3u  " fmt, __FILE__, __LINE__, ## args) | ||||||
|  | #define LOG_E(fmt, args...) logger_printf("ERROR %30s:%3u  " fmt, __FILE__, __LINE__, ## args) | ||||||
|  | #define LOG_C(fmt, args...) logger_printf("\n\n\n!!!!!!!!!! CRITICAL ERROR !!!!!!!!!!!!!!\n\n\tfile: %s:%3u\n\tmsg: " fmt "\n\n", __FILE__, __LINE__, ## args) | ||||||
|  | 
 | ||||||
|  | void logger_printf( const char *fmt, ...); | ||||||
|  | void logger_printFullLog(CLI_t* cli); | ||||||
|  | void logger_clearBuffer(); | ||||||
|  | 
 | ||||||
|  | #endif | ||||||
| @ -15,6 +15,7 @@ | |||||||
| #include "wifi.h" | #include "wifi.h" | ||||||
| #include "led.h" | #include "led.h" | ||||||
| #include "servos.h" | #include "servos.h" | ||||||
|  | #include "logger.h" | ||||||
| 
 | 
 | ||||||
| bool volatile running = true; | bool volatile running = true; | ||||||
| CMDList_t* cmdList; | CMDList_t* cmdList; | ||||||
| @ -73,15 +74,17 @@ void app_main() { | |||||||
| 	if (bits & WIFI_CONNECTED_BIT) | 	if (bits & WIFI_CONNECTED_BIT) | ||||||
| 	{ | 	{ | ||||||
| 		led_setRGB(0, 20, 0); | 		led_setRGB(0, 20, 0); | ||||||
| 		printf("INFO: main: connected to ap SSID '%s'\n", WIFI_SSID); | 		LOG_I("main: connected to ap SSID '%s'", WIFI_SSID); | ||||||
| 	} | 	} | ||||||
| 	else if (bits & WIFI_FAIL_BIT) | 	else if (bits & WIFI_FAIL_BIT) | ||||||
| 	{ | 	{ | ||||||
| 		led_setRGB(2, 0, 0); | 		led_setRGB(2, 0, 0); | ||||||
|  | 		LOG_E("main: Failed to connect to SSID '%s',", WIFI_SSID); | ||||||
| 	} | 	} | ||||||
| 	else | 	else | ||||||
| 	{ | 	{ | ||||||
| 		led_setRGB(2, 0, 0); | 		led_setRGB(2, 0, 0); | ||||||
|  | 		LOG_C("main: UNEXPECTED EVENT"); | ||||||
| 		return; | 		return; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -1,9 +1,10 @@ | |||||||
| #include "driver/ledc.h" | #include <driver/ledc.h> | ||||||
| #include <stdint.h> | #include <stdint.h> | ||||||
| 
 | 
 | ||||||
| #include "config.h" | #include "config.h" | ||||||
| 
 | 
 | ||||||
| #include "servos.h" | #include "servos.h" | ||||||
|  | #include "logger.h" | ||||||
| 
 | 
 | ||||||
| #define SERVO_LEDC_TIMER        LEDC_TIMER_0 | #define SERVO_LEDC_TIMER        LEDC_TIMER_0 | ||||||
| #define SERVO_LEDC_MODE         LEDC_LOW_SPEED_MODE | #define SERVO_LEDC_MODE         LEDC_LOW_SPEED_MODE | ||||||
| @ -57,7 +58,7 @@ void servo_init(void) | |||||||
| 			.hpoint         = 0 | 			.hpoint         = 0 | ||||||
| 		}; | 		}; | ||||||
| 		ledc_channel_config(&ledc_channel); | 		ledc_channel_config(&ledc_channel); | ||||||
| 		printf("DEBUG: inited servo channel %d (ledc: %u, gpio: %d)\n", i, Server_chs[i].channel, Server_chs[i].gpio); | 		LOG_D("servo_init: inited servo channel %d (ledc: %u, gpio: %d)", i, Server_chs[i].channel, Server_chs[i].gpio); | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| void servo_deinit(void) | void servo_deinit(void) | ||||||
|  | |||||||
| @ -4,9 +4,11 @@ | |||||||
| #include <stdint.h> | #include <stdint.h> | ||||||
| #include <inttypes.h> | #include <inttypes.h> | ||||||
| 
 | 
 | ||||||
| #include "esp_system.h" | #include <esp_system.h> | ||||||
| #include "esp_chip_info.h" | #include <esp_chip_info.h> | ||||||
| #include "esp_flash.h" | #include <esp_flash.h> | ||||||
|  | 
 | ||||||
|  | #include "logger.h" | ||||||
| 
 | 
 | ||||||
| char* getNextArg(char* args, const char separator) | char* getNextArg(char* args, const char separator) | ||||||
| { | { | ||||||
| @ -87,7 +89,7 @@ void printChipInfo() | |||||||
| 	esp_chip_info_t chip_info; | 	esp_chip_info_t chip_info; | ||||||
| 	uint32_t flash_size; | 	uint32_t flash_size; | ||||||
| 	esp_chip_info(&chip_info); | 	esp_chip_info(&chip_info); | ||||||
| 	printf("This is %s chip with %d CPU core(s), %s%s%s%s, ", | 	LOG_D("This is %s chip with %d CPU core(s), %s%s%s%s", | ||||||
| 		CONFIG_IDF_TARGET, | 		CONFIG_IDF_TARGET, | ||||||
| 		chip_info.cores, | 		chip_info.cores, | ||||||
| 		(chip_info.features & CHIP_FEATURE_WIFI_BGN) ? "WiFi/" : "", | 		(chip_info.features & CHIP_FEATURE_WIFI_BGN) ? "WiFi/" : "", | ||||||
| @ -98,15 +100,17 @@ void printChipInfo() | |||||||
| 
 | 
 | ||||||
| 	unsigned major_rev = chip_info.revision / 100; | 	unsigned major_rev = chip_info.revision / 100; | ||||||
| 	unsigned minor_rev = chip_info.revision % 100; | 	unsigned minor_rev = chip_info.revision % 100; | ||||||
| 	printf("silicon revision v%d.%d, ", major_rev, minor_rev); | 	LOG_D("silicon revision v%d.%d", major_rev, minor_rev); | ||||||
| 	if(esp_flash_get_size(NULL, &flash_size) != ESP_OK) { | 	if(esp_flash_get_size(NULL, &flash_size) != ESP_OK) | ||||||
| 		printf("Get flash size failed"); | 	{ | ||||||
|  | 		LOG_W("Get flash size failed"); | ||||||
| 		return; | 		return; | ||||||
| 	}     | 	} | ||||||
| 	 | 	 | ||||||
| 	printf("%" PRIu32 "MB %s flash\n", flash_size / (uint32_t)(1024 * 1024), | 	LOG_D("%" PRIu32 "MB %s flash",  | ||||||
|  | 		flash_size / (uint32_t)(1024 * 1024), | ||||||
| 		(chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "embedded" : "external" | 		(chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "embedded" : "external" | ||||||
| 	); | 	); | ||||||
| 
 | 
 | ||||||
| 	printf("Minimum free heap size: %" PRIu32 " bytes\n", esp_get_minimum_free_heap_size()); | 	LOG_D("Minimum free heap size: %" PRIu32 " bytes", esp_get_minimum_free_heap_size()); | ||||||
| } | } | ||||||
|  | |||||||
| @ -3,11 +3,12 @@ | |||||||
| #include <stdbool.h> | #include <stdbool.h> | ||||||
| #include <stdint.h> | #include <stdint.h> | ||||||
| 
 | 
 | ||||||
| #include "nvs_flash.h" | #include <nvs_flash.h> | ||||||
| #include "esp_wifi.h" | #include <esp_wifi.h> | ||||||
| #include "esp_event.h" | #include <esp_event.h> | ||||||
| 
 | 
 | ||||||
| #include "config.h" | #include "config.h" | ||||||
|  | #include "logger.h" | ||||||
| 
 | 
 | ||||||
| #define MAX_RETRY_ATTEMPTS 20 | #define MAX_RETRY_ATTEMPTS 20 | ||||||
| // static int s_ap_creds_num = 0;
 | // static int s_ap_creds_num = 0;
 | ||||||
| @ -24,31 +25,27 @@ static void event_handler(void* arg, esp_event_base_t event_base, int32_t event_ | |||||||
| 		switch (event_id) | 		switch (event_id) | ||||||
| 		{ | 		{ | ||||||
| 			case WIFI_EVENT_WIFI_READY: | 			case WIFI_EVENT_WIFI_READY: | ||||||
| 				printf("INFO: wifi: WiFi ready\n"); | 				LOG_I("wifi: WiFi ready"); | ||||||
| 				break; | 				break; | ||||||
| 			case WIFI_EVENT_SCAN_DONE: | 			case WIFI_EVENT_SCAN_DONE: | ||||||
| 				printf("INFO: wifi: Finished scanning AP\n"); | 				LOG_I("wifi: Finished scanning AP"); | ||||||
| 				break; | 				break; | ||||||
| 			case WIFI_EVENT_STA_START: | 			case WIFI_EVENT_STA_START: | ||||||
| 				printf("INFO: wifi: Station start\n"); | 				LOG_I("wifi: Station start"); | ||||||
| 				esp_wifi_connect(); | 				esp_wifi_connect(); | ||||||
| 				break; | 				break; | ||||||
| 			case WIFI_EVENT_STA_STOP: | 			case WIFI_EVENT_STA_STOP: | ||||||
| 				printf("INFO: wifi: Station stop\n"); | 				LOG_I("wifi: Station stop"); | ||||||
| 				break; | 				break; | ||||||
| 			case WIFI_EVENT_STA_CONNECTED: | 			case WIFI_EVENT_STA_CONNECTED: | ||||||
| 				printf("INFO: wifi: Station connected to AP\n"); | 				LOG_I("wifi: Station connected to AP"); | ||||||
| 				break; | 				break; | ||||||
| 			case WIFI_EVENT_STA_DISCONNECTED: | 			case WIFI_EVENT_STA_DISCONNECTED: | ||||||
| 				printf("WARN: wifi: Station disconnected from AP\n"); | 				LOG_W("wifi: Station disconnected from AP"); | ||||||
| 				if (s_retry_num < MAX_RETRY_ATTEMPTS) | 				if (s_retry_num < MAX_RETRY_ATTEMPTS) | ||||||
| 				{ | 				{ | ||||||
| 					s_retry_num++; | 					s_retry_num++; | ||||||
| 					printf("INFO: wifi: retry num %d\n", s_retry_num); | 					LOG_I("wifi: retry num %d", s_retry_num); | ||||||
| 					for (unsigned long i=0; i < 10000000; i++) |  | ||||||
| 					{ |  | ||||||
| 						// printf(".\n");
 |  | ||||||
| 					} |  | ||||||
| 					esp_wifi_connect(); | 					esp_wifi_connect(); | ||||||
| 				} | 				} | ||||||
| 				else | 				else | ||||||
| @ -58,119 +55,119 @@ static void event_handler(void* arg, esp_event_base_t event_base, int32_t event_ | |||||||
| 				break; | 				break; | ||||||
| 				break; | 				break; | ||||||
| 			case WIFI_EVENT_STA_AUTHMODE_CHANGE: | 			case WIFI_EVENT_STA_AUTHMODE_CHANGE: | ||||||
| 				printf("INFO: wifi: the auth mode of AP connected by device's station changed\n"); | 				LOG_I("wifi: the auth mode of AP connected by device's station changed"); | ||||||
| 				break; | 				break; | ||||||
| 			case WIFI_EVENT_STA_WPS_ER_SUCCESS: | 			case WIFI_EVENT_STA_WPS_ER_SUCCESS: | ||||||
| 				printf("INFO: wifi: Station wps succeeds in enrollee mode\n"); | 				LOG_I("wifi: Station wps succeeds in enrollee mode"); | ||||||
| 				break; | 				break; | ||||||
| 			case WIFI_EVENT_STA_WPS_ER_FAILED: | 			case WIFI_EVENT_STA_WPS_ER_FAILED: | ||||||
| 				printf("ERROR: wifi: Station wps fails in enrollee mode\n"); | 				LOG_E("wifi: Station wps fails in enrollee mode"); | ||||||
| 				break; | 				break; | ||||||
| 			case WIFI_EVENT_STA_WPS_ER_TIMEOUT: | 			case WIFI_EVENT_STA_WPS_ER_TIMEOUT: | ||||||
| 				printf("ERROR: wifi: Station wps timeout in enrollee mode\n"); | 				LOG_E("wifi: Station wps timeout in enrollee mode"); | ||||||
| 				break; | 				break; | ||||||
| 			case WIFI_EVENT_STA_WPS_ER_PIN: | 			case WIFI_EVENT_STA_WPS_ER_PIN: | ||||||
| 				printf("INFO: wifi: Station wps pin code in enrollee mode\n"); | 				LOG_I("wifi: Station wps pin code in enrollee mode"); | ||||||
| 				break; | 				break; | ||||||
| 			case WIFI_EVENT_STA_WPS_ER_PBC_OVERLAP: | 			case WIFI_EVENT_STA_WPS_ER_PBC_OVERLAP: | ||||||
| 				printf("INFO: wifi: Station wps overlap in enrollee mode\n"); | 				LOG_I("wifi: Station wps overlap in enrollee mode"); | ||||||
| 				break; | 				break; | ||||||
| 			case WIFI_EVENT_AP_START: | 			case WIFI_EVENT_AP_START: | ||||||
| 				printf("INFO: wifi: Soft-AP start\n"); | 				LOG_I("wifi: Soft-AP start"); | ||||||
| 				break; | 				break; | ||||||
| 			case WIFI_EVENT_AP_STOP: | 			case WIFI_EVENT_AP_STOP: | ||||||
| 				printf("INFO: wifi: Soft-AP stop\n"); | 				LOG_I("wifi: Soft-AP stop"); | ||||||
| 				break; | 				break; | ||||||
| 			case WIFI_EVENT_AP_STACONNECTED: | 			case WIFI_EVENT_AP_STACONNECTED: | ||||||
| 				printf("INFO: wifi: a station connected to Soft-AP\n"); | 				LOG_I("wifi: a station connected to Soft-AP"); | ||||||
| 				break; | 				break; | ||||||
| 			case WIFI_EVENT_AP_STADISCONNECTED: | 			case WIFI_EVENT_AP_STADISCONNECTED: | ||||||
| 				printf("WARN: wifi: a station disconnected from Soft-AP\n"); | 				LOG_W("wifi: a station disconnected from Soft-AP"); | ||||||
| 				break; | 				break; | ||||||
| 			case WIFI_EVENT_AP_PROBEREQRECVED: | 			case WIFI_EVENT_AP_PROBEREQRECVED: | ||||||
| 				printf("INFO: wifi: Receive probe request packet in soft-AP interface\n"); | 				LOG_I("wifi: Receive probe request packet in soft-AP interface"); | ||||||
| 				break; | 				break; | ||||||
| 			case WIFI_EVENT_FTM_REPORT: | 			case WIFI_EVENT_FTM_REPORT: | ||||||
| 				printf("INFO: wifi: Receive report of FTM procedure\n"); | 				LOG_I("wifi: Receive report of FTM procedure"); | ||||||
| 				break; | 				break; | ||||||
| 			case WIFI_EVENT_STA_BSS_RSSI_LOW: | 			case WIFI_EVENT_STA_BSS_RSSI_LOW: | ||||||
| 				printf("INFO: wifi: AP's RSSI crossed configured threshold\n"); | 				LOG_I("wifi: AP's RSSI crossed configured threshold"); | ||||||
| 				break; | 				break; | ||||||
| 			case WIFI_EVENT_ACTION_TX_STATUS: | 			case WIFI_EVENT_ACTION_TX_STATUS: | ||||||
| 				printf("INFO: wifi: Status indication of Action Tx operation\n"); | 				LOG_I("wifi: Status indication of Action Tx operation"); | ||||||
| 				break; | 				break; | ||||||
| 			case WIFI_EVENT_ROC_DONE: | 			case WIFI_EVENT_ROC_DONE: | ||||||
| 				printf("INFO: wifi: Remain-on-Channel operation complete\n"); | 				LOG_I("wifi: Remain-on-Channel operation complete"); | ||||||
| 				break; | 				break; | ||||||
| 			case WIFI_EVENT_STA_BEACON_TIMEOUT: | 			case WIFI_EVENT_STA_BEACON_TIMEOUT: | ||||||
| 				printf("ERROR: wifi: Station beacon timeout\n"); | 				LOG_E("wifi: Station beacon timeout"); | ||||||
| 				break; | 				break; | ||||||
| 			case WIFI_EVENT_CONNECTIONLESS_MODULE_WAKE_INTERVAL_START: | 			case WIFI_EVENT_CONNECTIONLESS_MODULE_WAKE_INTERVAL_START: | ||||||
| 				printf("INFO: wifi: Connectionless module wake interval start\n"); | 				LOG_I("wifi: Connectionless module wake interval start"); | ||||||
| 				break; | 				break; | ||||||
| 			case WIFI_EVENT_AP_WPS_RG_SUCCESS: | 			case WIFI_EVENT_AP_WPS_RG_SUCCESS: | ||||||
| 				printf("INFO: wifi: Soft-AP wps succeeds in registrar mode\n"); | 				LOG_I("wifi: Soft-AP wps succeeds in registrar mode"); | ||||||
| 				break; | 				break; | ||||||
| 			case WIFI_EVENT_AP_WPS_RG_FAILED: | 			case WIFI_EVENT_AP_WPS_RG_FAILED: | ||||||
| 				printf("ERROR: wifi: Soft-AP wps fails in registrar mode\n"); | 				LOG_E("wifi: Soft-AP wps fails in registrar mode"); | ||||||
| 				break; | 				break; | ||||||
| 			case WIFI_EVENT_AP_WPS_RG_TIMEOUT: | 			case WIFI_EVENT_AP_WPS_RG_TIMEOUT: | ||||||
| 				printf("ERROR: wifi: Soft-AP wps timeout in registrar mode\n"); | 				LOG_E("wifi: Soft-AP wps timeout in registrar mode"); | ||||||
| 				break; | 				break; | ||||||
| 			case WIFI_EVENT_AP_WPS_RG_PIN: | 			case WIFI_EVENT_AP_WPS_RG_PIN: | ||||||
| 				printf("INFO: wifi: Soft-AP wps pin code in registrar mode\n"); | 				LOG_I("wifi: Soft-AP wps pin code in registrar mode"); | ||||||
| 				break; | 				break; | ||||||
| 			case WIFI_EVENT_AP_WPS_RG_PBC_OVERLAP: | 			case WIFI_EVENT_AP_WPS_RG_PBC_OVERLAP: | ||||||
| 				printf("INFO: wifi: Soft-AP wps overlap in registrar mode\n"); | 				LOG_I("wifi: Soft-AP wps overlap in registrar mode"); | ||||||
| 				break; | 				break; | ||||||
| 			case WIFI_EVENT_ITWT_SETUP: | 			case WIFI_EVENT_ITWT_SETUP: | ||||||
| 				printf("INFO: wifi: iTWT setup\n"); | 				LOG_I("wifi: iTWT setup"); | ||||||
| 				break; | 				break; | ||||||
| 			case WIFI_EVENT_ITWT_TEARDOWN: | 			case WIFI_EVENT_ITWT_TEARDOWN: | ||||||
| 				printf("INFO: wifi: iTWT teardown\n"); | 				LOG_I("wifi: iTWT teardown"); | ||||||
| 				break; | 				break; | ||||||
| 			case WIFI_EVENT_ITWT_PROBE: | 			case WIFI_EVENT_ITWT_PROBE: | ||||||
| 				printf("INFO: wifi: iTWT probe\n"); | 				LOG_I("wifi: iTWT probe"); | ||||||
| 				break; | 				break; | ||||||
| 			case WIFI_EVENT_ITWT_SUSPEND: | 			case WIFI_EVENT_ITWT_SUSPEND: | ||||||
| 				printf("INFO: wifi: iTWT suspend\n"); | 				LOG_I("wifi: iTWT suspend"); | ||||||
| 				break; | 				break; | ||||||
| 			case WIFI_EVENT_NAN_STARTED: | 			case WIFI_EVENT_NAN_STARTED: | ||||||
| 				printf("INFO: wifi: NAN Discovery has started\n"); | 				LOG_I("wifi: NAN Discovery has started"); | ||||||
| 				break; | 				break; | ||||||
| 			case WIFI_EVENT_NAN_STOPPED: | 			case WIFI_EVENT_NAN_STOPPED: | ||||||
| 				printf("INFO: wifi: NAN Discovery has stopped\n"); | 				LOG_I("wifi: NAN Discovery has stopped"); | ||||||
| 				break; | 				break; | ||||||
| 			case WIFI_EVENT_NAN_SVC_MATCH: | 			case WIFI_EVENT_NAN_SVC_MATCH: | ||||||
| 				printf("INFO: wifi: NAN Service Discovery match found\n"); | 				LOG_I("wifi: NAN Service Discovery match found"); | ||||||
| 				break; | 				break; | ||||||
| 			case WIFI_EVENT_NAN_REPLIED: | 			case WIFI_EVENT_NAN_REPLIED: | ||||||
| 				printf("INFO: wifi: Replied to a NAN peer with Service Discovery match\n"); | 				LOG_I("wifi: Replied to a NAN peer with Service Discovery match"); | ||||||
| 				break; | 				break; | ||||||
| 			case WIFI_EVENT_NAN_RECEIVE: | 			case WIFI_EVENT_NAN_RECEIVE: | ||||||
| 				printf("INFO: wifi: Received a Follow-up message\n"); | 				LOG_I("wifi: Received a Follow-up message"); | ||||||
| 				break; | 				break; | ||||||
| 			case WIFI_EVENT_NDP_INDICATION: | 			case WIFI_EVENT_NDP_INDICATION: | ||||||
| 				printf("INFO: wifi: Received NDP Request from a NAN Peer\n"); | 				LOG_I("wifi: Received NDP Request from a NAN Peer"); | ||||||
| 				break; | 				break; | ||||||
| 			case WIFI_EVENT_NDP_CONFIRM: | 			case WIFI_EVENT_NDP_CONFIRM: | ||||||
| 				printf("INFO: wifi: NDP Confirm Indication\n"); | 				LOG_I("wifi: NDP Confirm Indication"); | ||||||
| 				break; | 				break; | ||||||
| 			case WIFI_EVENT_NDP_TERMINATED: | 			case WIFI_EVENT_NDP_TERMINATED: | ||||||
| 				printf("INFO: wifi: NAN Datapath terminated indication\n"); | 				LOG_I("wifi: NAN Datapath terminated indication"); | ||||||
| 				break; | 				break; | ||||||
| 			case WIFI_EVENT_HOME_CHANNEL_CHANGE: | 			case WIFI_EVENT_HOME_CHANNEL_CHANGE: | ||||||
| 				printf("INFO: wifi: WiFi home channel change,doesn't occur when scanning\n"); | 				LOG_I("wifi: WiFi home channel change,doesn't occur when scanning"); | ||||||
| 				break; | 				break; | ||||||
| 			case WIFI_EVENT_MAX: | 			case WIFI_EVENT_MAX: | ||||||
| 				printf("INFO: wifi: Invalid WiFi event ID\n"); | 				LOG_I("wifi: Invalid WiFi event ID"); | ||||||
| 				break; | 				break; | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) | 	else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) | ||||||
| 	{ | 	{ | ||||||
| 		ip_event_got_ip_t* event = (ip_event_got_ip_t*) event_data; | 		ip_event_got_ip_t* event = (ip_event_got_ip_t*) event_data; | ||||||
| 		printf("INFO: wifi: got ip: " IPSTR "\n", IP2STR(&event->ip_info.ip)); | 		LOG_I("wifi: got ip: " IPSTR "", IP2STR(&event->ip_info.ip)); | ||||||
| 		s_retry_num = 0; | 		s_retry_num = 0; | ||||||
| 		xEventGroupSetBits(s_wifi_event_group, WIFI_CONNECTED_BIT); | 		xEventGroupSetBits(s_wifi_event_group, WIFI_CONNECTED_BIT); | ||||||
| 	} | 	} | ||||||
| @ -198,7 +195,7 @@ void wifiInit() | |||||||
| 	ESP_ERROR_CHECK(esp_event_handler_instance_register( | 	ESP_ERROR_CHECK(esp_event_handler_instance_register( | ||||||
| 			IP_EVENT, IP_EVENT_STA_GOT_IP, &event_handler, NULL, &instance_got_ip)); | 			IP_EVENT, IP_EVENT_STA_GOT_IP, &event_handler, NULL, &instance_got_ip)); | ||||||
| 
 | 
 | ||||||
| 	printf("INFO: wifi: wifi_init_sta finished.\n"); | 	LOG_I("wifi: wifi_init_sta finished."); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void wifi_connect() | void wifi_connect() | ||||||
|  | |||||||
| @ -8,6 +8,8 @@ | |||||||
| #include "nvs_flash.h" | #include "nvs_flash.h" | ||||||
| #include "regex.h" | #include "regex.h" | ||||||
| 
 | 
 | ||||||
|  | #include "logger.h" | ||||||
|  | 
 | ||||||
| #define SCAN_LIST_SIZE 30 | #define SCAN_LIST_SIZE 30 | ||||||
| 
 | 
 | ||||||
| #ifdef CONFIG_EXAMPLE_USE_SCAN_CHANNEL_BITMAP | #ifdef CONFIG_EXAMPLE_USE_SCAN_CHANNEL_BITMAP | ||||||
| @ -22,37 +24,37 @@ static void print_auth_mode(int authmode) | |||||||
| { | { | ||||||
|     switch (authmode) { |     switch (authmode) { | ||||||
|     case WIFI_AUTH_OPEN: |     case WIFI_AUTH_OPEN: | ||||||
|         printf("INFO: \tAuthmode: WIFI_AUTH_OPEN\n"); |         LOG_I("\tAuthmode: WIFI_AUTH_OPEN"); | ||||||
|         break; |         break; | ||||||
|     case WIFI_AUTH_OWE: |     case WIFI_AUTH_OWE: | ||||||
|         printf("INFO: \tAuthmode: WIFI_AUTH_OWE\n"); |         LOG_I("\tAuthmode: WIFI_AUTH_OWE"); | ||||||
|         break; |         break; | ||||||
|     case WIFI_AUTH_WEP: |     case WIFI_AUTH_WEP: | ||||||
|         printf("INFO: \tAuthmode: WIFI_AUTH_WEP\n"); |         LOG_I("\tAuthmode: WIFI_AUTH_WEP"); | ||||||
|         break; |         break; | ||||||
|     case WIFI_AUTH_WPA_PSK: |     case WIFI_AUTH_WPA_PSK: | ||||||
|         printf("INFO: \tAuthmode: WIFI_AUTH_WPA_PSK\n"); |         LOG_I("\tAuthmode: WIFI_AUTH_WPA_PSK"); | ||||||
|         break; |         break; | ||||||
|     case WIFI_AUTH_WPA2_PSK: |     case WIFI_AUTH_WPA2_PSK: | ||||||
|         printf("INFO: \tAuthmode: WIFI_AUTH_WPA2_PSK\n"); |         LOG_I("\tAuthmode: WIFI_AUTH_WPA2_PSK"); | ||||||
|         break; |         break; | ||||||
|     case WIFI_AUTH_WPA_WPA2_PSK: |     case WIFI_AUTH_WPA_WPA2_PSK: | ||||||
|         printf("INFO: \tAuthmode: WIFI_AUTH_WPA_WPA2_PSK\n"); |         LOG_I("\tAuthmode: WIFI_AUTH_WPA_WPA2_PSK"); | ||||||
|         break; |         break; | ||||||
|     case WIFI_AUTH_ENTERPRISE: |     case WIFI_AUTH_ENTERPRISE: | ||||||
|         printf("INFO: \tAuthmode: WIFI_AUTH_ENTERPRISE\n"); |         LOG_I("\tAuthmode: WIFI_AUTH_ENTERPRISE"); | ||||||
|         break; |         break; | ||||||
|     case WIFI_AUTH_WPA3_PSK: |     case WIFI_AUTH_WPA3_PSK: | ||||||
|         printf("INFO: \tAuthmode: WIFI_AUTH_WPA3_PSK\n"); |         LOG_I("\tAuthmode: WIFI_AUTH_WPA3_PSK"); | ||||||
|         break; |         break; | ||||||
|     case WIFI_AUTH_WPA2_WPA3_PSK: |     case WIFI_AUTH_WPA2_WPA3_PSK: | ||||||
|         printf("INFO: \tAuthmode: WIFI_AUTH_WPA2_WPA3_PSK\n"); |         LOG_I("\tAuthmode: WIFI_AUTH_WPA2_WPA3_PSK"); | ||||||
|         break; |         break; | ||||||
|     case WIFI_AUTH_WPA3_ENT_192: |     case WIFI_AUTH_WPA3_ENT_192: | ||||||
|         printf("INFO: \tAuthmode: WIFI_AUTH_WPA3_ENT_192\n"); |         LOG_I("\tAuthmode: WIFI_AUTH_WPA3_ENT_192"); | ||||||
|         break; |         break; | ||||||
|     default: |     default: | ||||||
|         printf("INFO: \tAuthmode: WIFI_AUTH_UNKNOWN\n"); |         LOG_I("\tAuthmode: WIFI_AUTH_UNKNOWN"); | ||||||
|         break; |         break; | ||||||
|     } |     } | ||||||
| } | } | ||||||
| @ -61,70 +63,70 @@ static void print_cipher_type(int pairwise_cipher, int group_cipher) | |||||||
| { | { | ||||||
|     switch (pairwise_cipher) { |     switch (pairwise_cipher) { | ||||||
|     case WIFI_CIPHER_TYPE_NONE: |     case WIFI_CIPHER_TYPE_NONE: | ||||||
|         printf("INFO: \tPairwise Cipher: WIFI_CIPHER_TYPE_NONE\n"); |         LOG_I("\tPairwise Cipher: WIFI_CIPHER_TYPE_NONE"); | ||||||
|         break; |         break; | ||||||
|     case WIFI_CIPHER_TYPE_WEP40: |     case WIFI_CIPHER_TYPE_WEP40: | ||||||
|         printf("INFO: \tPairwise Cipher: WIFI_CIPHER_TYPE_WEP40\n"); |         LOG_I("\tPairwise Cipher: WIFI_CIPHER_TYPE_WEP40"); | ||||||
|         break; |         break; | ||||||
|     case WIFI_CIPHER_TYPE_WEP104: |     case WIFI_CIPHER_TYPE_WEP104: | ||||||
|         printf("INFO: \tPairwise Cipher: WIFI_CIPHER_TYPE_WEP104\n"); |         LOG_I("\tPairwise Cipher: WIFI_CIPHER_TYPE_WEP104"); | ||||||
|         break; |         break; | ||||||
|     case WIFI_CIPHER_TYPE_TKIP: |     case WIFI_CIPHER_TYPE_TKIP: | ||||||
|         printf("INFO: \tPairwise Cipher: WIFI_CIPHER_TYPE_TKIP\n"); |         LOG_I("\tPairwise Cipher: WIFI_CIPHER_TYPE_TKIP"); | ||||||
|         break; |         break; | ||||||
|     case WIFI_CIPHER_TYPE_CCMP: |     case WIFI_CIPHER_TYPE_CCMP: | ||||||
|         printf("INFO: \tPairwise Cipher: WIFI_CIPHER_TYPE_CCMP\n"); |         LOG_I("\tPairwise Cipher: WIFI_CIPHER_TYPE_CCMP"); | ||||||
|         break; |         break; | ||||||
|     case WIFI_CIPHER_TYPE_TKIP_CCMP: |     case WIFI_CIPHER_TYPE_TKIP_CCMP: | ||||||
|         printf("INFO: \tPairwise Cipher: WIFI_CIPHER_TYPE_TKIP_CCMP\n"); |         LOG_I("\tPairwise Cipher: WIFI_CIPHER_TYPE_TKIP_CCMP"); | ||||||
|         break; |         break; | ||||||
|     case WIFI_CIPHER_TYPE_AES_CMAC128: |     case WIFI_CIPHER_TYPE_AES_CMAC128: | ||||||
|         printf("INFO: \tPairwise Cipher: WIFI_CIPHER_TYPE_AES_CMAC128\n"); |         LOG_I("\tPairwise Cipher: WIFI_CIPHER_TYPE_AES_CMAC128"); | ||||||
|         break; |         break; | ||||||
|     case WIFI_CIPHER_TYPE_SMS4: |     case WIFI_CIPHER_TYPE_SMS4: | ||||||
|         printf("INFO: \tPairwise Cipher: WIFI_CIPHER_TYPE_SMS4\n"); |         LOG_I("\tPairwise Cipher: WIFI_CIPHER_TYPE_SMS4"); | ||||||
|         break; |         break; | ||||||
|     case WIFI_CIPHER_TYPE_GCMP: |     case WIFI_CIPHER_TYPE_GCMP: | ||||||
|         printf("INFO: \tPairwise Cipher: WIFI_CIPHER_TYPE_GCMP\n"); |         LOG_I("\tPairwise Cipher: WIFI_CIPHER_TYPE_GCMP"); | ||||||
|         break; |         break; | ||||||
|     case WIFI_CIPHER_TYPE_GCMP256: |     case WIFI_CIPHER_TYPE_GCMP256: | ||||||
|         printf("INFO: \tPairwise Cipher: WIFI_CIPHER_TYPE_GCMP256\n"); |         LOG_I("\tPairwise Cipher: WIFI_CIPHER_TYPE_GCMP256"); | ||||||
|         break; |         break; | ||||||
|     default: |     default: | ||||||
|         printf("INFO: \tPairwise Cipher: WIFI_CIPHER_TYPE_UNKNOWN\n"); |         LOG_I("\tPairwise Cipher: WIFI_CIPHER_TYPE_UNKNOWN"); | ||||||
|         break; |         break; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     switch (group_cipher) { |     switch (group_cipher) { | ||||||
|     case WIFI_CIPHER_TYPE_NONE: |     case WIFI_CIPHER_TYPE_NONE: | ||||||
|         printf("INFO: \tGroup Cipher: WIFI_CIPHER_TYPE_NONE\n"); |         LOG_I("\tGroup Cipher: WIFI_CIPHER_TYPE_NONE"); | ||||||
|         break; |         break; | ||||||
|     case WIFI_CIPHER_TYPE_WEP40: |     case WIFI_CIPHER_TYPE_WEP40: | ||||||
|         printf("INFO: \tGroup Cipher: WIFI_CIPHER_TYPE_WEP40\n"); |         LOG_I("\tGroup Cipher: WIFI_CIPHER_TYPE_WEP40"); | ||||||
|         break; |         break; | ||||||
|     case WIFI_CIPHER_TYPE_WEP104: |     case WIFI_CIPHER_TYPE_WEP104: | ||||||
|         printf("INFO: \tGroup Cipher: WIFI_CIPHER_TYPE_WEP104\n"); |         LOG_I("\tGroup Cipher: WIFI_CIPHER_TYPE_WEP104"); | ||||||
|         break; |         break; | ||||||
|     case WIFI_CIPHER_TYPE_TKIP: |     case WIFI_CIPHER_TYPE_TKIP: | ||||||
|         printf("INFO: \tGroup Cipher: WIFI_CIPHER_TYPE_TKIP\n"); |         LOG_I("\tGroup Cipher: WIFI_CIPHER_TYPE_TKIP"); | ||||||
|         break; |         break; | ||||||
|     case WIFI_CIPHER_TYPE_CCMP: |     case WIFI_CIPHER_TYPE_CCMP: | ||||||
|         printf("INFO: \tGroup Cipher: WIFI_CIPHER_TYPE_CCMP\n"); |         LOG_I("\tGroup Cipher: WIFI_CIPHER_TYPE_CCMP"); | ||||||
|         break; |         break; | ||||||
|     case WIFI_CIPHER_TYPE_TKIP_CCMP: |     case WIFI_CIPHER_TYPE_TKIP_CCMP: | ||||||
|         printf("INFO: \tGroup Cipher: WIFI_CIPHER_TYPE_TKIP_CCMP\n"); |         LOG_I("\tGroup Cipher: WIFI_CIPHER_TYPE_TKIP_CCMP"); | ||||||
|         break; |         break; | ||||||
|     case WIFI_CIPHER_TYPE_SMS4: |     case WIFI_CIPHER_TYPE_SMS4: | ||||||
|         printf("INFO: \tGroup Cipher: WIFI_CIPHER_TYPE_SMS4\n"); |         LOG_I("\tGroup Cipher: WIFI_CIPHER_TYPE_SMS4"); | ||||||
|         break; |         break; | ||||||
|     case WIFI_CIPHER_TYPE_GCMP: |     case WIFI_CIPHER_TYPE_GCMP: | ||||||
|         printf("INFO: \tGroup Cipher: WIFI_CIPHER_TYPE_GCMP\n"); |         LOG_I("\tGroup Cipher: WIFI_CIPHER_TYPE_GCMP"); | ||||||
|         break; |         break; | ||||||
|     case WIFI_CIPHER_TYPE_GCMP256: |     case WIFI_CIPHER_TYPE_GCMP256: | ||||||
|         printf("INFO: \tGroup Cipher: WIFI_CIPHER_TYPE_GCMP256\n"); |         LOG_I("\tGroup Cipher: WIFI_CIPHER_TYPE_GCMP256"); | ||||||
|         break; |         break; | ||||||
|     default: |     default: | ||||||
|         printf("INFO: \tGroup Cipher: WIFI_CIPHER_TYPE_UNKNOWN\n"); |         LOG_I("\tGroup Cipher: WIFI_CIPHER_TYPE_UNKNOWN"); | ||||||
|         break; |         break; | ||||||
|     } |     } | ||||||
| } | } | ||||||
| @ -153,7 +155,7 @@ void wifi_scan() | |||||||
| #ifdef USE_CHANNEL_BTIMAP | #ifdef USE_CHANNEL_BTIMAP | ||||||
| 	wifi_scan_config_t *scan_config = (wifi_scan_config_t *)calloc(1,sizeof(wifi_scan_config_t)); | 	wifi_scan_config_t *scan_config = (wifi_scan_config_t *)calloc(1,sizeof(wifi_scan_config_t)); | ||||||
| 	if (!scan_config) { | 	if (!scan_config) { | ||||||
| 		printf("ERROR: Memory Allocation for scan config failed!\n"); | 		LOG_I("Memory Allocation for scan config failed!"); | ||||||
| 		return; | 		return; | ||||||
| 	} | 	} | ||||||
| 	array_2_channel_bitmap(channel_list, CHANNEL_LIST_SIZE, scan_config); | 	array_2_channel_bitmap(channel_list, CHANNEL_LIST_SIZE, scan_config); | ||||||
| @ -163,16 +165,16 @@ void wifi_scan() | |||||||
|     esp_wifi_scan_start(NULL, true); |     esp_wifi_scan_start(NULL, true); | ||||||
| #endif /*USE_CHANNEL_BTIMAP*/ | #endif /*USE_CHANNEL_BTIMAP*/ | ||||||
| 
 | 
 | ||||||
| 	printf("INFO: Max AP number ap_info can hold = %u\n", number); | 	LOG_I("Max AP number ap_info can hold = %u", number); | ||||||
| 	ESP_ERROR_CHECK(esp_wifi_scan_get_ap_num(&ap_count)); | 	ESP_ERROR_CHECK(esp_wifi_scan_get_ap_num(&ap_count)); | ||||||
| 	ESP_ERROR_CHECK(esp_wifi_scan_get_ap_records(&number, ap_info)); | 	ESP_ERROR_CHECK(esp_wifi_scan_get_ap_records(&number, ap_info)); | ||||||
| 	printf("INFO: Total APs scanned = %u, actual AP number ap_info holds = %u\n", ap_count, number); | 	LOG_I("Total APs scanned = %u, actual AP number ap_info holds = %u", ap_count, number); | ||||||
| 	for (int i = 0; i < number; i++) { | 	for (int i = 0; i < number; i++) { | ||||||
| 		printf("INFO: %s  \tRSSI: %d", ap_info[i].ssid, ap_info[i].rssi); | 		LOG_I("%s  \tRSSI: %d", ap_info[i].ssid, ap_info[i].rssi); | ||||||
| 		print_auth_mode(ap_info[i].authmode); | 		print_auth_mode(ap_info[i].authmode); | ||||||
| 		// if (ap_info[i].authmode != WIFI_AUTH_WEP) {
 | 		// if (ap_info[i].authmode != WIFI_AUTH_WEP) {
 | ||||||
| 		// 	print_cipher_type(ap_info[i].pairwise_cipher, ap_info[i].group_cipher);
 | 		// 	print_cipher_type(ap_info[i].pairwise_cipher, ap_info[i].group_cipher);
 | ||||||
| 		// }
 | 		// }
 | ||||||
| 		printf("INFO: \tChannel: %d\n", ap_info[i].primary); | 		LOG_I("\tChannel: %d", ap_info[i].primary); | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user