Giter Site home page Giter Site logo

Comments (8)

patfelst avatar patfelst commented on June 24, 2024 1

I'm also finding reconnecting after resetting the ESP32 or uploading a new program is quite unreliable, I have to press the bluetooth pair button on my OBD dongle otherwise the EML327.begin fails. I suspect either I have to close the OBD connection, or close the bluetooth connection before uploading again. I will investigate.

ok I think I solved this in two steps, and am now getting really reliable connections every time I reboot, or upload a program:

  1. I had my iPhone paired with the OBD scanner. On every reboot, the iPhone was jumping in and connecting to the scanner over bluetooth and locking out the ESP32 - oops.

  2. by putting in a 1 second delay between starting the ESP32 bluetooth module and the connecting with the scanner.

So this is my setup() now:

void setup() {
  
  Serial.begin(115200);

  // Start the ESP32's bluetooth classic module and advertise as "Boost"
  Serial.println("Starting ESP32 bluetooth classic module");
  SerialBT.begin("Boost", true);
  delay(1000);
  
  // Try and connect to the OBD scanner over bluetooth
  sprintf(bt_scanner_mac, "%02X:%02X:%02X:%02X:%02X:%02X", address[0], address[1],address[2],address[3],address[4],address[5]);
  Serial.printf("Trying bluetooth connection with OBD scanner %s\n", bt_scanner_mac);
  bool connected = SerialBT.connect(address);
  
  if (!connected) {
    SerialBT.end();
    SerialBT.unpairDevice(address);
    Serial.printf("Couldn't make bluetooth connection with OBD scanner %s. "
            "Disconnected from OBD scanner, and unpaired it.\n", bt_scanner_mac);
  }

  if (!myELM327.begin(SerialBT, '6')) {
    Serial.println("Couldn't start OBD scanner CAN protocol 6");
    while (1);
  }

  Serial.println("Connected to ELM327");
}

Also I'm not sure if it helps, but to end the program, I'm searching for a keypress on the serial monitor, and if I press 'd' it closes the bluetooth connection.

  if(Serial.available()) {
    char c = Serial.read();
    if (c == 'd') {

      // if (myELM327.sendCommand("STPC") == ELM_SUCCESS)
      //   Serial.printf("Closed Protocol %s\n", myELM327.payload);

      Serial.println("Closing bluetooth connection");
      SerialBT.end();
      Serial.println("Halting program ... ");
      while(1);

    }

from elmduino.

patfelst avatar patfelst commented on June 24, 2024 1

2. by putting in a 1 second delay between starting the ESP32 bluetooth module and the connecting with the scanner.

PS With further testing I found 1 second delay is not needed for reliable operation during restart

from elmduino.

PowerBroker2 avatar PowerBroker2 commented on June 24, 2024

Can you update from master and see if it fixes the problem? Notice that I also switched around the input arguments on begin(), so now it's: bool ELM327::begin(Stream &stream, char protocol, uint16_t payloadLen)

from elmduino.

patfelst avatar patfelst commented on June 24, 2024

Yep fixed now. I am calling myELM327.begin(SerialBT, '6')) as I know my BMW uses CAN bus 11-bit at 500kbps.
When specifying protocol = '0' or default (also '0') I've had to increase the timeout to 5000ms otherwise it will connect, but times out when querying a PID. When I specify protocol 6, the 1000ms timeout is ok.

from elmduino.

patfelst avatar patfelst commented on June 24, 2024

I'm also finding reconnecting after resetting the ESP32 or uploading a new program is quite unreliable, I have to press the bluetooth pair button on my OBD dongle otherwise the EML327.begin fails. I suspect either I have to close the OBD connection, or close the bluetooth connection before uploading again. I will investigate.

from elmduino.

patfelst avatar patfelst commented on June 24, 2024

Sorry one last thing, in your code update I notice that here

if (sendCommand(SET_PROTOCOL_TO_H_SAVE) == ELM_SUCCESS)
you are not using the command variable, you've hard coded SET_PROTOCOL_TO_H_SAVE, I fixed that even though it never gets executed as the for me the function returns in the AUTO search code above.

from elmduino.

PowerBroker2 avatar PowerBroker2 commented on June 24, 2024

Everything should be fixed in 2.2.1. Thanks!

from elmduino.

patfelst avatar patfelst commented on June 24, 2024

excellent, thank you!

from elmduino.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.