ESP32

ESP32, Bluetooth, Wi-Fi, blufi

CoyoteUgly 2018. 8. 21. 13:23

ESP32, Bluetooth, Wi-Fi, blufi


안드로이드 기기가 꼭 필요함

테스트 앱이 안드로이드용만 있음


EPS32 부팅 후 ibeacon(?) 같은 신호를 브로드캐스팅하면
안드로이드 EspBlufi 앱에서 이를 수신하면 EPS32 리스트가 보여집니다.
그 중에서 해당 보드를 선택한 다음 wifi ssid, passwd를 입력합니다.


앱의 Bluetooth를 통해 wifi ssid, passwd를 해당 보드로 넘겨주게 되면
해당 보드는 이 정보를 통해 wifi 설정을 하고
BT를 종료하는 것으로 확인됩니다.




esp/esp-idf/components/bt/bluedroid/api/include/api/esp_gap_ble_api.h


0. 참고 사이트


1. 모듈


2. 보드 연결


3. 소스 설명

해당 example를 동작하기 위해 wifi 관련하여 소스 수정을 하였습니다.
initialise_wifi 함수가 timeout를 가지고 있기 때문에
Bluetooth 연결이 확인된 다음에
wifi 초기화 함수를 실행시키는 방향으로 수정하였습니다.

static void example_event_callback(esp_blufi_cb_event_t event, esp_blufi_cb_param_t *param)
{
    case ESP_BLUFI_EVENT_BLE_CONNECT:
        BLUFI_INFO("BLUFI ble connect\n");
        server_if = param->connect.server_if;
        conn_id = param->connect.conn_id;
        esp_ble_gap_stop_advertising();
        blufi_security_init();

        initialise_wifi();   // 추가함 
        break;


void app_main()
{
    esp_err_t ret;


    //initialise_wifi();   // 주석 처리함 

    ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT)); 


4. 소스

https://github.com/sglee0223/esp32/tree/master/blufi


5. 결과 확인

ESP32, 안드로이드 기기가 Bluetooth로 통신하면
안드로이드 기기에 디바이스 목록이 보여집니다.

안드로이드 기기에서 wifi ssid, passwd를 입력하면
Bluetooth를 통해 ESP32에게 해당 정보를 전달하게 되며
ESP32는 wifi 연결을 확인하고 Bluetooth를 종료합니다.

I (0) cpu_start: App cpu up.
I (451) heap_init: Initializing. RAM available for dynamic allocation:
I (458) heap_init: At 3FFAFF10 len 000000F0 (0 KiB): DRAM
I (464) heap_init: At 3FFCF160 len 00010EA0 (67 KiB): DRAM
I (470) heap_init: At 3FFE0440 len 00003BC0 (14 KiB): D/IRAM
I (477) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (483) heap_init: At 40095A00 len 0000A600 (41 KiB): IRAM
I (489) cpu_start: Pro cpu start user code
I (172) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
I (255) BTDM_INIT: BT controller compile version [a9156c1]

I (255) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
I (315) phy: phy_version: 3960, 5211945, Jul 18 2018, 10:40:07, 0, 0
I (575) BLUFI_EXAMPLE: BD ADDR: 30:ae:a4:15:20:9e

I (575) BLUFI_EXAMPLE: BLUFI VERSION 0102

I (585) BLUFI_EXAMPLE: example_event_callback [event: 0x0]
I (585) BLUFI_EXAMPLE: BLUFI init finish

I (595) BLUFI_EXAMPLE: example_gap_event_handler [event: 0x0]
I (595) BLUFI_EXAMPLE: Ble Adv Data Set Complete
I (605) BLUFI_EXAMPLE: example_gap_event_handler [event: 0x6]
I (605) BLUFI_EXAMPLE: Ble Adv Start Complete
I (316655) BLUFI_EXAMPLE: example_event_callback [event: 0x3]
I (316655) BLUFI_EXAMPLE: BLUFI ble connect

I (316655) wifi: wifi driver task: 3ffd6ac0, prio:23, stack:3584, core=0
I (316665) wifi: wifi firmware version: 633012a
I (316665) wifi: config NVS flash: enabled
I (316675) wifi: config nano formating: disabled
I (316675) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
I (316685) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
I (316715) wifi: Init dynamic tx buffer num: 32
I (316715) wifi: Init data frame dynamic rx buffer num: 32
I (316715) wifi: Init management frame dynamic rx buffer num: 32
I (316725) wifi: Init static rx buffer size: 1600
I (316725) wifi: Init static rx buffer num: 10
I (316725) wifi: Init dynamic rx buffer num: 32
I (316745) wifi: mode : sta (30:ae:a4:15:20:9c)
I (316745) BLUFI_EXAMPLE: example_net_event_handler [event: 0x2]
I (316745) BLUFI_EXAMPLE: Wifi Start
I (316755) BLUFI_EXAMPLE: example_gap_event_handler [event: 0x11]
I (316755) BLUFI_EXAMPLE: Ble Adv Stop Complete
I (317295) BLUFI_EXAMPLE: example_gap_event_handler [event: 0x14]
I (317295) BLUFI_EXAMPLE: Ble Update Conn Params
I (317535) BLUFI_EXAMPLE: example_gap_event_handler [event: 0x14]
I (317545) BLUFI_EXAMPLE: Ble Update Conn Params
I (318845) BLUFI_EXAMPLE: example_gap_event_handler [event: 0x14]
I (318845) BLUFI_EXAMPLE: Ble Update Conn Params
I (318965) BLUFI_EXAMPLE: example_event_callback [event: 0x7]
I (318965) BLUFI_EXAMPLE: BLUFI get wifi status from AP

I (319005) BLUFI_EXAMPLE: example_event_callback [event: 0x2]
I (319005) BLUFI_EXAMPLE: BLUFI Set WIFI opmode 1

I (319175) BLUFI_EXAMPLE: example_event_callback [event: 0xa]
I (319175) BLUFI_EXAMPLE: Recv STA SSID iptime

I (319175) BLUFI_EXAMPLE: example_net_event_handler [event: 0x5]
I (319175) BLUFI_EXAMPLE: Wifi Disconnected
I (319235) BLUFI_EXAMPLE: example_event_callback [event: 0xb]
I (319235) BLUFI_EXAMPLE: Recv STA PASSWORD 11111111

I (319275) BLUFI_EXAMPLE: example_event_callback [event: 0x5]
I (319275) BLUFI_EXAMPLE: BLUFI requset wifi connect to AP

I (319405) wifi: n:1 0, o:1 0, ap:255 255, sta:1 0, prof:1
I (320395) wifi: state: init -> auth (b0)
I (320405) wifi: state: auth -> assoc (0)
I (320405) wifi: state: assoc -> run (10)
I (321325) wifi: connected with iptime, channel 1
I (321325) wifi: pm start, type: 1

I (321325) BLUFI_EXAMPLE: example_net_event_handler [event: 0x4]
I (321325) BLUFI_EXAMPLE: Wifi Connected
I (322155) event: sta ip: 192.168.0.9, mask: 255.255.255.0, gw: 192.168.0.1
I (322155) BLUFI_EXAMPLE: example_net_event_handler [event: 0x7]
I (322155) BLUFI_EXAMPLE: Wifi Got IP
I (322245) BLUFI_EXAMPLE: example_event_callback [event: 0x17]
I (322245) BLUFI_EXAMPLE: blufi close a gatt connection
I (322255) BLUFI_EXAMPLE: example_event_callback [event: 0x4]
I (322255) BLUFI_EXAMPLE: BLUFI ble disconnect

I (322265) BLUFI_EXAMPLE: example_gap_event_handler [event: 0x6]
I (322265) BLUFI_EXAMPLE: Ble Adv Start Complete

 












'ESP32' 카테고리의 다른 글

ESP32, Bluetooth, ble_spp_server, ble_spp_client  (0) 2018.08.21
ESP32, Wi-Fi, smart_config  (0) 2018.08.21
ESP32, Wi-Fi, http2_request  (0) 2018.08.21
ESP32, UART, uart channel (0~2)  (0) 2018.08.20
EPS32, monitor option  (0) 2018.08.20