modify static variables and README file
This commit is contained in:
parent
1806a69abf
commit
98cf74d1b7
|
@ -1,17 +1,40 @@
|
||||||
# smartconfig Example
|
# 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.
|
||||||
|
|
||||||
|
### 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:
|
||||||
|
|
||||||
|
```
|
||||||
|
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.
|
* Open ESPTOUCH app and input password. There will be success message after few sec.
|
||||||
|
|
||||||
### Example output
|
|
||||||
|
|
||||||
Here is an example of smartconfig console output.
|
Here is an example of smartconfig console output.
|
||||||
```
|
```
|
||||||
I (372) wifi: mode : sta (24:0a:c4:00:44:86)
|
I (372) wifi: mode : sta (24:0a:c4:00:44:86)
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
#include "esp_smartconfig.h"
|
#include "esp_smartconfig.h"
|
||||||
|
|
||||||
/* FreeRTOS event group to signal when we are connected & ready to make a request */
|
/* 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,
|
/* The event group allows multiple bits for each event,
|
||||||
but we only care about one event - are we connected
|
but we only care about one event - are we connected
|
||||||
|
@ -40,11 +40,11 @@ static esp_err_t event_handler(void *ctx, system_event_t *event)
|
||||||
xTaskCreate(smartconfig_example_task, "smartconfig_example_task", 4096, NULL, 3, NULL);
|
xTaskCreate(smartconfig_example_task, "smartconfig_example_task", 4096, NULL, 3, NULL);
|
||||||
break;
|
break;
|
||||||
case SYSTEM_EVENT_STA_GOT_IP:
|
case SYSTEM_EVENT_STA_GOT_IP:
|
||||||
xEventGroupSetBits(wifi_event_group, CONNECTED_BIT);
|
xEventGroupSetBits(s_wifi_event_group, CONNECTED_BIT);
|
||||||
break;
|
break;
|
||||||
case SYSTEM_EVENT_STA_DISCONNECTED:
|
case SYSTEM_EVENT_STA_DISCONNECTED:
|
||||||
esp_wifi_connect();
|
esp_wifi_connect();
|
||||||
xEventGroupClearBits(wifi_event_group, CONNECTED_BIT);
|
xEventGroupClearBits(s_wifi_event_group, CONNECTED_BIT);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -55,7 +55,7 @@ static esp_err_t event_handler(void *ctx, system_event_t *event)
|
||||||
static void initialise_wifi(void)
|
static void initialise_wifi(void)
|
||||||
{
|
{
|
||||||
tcpip_adapter_init();
|
tcpip_adapter_init();
|
||||||
wifi_event_group = xEventGroupCreate();
|
s_wifi_event_group = xEventGroupCreate();
|
||||||
ESP_ERROR_CHECK( esp_event_loop_init(event_handler, NULL) );
|
ESP_ERROR_CHECK( esp_event_loop_init(event_handler, NULL) );
|
||||||
|
|
||||||
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||||
|
@ -93,7 +93,7 @@ static void sc_callback(smartconfig_status_t status, void *pdata)
|
||||||
memcpy(phone_ip, (uint8_t* )pdata, 4);
|
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]);
|
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;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -106,7 +106,7 @@ void smartconfig_example_task(void * parm)
|
||||||
ESP_ERROR_CHECK( esp_smartconfig_set_type(SC_TYPE_ESPTOUCH) );
|
ESP_ERROR_CHECK( esp_smartconfig_set_type(SC_TYPE_ESPTOUCH) );
|
||||||
ESP_ERROR_CHECK( esp_smartconfig_start(sc_callback) );
|
ESP_ERROR_CHECK( esp_smartconfig_start(sc_callback) );
|
||||||
while (1) {
|
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) {
|
if(uxBits & CONNECTED_BIT) {
|
||||||
ESP_LOGI(TAG, "WiFi Connected to ap");
|
ESP_LOGI(TAG, "WiFi Connected to ap");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue