1

Topic: ESP32 - Delay when disconnected

Hello everyone, I'm noob so forgive me if I ask a stupid question!
I'm making my first project with Esp32 and RemoteXY via Bluetooth.

I use ESP32 board with an H bridge to control two DC Motors.

I use RemoteXY.connect_flag for making DC motors stop when ESP32 lost Bluetooth connection,but if I disconnect bluetooth from my phone it takes 8-10 seconds for dc motors to stop.

How can I solve this problem?
thank you very much for your attention!

2 (edited by Gunner 2021-06-03 03:12:28)

Re: ESP32 - Delay when disconnected

santo.minniti wrote:

I use RemoteXY.connect_flag for making DC motors stop when ESP32 lost Bluetooth connection

What is the code you used for this method?  I personally couldn't get any response from that flag... or perhaps I didn't wait long enough?

Instead, I used this in my void loop()…  Which gives me the required failsafe stop (and visual disconnection notice) for my rover within a few seconds.

// Connection Failsafe
  if (RemoteXY_isConnected() == 0) {
    RemoteXY.joystick_1_x = 0; // Set for dead stop
    RemoteXY.joystick_1_y = 0; // Set for dead stop
    // Flash headlamp LED when App not connected.
    digitalWrite(PIN_LED, !digitalRead(PIN_LED));
    delay(500);
  }

Also,  I use WiFi in my rover, which I believe is just quicker at responding to feedback than Serial, which being slower needs more leeway in it's timeout settings else it may never stay stably connected.  Perhaps try switching to WiFi and see if it is quicker for you as well.

Otherwise, I suppose you could try some changes to the RemoteXYComm_AT.h library (I think that would be applicable for BT/BLE), which does have a few timeout settings in what looks like millisecond ranges.

NOTE: I have no idea if this would be the proper way to accomplish your goal, but experimenting is half the fun.... make backups wink

#define REMOTEXYCOMM_AT__COMMAND_TIMEOUT 1000
#define REMOTEXYCOMM_AT__SEND_TIMEOUT 5000
#define REMOTEXYCOMM_AT__TEST_TIMEOUT 30000
#define REMOTEXYCOMM_AT__CONNECT_TIMEOUT 20000
"And voila, which is French for.......'and then I found out.'" - Ready Player One