Skip to content

SerialBT.end() Crashes sketch. #4919

Closed
Closed
@dabonetn

Description

@dabonetn

Hardware:

Board: ESP32 Devkit1
Core Installation version: 1.0.5
IDE name: Arduino
Flash Frequency: 40Mhz or 80Mhz, doesn't matter
PSRAM enabled: no
Upload Speed: 921600
Computer OS: Windows 10

Description:

Trying to stop a SerialBT.begin command with SerialBT.end(); crashes the sketch. It just stops with no more output.
Example sketch uses the boot button to send the SerialBT.end() command.

Sketch: (leave the backquotes for code formatting)

//Change the code below by your sketch
//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

#include "BluetoothSerial.h"

#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif
const int buttonPin = 0; 
int buttonState = 0;  
BluetoothSerial SerialBT;

void setup() {
  Serial.begin(115200);
  SerialBT.begin("ESP32test"); //Bluetooth device name
  Serial.println("The device started, now you can pair it with bluetooth!");
}



void loop() {

  buttonState = digitalRead(buttonPin);
  if (buttonState == 0) {
    Serial.println("Button Pressed sending SerialBT.end");
    SerialBT.end();
    Serial.println("SerialBT.end Worked!");
    delay (1000);
   }
  if (Serial.available()) {
    SerialBT.write(Serial.read());
  }
  if (SerialBT.available()) {
    Serial.write(SerialBT.read());
  }
  delay(20);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions