Continuar a discussão de Esp32 wemos d1r32 bluetooth:
@Brazilino gostaria de aproveitar esse tópico ou criar outro se achar mais adequado, pois estou enfrentando uma dificuldade que lembra muito a descrita neste tópico. Tenho um ESP32 DEV Kit v1 e consegui parear com um leitor de códigos de barras bluetooth. Porém não consigo obter as leituras no monitor serial. Sou novato neste mundo e busco ajuda para uma solução. Agradeceria muito se pudesse fazer suas considerações.
Segue o código que estou usando.
#include "BluetoothSerial.h"
// 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;
String MACadd = "e4:86:50:39:9b:fd"; // This only for printing
uint8_t address[6] = {0xe4, 0x86, 0x50, 0x39, 0x9b, 0xfd}; // Change this to reflect real MAC address of your slave BT device e4:86:50:39:9b:fd
String myName = "ESP32-BT-Master";
void setup() {
bool connected;
Serial.begin(9600);
SerialBT.begin(myName, true);
SerialBT.deleteAllBondedDevices(); // Uncomment this to delete paired devices; Must be called after begin
Serial.printf("The device \"%s\" started in master mode, make sure slave BT device is on!\n", myName.c_str());
connected = SerialBT.connect(address);
Serial.print("Connecting to slave BT device with MAC ");
Serial.println(MACadd);
if (connected) {
Serial.println("Connected Successfully!");
} else {
while (!SerialBT.connected(10000)) {
Serial.println("Failed to connect. Make sure remote device is available and in range, then restart app.");
}
}
//SerialBT.connect();
}
void loop() {
// Check for incoming data from both Serial and Bluetooth without delay
if (Serial.available()<0) {
char incoming = Serial.read();
// You can add logic here to process the data before sending it over Bluetooth
SerialBT.write(incoming);
}
if (SerialBT.available()<0) {
char incoming = SerialBT.read();
// You can add logic here to decode or process the data before printing it to the serial monitor
Serial.write(incoming);
}
}