esp-idf/examples/bluetooth/bluedroid/classic_bt/bt_spp_initiator
weitianhua c347b0a937 Update bt_discovery demo and README
1. Use bt_app_gap_init function
2. Add Security Simple Pair doc
3. Update README

Update SPP demo

1. Add input module for bt_spp_initiator demo to show the security simple pair features
2. Update README of bt_spp_acceptor and bt_spp_initiator demo.

Format comment in esp_a2dp_api.h

Format comment in esp_avrc_api.h

Format comment in esp_spp_api.h

Fix bt_discovery build err

Update HFP API guide error

Remove BTA_AV_DEBUG

Remove Trailing Whitespace & End of Files
2021-01-27 14:17:12 +08:00
..
main Update bt_discovery demo and README 2021-01-27 14:17:12 +08:00
CMakeLists.txt build_app: make multi target support readable 2020-04-09 16:40:57 +08:00
Makefile Bluetooth examples restructuring 2019-07-01 19:21:57 +08:00
README.md Update bt_discovery demo and README 2021-01-27 14:17:12 +08:00
sdkconfig.defaults examples: fix sdkconfig warnings 2019-11-21 15:36:06 +01:00

Supported Targets ESP32

ESP-IDF BT-SPP-INITATOR demo

This is the demo for user to use ESP_APIs to create a Serial Port Protocol (SPP) initiator and we aggregate Secure Simple Pair (SSP) into this demo to show how to use SPP when creating your own APPs.

How to use example

Hardware Required

This example is designed to run on commonly available ESP32 development board, e.g. ESP32-DevKitC. To operate it should be connected to an SPP Acceptor running on another device.

Configure the project

idf.py menuconfig

In menuconfig path: Coponent config --> Bluetooth--> Bluedroid Options -->SPP and Coponent config --> Bluetooth--> Bluedroid Options -->Secure Simple Pair.

Build and Flash

Build the project and flash it to the board, then run monitor tool to view serial output:

idf.py -p PORT flash monitor

(Replace PORT with the name of the serial port to use.)

(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

When you run this example and the IO capability is ESP_IO_CAP_IO or ESP_IO_CAP_IN , the commands help table prints the following at the very beginning:

########################################################################
Supported commands are as follows, arguments are embraced with < and >
spp h;                -- show command manual

Use this cmmand table if the IO Capability of local device set as IO_CAP_IO.
spp ok;               -- manual Numeric Confirmation.

Use this cmmand table if the IO Capability of local device set as IO_CAP_IN.
spp key <auth key>;   -- manual Passkey. (e.g. spp key 136245;)

########################################################################

Note:

  • Only after SPP service is initialized and a service level connection exists between an Initiator and Acceptor device, could other commands be available.

  • This command help table will print out in monitor whenever you type spp h; or if you input a command that is not required by the command parse rule.

  • Commands should always start with spp and end with ; or the example will not responds.

  • The command you typed will not echo in monitor.

Situation under ESP_IO_CAP_IN

The log in terminal will indicate you to input the passkey to initiate the connection of SPP.

I (2244) SPP_INITIATOR_DEMO: ESP_BT_GAP_DISC_RES_EVT
I (2244) SPP_INITIATOR_DEMO: ...... 
I (2394) SPP_INITIATOR_DEMO: ESP_BT_GAP_DISC_RES_EVT
I (2404) SPP_INITIATOR_DEMO: ......
I (2404) SPP_INITIATOR_DEMO: ESP_SPP_ACCEPTOR
I (2414) SPP_INITIATOR_DEMO: ESP_BT_GAP_DISC_STATE_CHANGED_EVT
I (3274) SPP_INITIATOR_DEMO: ESP_SPP_DISCOVERY_COMP_EVT status=0 scn_num=1
I (3284) SPP_INITIATOR_DEMO: ESP_SPP_CL_INIT_EVT
I (3454) SPP_INITIATOR_DEMO: ESP_BT_GAP_KEY_REQ_EVT Please enter passkey!
W (3454) SPP_INITIATOR_DEMO: To input the key, type `spp key xxxxxx;`

Situation under ESP_IO_CAP_IO

The log in terminal will indicate you to confirm the number to initiate the connection of SPP.

I (2342) SPP_INITIATOR_DEMO: ESP_BT_GAP_DISC_RES_EVT
I (2342) SPP_INITIATOR_DEMO: 30 ae a4 80 18 32 
I (2342) SPP_INITIATOR_DEMO: ESP_SPP_ACCEPTOR
I (2352) SPP_INITIATOR_DEMO: ESP_BT_GAP_DISC_STATE_CHANGED_EVT
I (3212) SPP_INITIATOR_DEMO: ESP_SPP_DISCOVERY_COMP_EVT status=0 scn_num=1
I (3222) SPP_INITIATOR_DEMO: ESP_SPP_CL_INIT_EVT
I (3392) SPP_INITIATOR_DEMO: ESP_BT_GAP_CFM_REQ_EVT Please compare the numeric value: 864115
W (3392) SPP_INITIATOR_DEMO: To confirm the value, type `spp ok;`

Note:

Whether you should passkey or confirm the number also depends on the IO capability of the peer device. And whether the two device are already paired before.

Troubleshouting

  • Set SPP_SHOW_MODE as SPP_SHOW_DATA or SPP_SHOW_SPEED in code (should be same with bt_spp_acceptor).

  • After the program started, It will connect to bt_spp_acceptor and send data.

  • We haven't do the same update to bt_acceptor_demo for the sake of reducing the size of ESP_IDF, but transplanting of input module is supported.

  • We also show the Security Simple Pair in this SPP demo. Users can set the IO Capability and Security Mode for their device (security level is fixed level 4). The default security mode of this demo is ESP_SPP_SEC_AUTHENTICATE which support MITM (Man In The Middle) protection. For more information about Security Simple Pair on ESP32, please refer to ESP32_SSP.

Example Breakdown

To clearly show how the SSP aggregate with the SPP , we use the Commands and Effects scheme to illustrate the process of secure paring and connection establishment.

  • The example will respond to user command through UART console. Please go to console_uart.c for the configuration details.

  • If you want to update the command table, please refer to app_spp_msg_set.c.

  • If you want to update the command parse rules, please refer to app_spp_msg_prs.c.

  • If you want to update the responses of HF Unit or want to update the log, please refer to bt_app_spp.c.

  • Task configuration part is in example_spp_initiator_demo.c.