Advertisement
mikroavr

bluetooth_esp32

Nov 3rd, 2020
1,021
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "BluetoothSerial.h"
  2.  
  3. #if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
  4. #error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
  5. #endif
  6.  
  7. BluetoothSerial SerialBT;
  8.  
  9. char chr_bt[10];
  10. int c_bt;
  11. String str_bt, buf_str_bt;
  12. unsigned long cur_time, old_time;
  13.  
  14. void setup() {
  15.   // put your setup code here, to run once:
  16.   Serial.begin(115200);
  17.   SerialBT.begin("ESP32test"); //Bluetooth device name
  18.   Serial.println("The device started, now you can pair it with bluetooth!");
  19. }
  20.  
  21. void loop() {
  22.   // put your main code here, to run repeatedly:
  23.   while(SerialBT.available()){
  24.     chr_bt[c_bt] = SerialBT.read();
  25.     c_bt++;
  26.   }
  27.   cur_time = millis();
  28.   if(cur_time - old_time >= 1000){
  29.     for(int i=0; i<c_bt - 2; i++){
  30.       str_bt += String(chr_bt[i]);
  31.     }
  32.     if(str_bt == "rst"){
  33.       Serial.println("EEPROM ERASE");
  34.     }
  35.     str_bt = "";c_bt = 0;
  36.     old_time = cur_time;
  37.   }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement