forked from nkolban/esp32-snippets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccess-point.c
72 lines (69 loc) · 1.92 KB
/
access-point.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
* Test being an access point. When we run this app, watch the console and look
* for a message of the form:
*
* event: SYSTEM_EVENT_AP_START
*
* This means that we have started being an access point.
*
* Now connect your WiFi client device (phone/PC) and we should see a message:
*
* event: SYSTEM_EVENT_AP_STACONNECTED, mac:7c:dd:90:9e:b5:62, aid:1
*
* This says that we have now connected.
*
*/
#include <esp_event.h>
#include <esp_event_loop.h>
#include <esp_log.h>
#include <esp_system.h>
#include <esp_wifi.h>
#include <freertos/FreeRTOS.h>
#include <nvs_flash.h>
//static char tag[] = "access-point";
/**
* An ESP32 WiFi event handler.
* The types of events that can be received here are:
*
* SYSTEM_EVENT_AP_PROBEREQRECVED
* SYSTEM_EVENT_AP_STACONNECTED
* SYSTEM_EVENT_AP_STADISCONNECTED
* SYSTEM_EVENT_AP_START
* SYSTEM_EVENT_AP_STOP
* SYSTEM_EVENT_SCAN_DONE
* SYSTEM_EVENT_STA_AUTHMODE_CHANGE
* SYSTEM_EVENT_STA_CONNECTED
* SYSTEM_EVENT_STA_DISCONNECTED
* SYSTEM_EVENT_STA_GOT_IP
* SYSTEM_EVENT_STA_START
* SYSTEM_EVENT_STA_STOP
* SYSTEM_EVENT_WIFI_READY
*/
esp_err_t esp32_wifi_eventHandler(void *ctx, system_event_t *event) {
// Your event handling code here...
return ESP_OK;
}
void access_point_task(void *ignore) {
nvs_flash_init();
tcpip_adapter_init();
ESP_ERROR_CHECK( esp_event_loop_init(esp32_wifi_eventHandler, NULL) );
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK( esp_wifi_init(&cfg) );
ESP_ERROR_CHECK( esp_wifi_set_storage(WIFI_STORAGE_RAM) );
ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_AP) );
wifi_config_t apConfig = {
.ap = {
.ssid="ESP32_TESTAP",
.ssid_len=0,
.password="",
.channel=0,
.authmode=WIFI_AUTH_OPEN,
.ssid_hidden=0,
.max_connection=4,
.beacon_interval=100
}
};
ESP_ERROR_CHECK( esp_wifi_set_config(WIFI_IF_AP, &apConfig) );
ESP_ERROR_CHECK( esp_wifi_start() );
vTaskDelete(NULL);
}