Espressif ESP32 Manuel utilisateur

ESP32 Bluetooth Networking
User Guide
Version 1.1
Espressif Systems
Copyright © 2019

About This Guide
This document provides a guide to using ESP32 in Bluetooth networking for IoT devices
with examples.
Release Note
Documentation Change Notification
Espressif provides email notifications to keep customers updated on changes to
technical documentation. Please subscribe at https://www.espressif.com/en/subscribe.
Certification
Download certificates for Espressif products from https://www.espressif.com/en/
certificates.!
Date
Version
Release notes
2017.03
V1.0
First release.
2019.05
V1.1
Update figures.

Content
1. Introduction!1".............................................................................................................................
1.1. Overview!1"....................................................................................................................................
1.2. EspBlufi!1"......................................................................................................................................
2. APIs for Networking Development!3".........................................................................................
2.1. BluFi Protocol!3".............................................................................................................................
2.2. APIs on ESP32 End!3"....................................................................................................................
2.3. APIs on the EspBlufi APK End!4"...................................................................................................
3. ESP32 Bluetooth Networking Examples!5"................................................................................
3.1. Hardware and Software Preparation!5"..........................................................................................
3.2. Setting ESP32 to Station Mode!5".................................................................................................
3.3. Setting ESP32 as a SoftAP!9........................................................................................................

!
1. Introduction
1. Introduction
1.1. Overview
The ESP32, as a single 2.4 GHz Wi-Fi and Bluetooth combo chip, supports Wi-Fi setups
via both SmartConfig and Bluetooth. Users can use ESP32 for secure configuration of Wi-
Fi networking for IoT devices.
Using Bluetooth for configuring Wi-Fi network presents the following advantages:
•The Bluetooth protocol is open and scalable.
•By using Bluetooth protocol, users can easily discover nearby devices via Bluetooth
beacons.
•The Bluetooth protocol is secure, because the authentication of the device is done
over a secure Bluetooth connection before the password is sent to the device.
•Users can also transmit data over Bluetooth to a smartphone, even when the router
is not working. The phone can then uploads the data to the Internet.
•The phone can now also connect to the Bluetooth device and send commands
directly to control the device if the Wi-Fi network is down.
1.2. EspBlufi
ESP32 is compliant with Bluetooth v4.2 BR/EDR and BLE specifications. Espressif has
developed the app EspBlufi specifically for Bluetooth networking of IoT devices. The app is
supported on Android 4.3 and above. For smartphones of Android 6.0 or above, because
of Google’s modification to the Android API, users must give their permission for access to
their current location and enable the location information module to start the Bluetooth
scanning.
•EspBlufi can be downloaded via: https://github.com/EspressifApp/EspRelease/tree/
master/EspBlufi
•Open EspBlufi after downloading it. In the user interface as shown in Figure 1-1, click on
the !icon in the upper right corner.
!
Figure 1-1. EspBlufi User Interface
Espressif
!/!1 13
2019.05

!
1. Introduction
•The Configure button will be shown in the interface and click this button.
!
Figure 1-2. CONFIGURE Button
•Configure the length of BLE mtu, BLE device filtering, and check the version of the app
and Blufi repository.
!
Figure 1-3. CONFIGURE Interface!
Espressif
!/!2 13
2019.05

!
2. APIs for Networking Development
2. APIs for Networking
Development
2.1. BluFi Protocol
Protocol documentation: https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/
blufi.html
2.2. APIs on ESP32 End
In the program of ESP32, security-related processes such as key establishment are
determined and developed by the users. The app sends the “negotiate data” to ESP32 and
the data packets will be sent to the application layer. If the data is not handled by the
application layer, DH algorithm provided by BluFi can be used to exchange the key. The
application layer needs to register relevant callback functions to BluFi. Table 2-1 provides
description of those functions.
Table 2-1. Security-Related Functions
Function
Description
typedef void
(*esp_blufi_negotiate_data_handler_t)
(uint8_t *data, int len, uint8_t
**output_data, int *output_len, bool
*need_free);
•This function is used to receive the “negotiate
data” during key exchange. The data to be sent
should be output by passing the parameters
output_data and output_len to BluFi.
•After BluFi calls negotiate_data_handler,
output_data output by
negotiate_data_handler is sent.
•Since the length of data to be sent is not definite,
**output_data has to malloc a part of
memory or use global variables to release memory
via need_free.
typedef int (*
esp_blufi_encrypt_func_t)(uint8_t iv8,
uint8_t *crypt_data, int cyprt_len);
The length of the encoded and decoded data must
be the same. iv8 in this function means the 8-bit
sequence of the packets. It can be used for eight bits
of the initialization vector.
typedef int (*
esp_blufi_decrypt_func_t)(uint8_t iv8,
uint8_t *crypt_data, int crypt_len);
The length of the encoded and decoded data must
be the same. iv8 in this function means the 8-bit
sequence of the packets. It can be used for eight bits
of the initialization vector.
typedef uint16_t
(*esp_blufi_checksum_func_t)(uint8_t
iv8, uint8_t *data, int len);
The function is used to calculate the checksum.
Calling this function returns the value of checksum.
The returned value will be compared with the
checksum at the end of the packet by BluFi.
Espressif
!/!3 13
2019.05

!
2. APIs for Networking Development
2.3. APIs on the EspBlufi APK End
• Source code of EspBlufi for Android: https://github.com/EspressifApp/
EspBlufiForAndroid
• Documentation of EspBlufi for Android: https://github.com/EspressifApp/
EspBlufiForAndroid/blob/master/doc/
Introduction_to_the_EspBlufi_API_Interface_for_Android__cn.md
• Source code of EspBlufi for iOS: https://github.com/EspressifApp/EspBlufiForiOS
• Documentation of EspBlufi for iOS: https://github.com/EspressifApp/EspBlufiForiOS/
blob/master/doc/Blufi_APP_API_for_iOS_CN.md
Espressif
!/!4 13
2019.05

!
3. ESP32 Bluetooth Networking Examples
3. ESP32 Bluetooth Networking
Examples
3.1. Hardware and Software Preparation
•1 ×ESP32 module
•1 ×PC, connected to the module to supply power and print log for ESP32.
•1 ×smartphone (Android 4.3 or above)
•Download and install EspBlufi on the smartphone. Turn on the Wi-Fi and Bluetooth
capabilities on the phone. The link for downloading EspBlufi is!
https://github.com/EspressifApp/EspRelease/tree/master/EspBlufi
3.2. Setting ESP32 to Station Mode
1. Power on the module. The following log will be output to the serial port tool:
!
2. Open the EspBlufi app, and refresh the interface by swiping down from the top of the
screen. The nearby Bluetooth-enabled devices will be shown on the screen.
!
Figure 3-1. EspBlufi Interface
Espressif
!/!5 13
2019.05

!
3. ESP32 Bluetooth Networking Examples
3. Click on the ESP32 device in the interface as Figure 3-1 shows, and click Connect
button !to establish Bluetooth connection to it. Successful connection will yield the
interface shown in Figure 3-2.
!
Figure 3-2. Interface Showing Successful Connection
Meanwhile, the following log will be output to the serial port tool:
!
4. Click on the Networking button !to configure the network, get the dropdown menu
for network configuration, as Figure 3-3 shows:
📖Note:
If the Networking button is not shown or can not be clicked in the interface of Figure 3-2, it means that
Bluetooth connection has failed.
Espressif
!/!6 13
2019.05

!
3. ESP32 Bluetooth Networking Examples
!
Figure 3-3. Network Configuration Interface
5. Select the device mode from the dropdown menu, as Figure 3-4 shows. (BluFi
networking supports the following three modes: Station, SoftAP, and Station+SoftAP.)
!
Figure 3-4. Selecting Device Mode
Espressif
!/!7 13
2019.05
Autres manuels pour ESP32
3
Table des matières
Manuels Électricité industrielle populaires d'autres marques

Murata
Murata GJM0335C1E4R4BB01 Series Manuel utilisateur

Stahl
Stahl 8575/12 Manuel utilisateur

SI
SI Pegasus Manuel utilisateur

Murata
Murata GRM1555C1H2R7CA01 Seies Manuel utilisateur

Murata
Murata GRM0225C1E6R4BA03 Series Manuel utilisateur

Cooper Power Systems
Cooper Power Systems VXE15 Manuel utilisateur

S&C
S&C Vista SD Manuel utilisateur

Murata
Murata GRM0335C2A7R3CA01 Series Manuel utilisateur

Siemens
Siemens 3VA9988-0BM10 Manuel utilisateur

Siemens
Siemens SITRANS LVS100 Manuel utilisateur

Murata
Murata GRM32ER60G227ME05 Series Manuel utilisateur

Siemens
Siemens SENTRON SUPERSWITCH 3KL82 Series Manuel utilisateur





