]> granicus.if.org Git - esp-idf/commitdiff
wps_ps: Add new options to menuconfig, modify README and some explainations.
authorchenyudong <chenyudong@espressif.com>
Wed, 29 Mar 2017 07:33:05 +0000 (15:33 +0800)
committerchenyudong <chenyudong@espressif.com>
Fri, 31 Mar 2017 08:12:58 +0000 (16:12 +0800)
examples/wifi/power_save/README.md
examples/wifi/power_save/main/Kconfig.projbuild
examples/wifi/power_save/main/power_save.c
examples/wifi/wps/README.md
examples/wifi/wps/main/Kconfig.projbuild [new file with mode: 0644]
examples/wifi/wps/main/wps.c

index 8ff190c846a6dc3ce0a8dfc9047f30b1c51a185b..0f722584a3c9314ac580e7391866c90141b9ac59 100644 (file)
@@ -4,8 +4,8 @@ This example shows how to use power save mode of wifi.
 
 Power save mode only works in sta mode.
 
-* No power save: This is default mode. And the esp32 will work at full speed.
+* No power save: This is default mode. And the esp32 will work with full power.
 
-* modem sleep: If you set power save mode as modem sleep, after connected to AP about 10s, esp32 will wake up and sleep periodically. When it sleeps, the current will be much lower than it works.
+* modem sleep: If you set power save mode as modem sleep, 10s later after connecting to AP, esp32 will wake up and sleep(turn off RF and PHY) periodically.
 
 * others: not supported yet.
index 134f28d7a2ccbb81b26d1c6d77c25902478734ae..96e28d0b99c3873f126c484851bf4e4bf6e087c2 100644 (file)
@@ -1,13 +1,27 @@
 menu "Example Configuration"
-                                                                           config WIFI_SSID
+
+config WIFI_SSID
     string "WiFi SSID"
     default "myssid"
     help
        SSID (network name) for the example to connect to.
+
 config WIFI_PASSWORD
     string "WiFi Password"
     default "mypassword"
     help
        WiFi password (WPA or WPA2) for the example to use.
 
+choice POWER_SAVE_MODE
+    prompt "power save mode"
+    default POWER_SAVE_NONE
+    help
+       Power save mode for the esp32 to use.
+
+config POWER_SAVE_NONE
+    bool "none"
+config POWER_SAVE_MODEM
+    bool "modem"
+endchoice
+
 endmenu
index 837fce3b98c3dc2e19c55e110c5852847c522e4a..8f6139d89caabd1bc4563de3fce36b2457a61212 100644 (file)
@@ -2,7 +2,7 @@
  * this example shows how to use power save mode
  * 
  * set a router or a AP using the same SSID&PASSWORD as configuration of this example.
- * start esp32 and when it connected to AP it will inter power save mode
+ * start esp32 and when it connected to AP it will enter power save mode
  */
 #include "freertos/FreeRTOS.h"
 #include "freertos/event_groups.h"
 /*set the ssid and password via "make menuconfig"*/
 #define DEFAULT_SSID CONFIG_WIFI_SSID
 #define DEFAULT_PWD CONFIG_WIFI_PASSWORD
-/* FreeRTOS event group to signal when we are connected & ready to make a request */
-static EventGroupHandle_t wifi_event_group;
+
+#if CONFIG_POWER_SAVE_MODEM
+#define DEFAULT_PS_MODE WIFI_PS_MODEM
+//#elif CONFIG_POWER_SAVE_NONE
+//#define DEFAULT_PS_MODE WIFI_PS_NONE
+#else
+#define DEFAULT_PS_MODE WIFI_PS_NONE
+#endif
 
 static const char *TAG = "power_save";
 
@@ -25,7 +31,7 @@ static esp_err_t event_handler(void *ctx, system_event_t *event)
     case SYSTEM_EVENT_STA_START:
        ESP_LOGI(TAG, "SYSTEM_EVENT_STA_START");
        ESP_ERROR_CHECK(esp_wifi_connect());
-        break;
+       break;
     case SYSTEM_EVENT_STA_GOT_IP:
        ESP_LOGI(TAG, "SYSTEM_EVENT_STA_GOT_IP");
        ESP_LOGI(TAG, "got ip:%s\n",
@@ -34,18 +40,17 @@ static esp_err_t event_handler(void *ctx, system_event_t *event)
     case SYSTEM_EVENT_STA_DISCONNECTED:
        ESP_LOGI(TAG, "SYSTEM_EVENT_STA_DISCONNECTED");
        ESP_ERROR_CHECK(esp_wifi_connect());
-        break;
+       break;
     default:
         break;
     }
     return ESP_OK;
 }
 
-/*init wifi as sta and set pawer save mode*/
+/*init wifi as sta and set power save mode*/
 static void wifi_power_save(void)
 {
     tcpip_adapter_init();
-    wifi_event_group = xEventGroupCreate();
     ESP_ERROR_CHECK(esp_event_loop_init(event_handler, NULL));
     wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
     ESP_ERROR_CHECK(esp_wifi_init(&cfg));
@@ -58,9 +63,9 @@ static void wifi_power_save(void)
     ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
     ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_config));
     ESP_ERROR_CHECK(esp_wifi_start());
-    
-    ESP_LOGI(TAG, "esp_wifi_set_ps(WIFI_PS_MODEM).");
-    esp_wifi_set_ps(WIFI_PS_MODEM);
+
+    ESP_LOGI(TAG, "esp_wifi_set_ps().");
+    esp_wifi_set_ps(DEFAULT_PS_MODE);
 }
 
 void app_main()
index d2f9e2b64f06eec4080693f348763c51f0d5fc56..dc62dcbc8c264dd428927d0aa910600b32f702c0 100644 (file)
@@ -4,8 +4,8 @@ This example shows how to use wps in esp32.
 
 The wps only works in station mode now.
 
-* PBC_MODE: Start esp32 and push the buttom of wps on router, Then esp32 will get the ssid&password by wps PBC mode.
+* PBC_MODE: Start esp32 and press the wps button on router, Then esp32 will get the ssid&password by wps PBC mode.
 
-* PIN_MODE: Start esp32, It will inter wps mode and you'll see a pin code showing by COM. Enter this pin code in router and the esp32 can get ssid&password by wps PIN mode.
+* PIN_MODE: Start esp32, It will enter wps mode and you'll see a pin code showing by COM. Enter this pin code in router and the esp32 can get ssid&password by wps PIN mode.
 
 More info in the code [wps.c](./main/wps.c).
diff --git a/examples/wifi/wps/main/Kconfig.projbuild b/examples/wifi/wps/main/Kconfig.projbuild
new file mode 100644 (file)
index 0000000..c978d89
--- /dev/null
@@ -0,0 +1,17 @@
+menu "Example Configuration"
+
+choice EXAMPLE_WPS_TYPE
+    prompt "WPS mode"
+    default EXAMPLE_WPS_TYPE_PBC
+    help
+       WPS type for the esp32 to use.
+
+config EXAMPLE_WPS_TYPE_PBC
+    bool "PBC"
+config EXAMPLE_WPS_TYPE_PIN
+    bool "PIN"
+config EXAMPLE_WPS_TYPE_DISABLE
+    bool "disable"
+endchoice
+
+endmenu
index e2a26c523c5e385fdd24a11c4e3a429d877edacf..e68ac04556e7475f1770a786f1f592213ca24207 100644 (file)
@@ -1,6 +1,6 @@
 /* WiFi Connection Example using WPS
  * 
- * WPS_TYPE_PBC: Start esp32 and it will inter wps PBC mode. Then push the buttom of wps on router down. The esp32 will connected to the router.
+ * WPS_TYPE_PBC: Start esp32 and it will enter wps PBC mode. Then push the button of wps on router down. The esp32 will connected to the router.
  *
  * WPS_TYPE_PIN: Start esp32, You'll see PIN code which is a eight-digit number showing on COM. Enter the PIN code in router and then the esp32 will connected to router.
  */
 #include "esp_event_loop.h"
 
 
-/*set wps mode here*/
+/*set wps mode via "make menuconfig"*/
+#if CONFIG_EXAMPLE_WPS_TYPE_PBC
 #define WPS_TEST_MODE WPS_TYPE_PBC
-//#define WPS_TEST_MODE WPS_TYPE_PIN
-//#define WPS_TEST_MODE WPS_TYPE_MAX 
-
+#elif CONFIG_EXAMPLE_WPS_TYPE_PIN
+#define WPS_TEST_MODE WPS_TYPE_PIN
+#else
+#define WPS_TEST_MODE WPS_TYPE_DISABLE
+#endif
 
 #ifndef PIN2STR
 #define PIN2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5], (a)[6], (a)[7]
 #define PINSTR "%c%c%c%c%c%c%c%c"
 #endif
 
-/* FreeRTOS event group to signal when we are connected & ready to make a request */
-static EventGroupHandle_t wifi_event_group;
 
 static const char *TAG = "example_wps";
 
@@ -79,7 +80,6 @@ static esp_err_t event_handler(void *ctx, system_event_t *event)
 static void start_wps(void)
 {
     tcpip_adapter_init();
-    wifi_event_group = xEventGroupCreate();
     ESP_ERROR_CHECK(esp_event_loop_init(event_handler, NULL));
 
     wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();