ESP32 bluetooth freezing the board
Posted: Sat Sep 05, 2020 6:40 pm
I have a mobile project with the ESP32 Wroom card that reads a sensor through the serial port and sends the data via Bluetooth so that an Android APP handles the information. The circuit is powered by an external battery. There is a circuit that, once connected, keeps the board on until a button is pressed. When the APP connects to bluetooth, an LED lights up to indicate the connection.
When I go to the street with the sign to take the readings, ESP32 is randomly freezing. The APP loses its connection with the bluetooth, but the indicative LED remains on and the button to turn off does not work anymore, leaving the plate as if it were frozen. To get it working again, I have to disconnect the battery or press the reset button.
The problem is occurring at random, sometimes I use the circuit all day and it doesn't freeze. Sometimes with little use, the circuit freezes.
The source code looks like the following:
Has anyone had a similar problem?
When I go to the street with the sign to take the readings, ESP32 is randomly freezing. The APP loses its connection with the bluetooth, but the indicative LED remains on and the button to turn off does not work anymore, leaving the plate as if it were frozen. To get it working again, I have to disconnect the battery or press the reset button.
The problem is occurring at random, sometimes I use the circuit all day and it doesn't freeze. Sometimes with little use, the circuit freezes.
The source code looks like the following:
- void readData() {
- if (Serial2.available()) {
- SerialBT.write(Serial2.read());
- }
- if (SerialBT.available()) {
- Serial2.write(SerialBT.read());
- }
- }
- void callback(esp_spp_cb_event_t event, esp_spp_cb_param_t* param) {
- if (event == ESP_SPP_SRV_OPEN_EVT) {
- ... turn on LED
- }
- else if (event == ESP_SPP_CLOSE_EVT) {
- ... turn off LED
- }
- }
- void checkbutton() {
- If the button is pressed then
- digitalWrite(PIN, 0); // TURN OFF THE CIRCUIT. THE PIN IS PULLUP TO KEEP THE BOARD ON
- }
- void setup() {
- Serial2.begin(19200);
- SerialBT.begin(DEVICE_ID);
- ...
- SerialBT.register_callback(callback);
- }
- void loop() {
- readData();
- checkbutton();
- delay(1);
- }