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);
- }