* Add Config * Add Cache and remove pre-commit action * [pre-commit.ci lite] apply automatic fixes * Remove freeze * Fix * Update action * Use latest stable Python 3 version * Improve caching * Improve cache tag * Improve bot message * fix(typos): Fix typos * fix(typos): Fix more typos * refactor(udp_server): Convert script from Python 2 to 3 * Fix whitespace * Clang-format fixes * Prettier fixes * Black formatting * Manual fixes * Line endings * Fix flake and make Vale manual * Fix flake and reformat --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Co-authored-by: Rodrigo Garcia <rodrigo.garcia@espressif.com>
39 lines
1.3 KiB
C++
39 lines
1.3 KiB
C++
// This example code is in the Public Domain (or CC0 licensed, at your option.)
|
|
// By Evandro Copercini - 2018
|
|
//
|
|
// This example creates a bridge between Serial and Classical Bluetooth (SPP)
|
|
// and also demonstrate that SerialBT have the same functionalities of a normal Serial
|
|
// Note: Pairing is authenticated automatically by this device
|
|
|
|
#include "BluetoothSerial.h"
|
|
|
|
String device_name = "ESP32-BT-Slave";
|
|
|
|
// Check if Bluetooth is available
|
|
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
|
|
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
|
|
#endif
|
|
|
|
// Check Serial Port Profile
|
|
#if !defined(CONFIG_BT_SPP_ENABLED)
|
|
#error Serial Port Profile for Bluetooth is not available or not enabled. It is only available for the ESP32 chip.
|
|
#endif
|
|
|
|
BluetoothSerial SerialBT;
|
|
|
|
void setup() {
|
|
Serial.begin(115200);
|
|
SerialBT.begin(device_name); //Bluetooth device name
|
|
//SerialBT.deleteAllBondedDevices(); // Uncomment this to delete paired devices; Must be called after begin
|
|
Serial.printf("The device with name \"%s\" is started.\nNow you can pair it with Bluetooth!\n", device_name.c_str());
|
|
}
|
|
|
|
void loop() {
|
|
if (Serial.available()) {
|
|
SerialBT.write(Serial.read());
|
|
}
|
|
if (SerialBT.available()) {
|
|
Serial.write(SerialBT.read());
|
|
}
|
|
delay(20);
|
|
}
|