From 69e02e590925c6fcb628fee69f164c6b56e0251e Mon Sep 17 00:00:00 2001 From: Zhang Jun Hao Date: Mon, 30 Jul 2018 10:28:48 +0800 Subject: [PATCH] feat(examples): remove wifi station machine example --- examples/wifi/wifi_station_machine/Makefile | 9 - .../wifi_station_machine/main/component.mk | 7 - .../wifi_station_machine/main/user_config.h | 16 - .../main/wifi_state_machine.c | 336 ------------------ .../main/wifi_state_machine.h | 34 -- examples/wifi/wifi_station_machine/readme.txt | 56 --- 6 files changed, 458 deletions(-) delete mode 100644 examples/wifi/wifi_station_machine/Makefile delete mode 100644 examples/wifi/wifi_station_machine/main/component.mk delete mode 100644 examples/wifi/wifi_station_machine/main/user_config.h delete mode 100644 examples/wifi/wifi_station_machine/main/wifi_state_machine.c delete mode 100644 examples/wifi/wifi_station_machine/main/wifi_state_machine.h delete mode 100644 examples/wifi/wifi_station_machine/readme.txt diff --git a/examples/wifi/wifi_station_machine/Makefile b/examples/wifi/wifi_station_machine/Makefile deleted file mode 100644 index 6ffd6c62..00000000 --- a/examples/wifi/wifi_station_machine/Makefile +++ /dev/null @@ -1,9 +0,0 @@ -# -# This is a project Makefile. It is assumed the directory this Makefile resides in is a -# project subdirectory. -# - -PROJECT_NAME := wifi_station_machine_example - -include $(IDF_PATH)/make/project.mk - diff --git a/examples/wifi/wifi_station_machine/main/component.mk b/examples/wifi/wifi_station_machine/main/component.mk deleted file mode 100644 index 7d7b29bf..00000000 --- a/examples/wifi/wifi_station_machine/main/component.mk +++ /dev/null @@ -1,7 +0,0 @@ -# -# "main" pseudo-component makefile. -# -# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.) - - - diff --git a/examples/wifi/wifi_station_machine/main/user_config.h b/examples/wifi/wifi_station_machine/main/user_config.h deleted file mode 100644 index 034ff89c..00000000 --- a/examples/wifi/wifi_station_machine/main/user_config.h +++ /dev/null @@ -1,16 +0,0 @@ -/* - This example code is in the Public Domain (or CC0 licensed, at your option.) - - Unless required by applicable law or agreed to in writing, this - software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - CONDITIONS OF ANY KIND, either express or implied. -*/ - -#ifndef __USER_CONFIG_H__ -#define __USER_CONFIG_H__ - -#define SSID "N600" -#define PASSWORD "espressif" - -#endif - diff --git a/examples/wifi/wifi_station_machine/main/wifi_state_machine.c b/examples/wifi/wifi_station_machine/main/wifi_state_machine.c deleted file mode 100644 index 74b80846..00000000 --- a/examples/wifi/wifi_station_machine/main/wifi_state_machine.c +++ /dev/null @@ -1,336 +0,0 @@ -/* WiFi station machine example - - This example code is in the Public Domain (or CC0 licensed, at your option.) - - Unless required by applicable law or agreed to in writing, this - software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - CONDITIONS OF ANY KIND, either express or implied. -*/ - -#include -#include -#include - -#include "esp_misc.h" -#include "esp_sta.h" -#include "esp_softap.h" -#include "esp_system.h" -#include "esp_timer.h" - -#include "wifi_state_machine.h" - -#include "user_config.h" - -typedef void (* wifi_state_cb_t)(); - -wifi_state_cb_t on_station_first_connect = NULL; -wifi_state_cb_t on_station_connect = NULL; -wifi_disco_cb_t on_station_disconnect = NULL; - -wifi_state_cb_t on_client_connect = NULL; -wifi_state_cb_t on_client_disconnect = NULL; - -volatile bool wifi_station_static_ip = false; -volatile bool wifi_station_is_connected = false; - -void wifi_event_handler_cb(System_Event_t* event) -{ - static bool station_was_connected = false; - - if (event == NULL) { - return; - } - - //printf("[WiFi] event %u\n", event->event_id); - - switch (event->event_id) { - case EVENT_STAMODE_DISCONNECTED: - wifi_station_is_connected = false; - Event_StaMode_Disconnected_t* ev = (Event_StaMode_Disconnected_t*)&event->event_info; - - if (on_station_disconnect) { - on_station_disconnect(ev->reason); - } - - break; - - case EVENT_STAMODE_CONNECTED: - if (wifi_station_static_ip) { - wifi_station_is_connected = true; - - if (!station_was_connected) { - station_was_connected = true; - - if (on_station_first_connect) { - on_station_first_connect(); - } - } - - if (on_station_connect) { - on_station_connect(); - } - } - - break; - - case EVENT_STAMODE_DHCP_TIMEOUT: - if (wifi_station_is_connected) { - wifi_station_is_connected = false; - - if (on_station_disconnect) { - on_station_disconnect(REASON_UNSPECIFIED); - } - } - - break; - - case EVENT_STAMODE_GOT_IP: - wifi_station_is_connected = true; - - if (!station_was_connected) { - station_was_connected = true; - - if (on_station_first_connect) { - on_station_first_connect(); - } - } - - if (on_station_connect) { - on_station_connect(); - } - - break; - - case EVENT_SOFTAPMODE_STACONNECTED: - if (on_client_connect) { - on_client_connect(); - } - - break; - - case EVENT_SOFTAPMODE_STADISCONNECTED: - if (on_client_disconnect) { - on_client_disconnect(); - } - - break; - - default: - break; - } -} - -void set_on_station_first_connect(wifi_state_cb_t cb) -{ - on_station_first_connect = cb; -} - -void set_on_station_connect(wifi_state_cb_t cb) -{ - on_station_connect = cb; -} - -void set_on_station_disconnect(wifi_disco_cb_t cb) -{ - on_station_disconnect = cb; -} - -void set_on_client_connect(wifi_state_cb_t cb) -{ - on_client_connect = cb; -} - -void set_on_client_disconnect(wifi_state_cb_t cb) -{ - on_client_disconnect = cb; -} - -bool wifi_set_mode(WIFI_MODE mode) -{ - if (!mode) { - bool s = wifi_set_opmode(mode); - wifi_fpm_open(); - wifi_fpm_set_sleep_type(MODEM_SLEEP_T); - wifi_fpm_do_sleep(0xFFFFFFFF); - return s; - } - - wifi_fpm_close(); - return wifi_set_opmode(mode); -} - -WIFI_MODE init_esp_wifi(void) -{ - wifi_set_event_handler_cb(wifi_event_handler_cb); - WIFI_MODE mode = wifi_get_opmode_default(); - wifi_set_mode(mode); - return mode; -} - -bool start_wifi_station(const char* ssid, const char* pass) -{ - WIFI_MODE mode = wifi_get_opmode(); - - if ((mode & STATION_MODE) == 0) { - mode |= STATION_MODE; - - if (!wifi_set_mode(mode)) { - printf("Failed to enable Station mode!\n"); - return false; - } - } - - if (!ssid) { - printf("No SSID Given. Will connect to the station saved in flash\n"); - return true; - } - - struct station_config config; - - memset((void*)&config, 0, sizeof(struct station_config)); - - strcpy((char*)config.ssid, ssid); - - if (pass) { - strcpy((char*)config.password, pass); - } - - if (!wifi_station_set_config(&config)) { - printf("Failed to set Station config!\n"); - return false; - } - - if (!wifi_station_dhcpc_status()) { - printf("DHCP is not started. Starting it...\n"); - - if (!wifi_station_dhcpc_start()) { - printf("DHCP start failed!\n"); - return false; - } - } - - return wifi_station_connect(); -} - -bool stop_wifi_station(void) -{ - WIFI_MODE mode = wifi_get_opmode(); - mode &= ~STATION_MODE; - - if (!wifi_set_mode(mode)) { - printf("Failed to disable Station mode!\n"); - return false; - } - - return true; -} - -bool start_wifi_ap(const char* ssid, const char* pass) -{ - WIFI_MODE mode = wifi_get_opmode(); - - if ((mode & SOFTAP_MODE) == 0) { - mode |= SOFTAP_MODE; - - if (!wifi_set_mode(mode)) { - printf("Failed to enable AP mode!\n"); - return false; - } - } - - if (!ssid) { - printf("No SSID Given. Will start the AP saved in flash\n"); - return true; - } - - struct softap_config config; - - bzero(&config, sizeof(struct softap_config)); - - sprintf((char*)config.ssid, ssid); - - if (pass) { - sprintf((char*)config.password, pass); - } - - return wifi_softap_set_config(&config); -} - -bool stop_wifi_ap(void) -{ - WIFI_MODE mode = wifi_get_opmode(); - mode &= ~SOFTAP_MODE; - - if (!wifi_set_mode(mode)) { - printf("Failed to disable AP mode!\n"); - return false; - } - - return true; -} - -bool wifi_station_connected(void) -{ - if (!wifi_station_is_connected) { - return false; - } - - WIFI_MODE mode = wifi_get_opmode(); - - if ((mode & STATION_MODE) == 0) { - return false; - } - - STATION_STATUS wifistate = wifi_station_get_connect_status(); - wifi_station_is_connected = (wifistate == STATION_GOT_IP || (wifi_station_static_ip && wifistate == STATION_CONNECTING)); - return wifi_station_is_connected; -} - -bool wifi_ap_enabled(void) -{ - return !!(wifi_get_opmode() & SOFTAP_MODE); -} - -static os_timer_t timer; - -static void wait_for_connection_ready(uint8_t flag) -{ - os_timer_disarm(&timer); - - if (wifi_station_connected()) { - printf("connected\n"); - } else { - printf("reconnect after 2s\n"); - os_timer_setfn(&timer, (os_timer_func_t*)wait_for_connection_ready, NULL); - os_timer_arm(&timer, 2000, 0); - } -} - -static void on_wifi_connect(void) -{ - os_timer_disarm(&timer); - os_timer_setfn(&timer, (os_timer_func_t*)wait_for_connection_ready, NULL); - os_timer_arm(&timer, 100, 0); -} - -static void on_wifi_disconnect(uint8_t reason) -{ - printf("disconnect %d\n", reason); -} - -/****************************************************************************** - * FunctionName : user_init - * Description : entry of user application, init user function here - * Parameters : none - * Returns : none -*******************************************************************************/ -void user_init(void) -{ - printf("SDK version:%s\n", esp_get_idf_version()); - - set_on_station_connect(on_wifi_connect); - set_on_station_disconnect(on_wifi_disconnect); - init_esp_wifi(); - stop_wifi_ap(); - start_wifi_station(SSID, PASSWORD); -} diff --git a/examples/wifi/wifi_station_machine/main/wifi_state_machine.h b/examples/wifi/wifi_station_machine/main/wifi_state_machine.h deleted file mode 100644 index d8195463..00000000 --- a/examples/wifi/wifi_station_machine/main/wifi_state_machine.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - This example code is in the Public Domain (or CC0 licensed, at your option.) - - Unless required by applicable law or agreed to in writing, this - software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - CONDITIONS OF ANY KIND, either express or implied. -*/ - -#ifndef _WIFI_STATE_MACHINE_H_ -#define _WIFI_STATE_MACHINE_H_ - -#include - -#include "esp_wifi.h" - -typedef void (* wifi_state_cb_t)(); -typedef void (* wifi_disco_cb_t)(uint8_t reason); - -void set_on_station_first_connect(wifi_state_cb_t cb); -void set_on_station_connect(wifi_state_cb_t cb); -void set_on_station_disconnect(wifi_disco_cb_t cb); -void set_on_client_connect(wifi_state_cb_t cb); -void set_on_client_disconnect(wifi_state_cb_t cb); - -WIFI_MODE init_esp_wifi(); -bool start_wifi_station(const char * ssid, const char * pass); -bool stop_wifi_station(); -bool start_wifi_ap(const char * ssid, const char * pass); -bool stop_wifi_ap(); - -bool wifi_station_connected(); -bool wifi_ap_enabled(); - -#endif /* _WIFI_STATE_MACHINE_H_ */ diff --git a/examples/wifi/wifi_station_machine/readme.txt b/examples/wifi/wifi_station_machine/readme.txt deleted file mode 100644 index 288a84cf..00000000 --- a/examples/wifi/wifi_station_machine/readme.txt +++ /dev/null @@ -1,56 +0,0 @@ -This is a simple project template. - -sample_lib is an example for multi-level folder Makefile, notice the folder structure and each Makefile, you can get the clue. - - -HOWTO: -1. Copy this folder to anywhere. -Example: - Copy to ~/workspace/project_template - You can rename this folder as you like. - -2. Export SDK_PATH and BIN_PATH. -Example: - Your SDK path is ~/esp_iot_rtos_sdk, and want generate bin at ~/esp8266_bin. - Do follow steps: - 1>. export SDK_PATH=~/esp_iot_rtos_sdk - 2>. export BIN_PATH=~/esp8266_bin - SDK and project are seperate, you can update SDK without change your project. - -3. Enter project_template folder, run ./gen_misc.sh, and follow the tips and steps. - - -Compile Options: -(1) COMPILE - Possible value: xcc - Default value: - If not set, use gcc by default. - -(2) BOOT - Possible value: none/old/new - none: no need boot - old: use boot_v1.1 - new: use boot_v1.2 - Default value: new - -(3) APP - Possible value: 0/1/2 - 0: original mode, generate eagle.app.v6.flash.bin and eagle.app.v6.irom0text.bin - 1: generate user1 - 2: generate user2 - Default value: 0 - -(3) SPI_SPEED - Possible value: 20/26.7/40/80 - Default value: 40 - -(4) SPI_MODE - Possible value: QIO/QOUT/DIO/DOUT - Default value: QIO - -(4) SPI_SIZE_MAP - Possible value: 0/2/3/4/5/6 - Default value: 0 - -For example: - make COMPILE=gcc BOOT=new APP=1 SPI_SPEED=40 SPI_MODE=QIO SPI_SIZE_MAP=0