PowerBroker2 / ELMduino

Arduino OBD-II Bluetooth Scanner Interface Library for Car Hacking Projects
MIT License
638 stars 124 forks source link

ELM_TIMEOUT for example code ESP32_Bluetooth_Serial in the library #159

Closed NickEsColR closed 9 months ago

NickEsColR commented 1 year ago

Hello, first I want to thanks for the effort put in develop this library. I am currently trying to execute the example code in my ESP32-WROOM-32 and the only change I made was the OBDII conection. I tried using the bluetooth name to connect but it never connect, so I tried with the mac address, bellow i paste the code fragment I change `uint8_t address[6] = {0x00, 0x10, 0xCC, 0x4F, 0x36, 0x03};

uint32_t rpm = 0;

void setup() { //#if LED_BUILTIN //pinMode(LED_BUILTIN, OUTPUT); //digitalWrite(LED_BUILTIN, LOW); //#endif

DEBUG_PORT.begin(38400); ELM_PORT.begin("ESP32test", true); //ELM_PORT.setPin("1234");

if (!ELM_PORT.connect(address))`

Then, in the serial monitor I receive the following output. image After, I decide to add a delay of 10 seconds to the loop and the problem wasn´t solve. And as you can see in the next capture, the only change in the output was the overflow for the timeout image I check in other issues and forums, seeing the successful output. I will happy if you could help me.

GaryJurgens commented 1 year ago

I have the same problem, i have to connect via the mac address as the connecting via the name does not work. I am also getting timeout, when i use the serial pass though it just echos my command or says Searching no data. I can query it on my phone and can send some basic hex commands if i use the Discover and Connect Example

GaryJurgens commented 1 year ago

Solved this, I overloaded the the myELM.Begin constructor with the following.

if (!myELM327.begin(ELM_PORT, false , 2000, '5', 40,2000)) { Serial.println("Couldn't connect to OBD scanner - Phase 2"); while (1); }

and it now connects and prints out the following as i Rev my car.

Received: 410C0C98410C0C9C ELM_SUCCESS RPM: 804 Received: 410C0C92 ELM_SUCCESS RPM: 16383 Received: 410CFFFC ELM_SUCCESS RPM: 16383 Received: 410CFFFC

NickEsColR commented 1 year ago

right now I have the following code `#include "BluetoothSerial.h"

include "ELMduino.h"

BluetoothSerial SerialBT;

define ELM_PORT SerialBT

define DEBUG_PORT Serial

// to remove bonded devices, set to 1 in normal to 0 //#define REMOVE_BONDED_DEVICES 0

ELM327 myELM327;

uint8_t address[6] = {0x00, 0x10, 0xCC, 0x4F, 0x36, 0x03};

uint32_t rpm = 0; int counter = 0; String response[8] = {"engineCoolantTemp: ","fuelPressure: ","rpm: ","fuelRailPressure: ","fuelLevel: ","ambientAirTemp: ","oilTemp: ","torque: "}; void setup() { //#if LED_BUILTIN //pinMode(LED_BUILTIN, OUTPUT); //digitalWrite(LED_BUILTIN, LOW); //#endif

DEBUG_PORT.begin(38400); ELM_PORT.begin("ESP32test", true); //ELM_PORT.setPin("1234");

if (!ELM_PORT.connect(address)) { DEBUG_PORT.println("Couldn't connect to OBD scanner - Phase 1"); while(1); }

//if (!myELM327.begin(ELM_PORT, true, 2000)) if (!myELM327.begin(ELM_PORT, false , 2000, '5', 40,2000)) { Serial.println("Couldn't connect to OBD scanner - Phase 2"); while (1); }

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

void loop() { float temp = 0; if(counter == 0){ temp = myELM327.engineCoolantTemp(); counter = counter + 1; } else if(counter == 1){ temp = myELM327.fuelPressure(); counter = counter + 1; } else if(counter == 2){ temp = myELM327.rpm(); counter = counter + 1; } else if(counter == 3){ //supportedPIDs_21_40 temp = myELM327.fuelRailPressure(); counter = counter + 1; } else if(counter == 4){ temp = myELM327.fuelLevel(); counter = counter + 1; } else if(counter == 5){//supportedPIDs_41_60 temp = myELM327.ambientAirTemp(); counter = counter + 1; } else if(counter == 6){ temp = myELM327.oilTemp(); counter = counter + 1; } else if(counter == 7){//supportedPIDs_61_80 temp = myELM327.torque(); counter = 0; } delay(10000); Serial.print(response[counter]); if (myELM327.nb_rx_state == ELM_SUCCESS) { Serial.println(temp); } else if (myELM327.nb_rx_state != ELM_GETTING_MSG) myELM327.printError();

}` and in all the options I try i get no response has you can see in the image image

PowerBroker2 commented 1 year ago

Please see the multiple pids example to see how to propperly query multiple pids in one sketch