# smartconfig Example
-This example shows how ESP32 connects to AP with ESPTOUCH. Example does the following steps:
+This example shows how ESP32 connects to a target AP with ESPTOUCH.
-* Download ESPTOUCH APP from app store. [Android source code](https://github.com/EspressifApp/EsptouchForAndroid) and [iOS source code](https://github.com/EspressifApp/EsptouchForIOS) is available.
+## How to use example
-* Compile this example and upload it to an ESP32.
+### Hardware Required
-* Make sure your phone connect to target AP (2.4GHz).
+Download ESPTOUCH APP from app store:
+[Android source code](https://github.com/EspressifApp/EsptouchForAndroid)
+[iOS source code](https://github.com/EspressifApp/EsptouchForIOS) is available.
-* Open ESPTOUCH app and input password. There will be success message after few sec.
+### Configure the project
+
+```
+make menuconfig
+```
+
+* Set serial port under Serial Flasher Options.
+
+### Build and Flash
+
+Build the project and flash it to the board, then run monitor tool to view serial output:
-### Example output
+```
+make -j4 flash monitor
+```
+
+(To exit the serial monitor, type ``Ctrl-]``.)
+
+See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.
+
+## Example output
+
+* Make sure your phone connect to the target AP (2.4GHz).
+* Open ESPTOUCH app and input password. There will be success message after few sec.
Here is an example of smartconfig console output.
```
#include "esp_smartconfig.h"
/* FreeRTOS event group to signal when we are connected & ready to make a request */
-static EventGroupHandle_t wifi_event_group;
+static EventGroupHandle_t s_wifi_event_group;
/* The event group allows multiple bits for each event,
but we only care about one event - are we connected
xTaskCreate(smartconfig_example_task, "smartconfig_example_task", 4096, NULL, 3, NULL);
break;
case SYSTEM_EVENT_STA_GOT_IP:
- xEventGroupSetBits(wifi_event_group, CONNECTED_BIT);
+ xEventGroupSetBits(s_wifi_event_group, CONNECTED_BIT);
break;
case SYSTEM_EVENT_STA_DISCONNECTED:
esp_wifi_connect();
- xEventGroupClearBits(wifi_event_group, CONNECTED_BIT);
+ xEventGroupClearBits(s_wifi_event_group, CONNECTED_BIT);
break;
default:
break;
static void initialise_wifi(void)
{
tcpip_adapter_init();
- wifi_event_group = xEventGroupCreate();
+ s_wifi_event_group = xEventGroupCreate();
ESP_ERROR_CHECK( esp_event_loop_init(event_handler, NULL) );
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
memcpy(phone_ip, (uint8_t* )pdata, 4);
ESP_LOGI(TAG, "Phone ip: %d.%d.%d.%d\n", phone_ip[0], phone_ip[1], phone_ip[2], phone_ip[3]);
}
- xEventGroupSetBits(wifi_event_group, ESPTOUCH_DONE_BIT);
+ xEventGroupSetBits(s_wifi_event_group, ESPTOUCH_DONE_BIT);
break;
default:
break;
ESP_ERROR_CHECK( esp_smartconfig_set_type(SC_TYPE_ESPTOUCH) );
ESP_ERROR_CHECK( esp_smartconfig_start(sc_callback) );
while (1) {
- uxBits = xEventGroupWaitBits(wifi_event_group, CONNECTED_BIT | ESPTOUCH_DONE_BIT, true, false, portMAX_DELAY);
+ uxBits = xEventGroupWaitBits(s_wifi_event_group, CONNECTED_BIT | ESPTOUCH_DONE_BIT, true, false, portMAX_DELAY);
if(uxBits & CONNECTED_BIT) {
ESP_LOGI(TAG, "WiFi Connected to ap");
}