ESP32 Bluetooth classic. Callback. ESP32 CAM

3.- Application sends three numbers, receives double of each.

p62D_esp32_bluetooth_3.aia (3.4 KB)

#include "BluetoothSerial.h"

BluetoothSerial SerialBT;

void setup() {
  Serial.begin(115200);
  initBT();
}

void initBT(){
  if(!SerialBT.begin("ESP32CAM-CLASSIC-BT")){
    Serial.println("An error occurred initializing Bluetooth");
    ESP.restart();
  }else{
    Serial.println("Bluetooth initialized");
  }

  SerialBT.register_callback(btCallback);
  Serial.println("The device started, now you can pair it with bluetooth");
}

void btCallback(esp_spp_cb_event_t event, esp_spp_cb_param_t *param){
  if(event == ESP_SPP_SRV_OPEN_EVT){
    Serial.println("Client Connected!");
  }else if(event == ESP_SPP_DATA_IND_EVT){
        while(SerialBT.available())
             {
              String a =  SerialBT.readStringUntil(',');
              String b =  SerialBT.readStringUntil(',');
              String c =  SerialBT.readStringUntil('\n');
              String retorno = (String)(2 * a.toInt()) +","+ (String)(2 * b.toInt()) +","+ (String)(2 * c.toInt());
              SerialBT.println(retorno);
            } 
    }
}

void loop() { }
1 Like