Open jimwhitelaw opened 2 weeks ago
@molotovec, here's what I can see happening in your log file.
Are you certain that protocol 7 (ISO 15765-4 CAN 29bit ID, 500 kbaud) is correct for your vehicle? The way the "AT TP A7" works is that if it doesn't establish a connection with protocol 7, the ELM327 starts an automatic protocol search, which takes some time to complete that needs to be accounted for. Try leaving the protocol off when calling myELM327.begin(). That will do an auto protocol search with the appropriate wait for the search.
void loop() {
//float tempRPM = myELM327.rpm();
float tempVolts = myELM327.batteryVoltage();
if (myELM327.nb_rx_state == ELM_SUCCESS) {
//rpm = tempRPM;
volts=tempVolts;
} else {
Serial.println("Failed to receive data from ELM327.");
myELM327.printError();
}
//draw(rpm);
draw(volts);
if (myELM327.nb_rx_state == ELM_TIMEOUT) {
Serial.print("Reset by: ELM_TIMEOUT");
resetDraw();
}
}
This is not the correct way to query in a loop. You need to account for the ELM_GETTING_MESSAGE state. See this code from the Bluetooth serial example:
void loop()
{
float tempRPM = myELM327.rpm();
if (myELM327.nb_rx_state == ELM_SUCCESS)
{
rpm = (uint32_t)tempRPM;
Serial.print("RPM: "); Serial.println(rpm);
}
else if (myELM327.nb_rx_state != ELM_GETTING_MSG)
myELM327.printError();
}
Lastly, batteryVoltage() is not a good query to use for testing your ELM327 connection. Unlike all the other queries, when responding to that query, the EML327 does not communicate with the vehicle ECU, it simply reads the voltage on its own power input and returns that. So it's possible to get a good response to batteryVoltage() and still not have a valid connection from your ELM device to the vehicle ECU. A better option is to use _supportedPIDs_120() as that is guaranteed to communicate with and work on all ECUs (per the OBDII spec).
@jimwhitelaw Thanks a lot for the reply!!! Unfortunately setting protocol is not a case. I tried auto before and it fails with timeouts so i've dig issues and found that protocol setting might fix, but is not. Timeout increase in the myELM327.begin(client, true, 2000); doesn't help. So point 3 is not a case. I've tried to use supportedPIDs_1_20() but result was same. Data received for a while and then stopped with timeout error even with no tft library use. Tests were don in the car and at home.
I've thinking of try to trigger ELM adapter with AT command to wake it up if it does so, but not sure of this workaround and what command is good to send (AT @1 not helped). What do u think of that? Maybe I need to send some extra AT command on adapter initialization?
Please do see code below and log output:
#include <WiFi.h>
#include "ELMduino.h"
int nb_query_state = SEND_COMMAND; // Set the inital query state ready to send a command
const char* ssid = "V-LINK";
const char* host = "192.168.0.10";
const int port = 35000;
//IP Adress of your ELM327 Dongle
IPAddress server(192, 168, 0, 10);
WiFiClient client;
ELM327 myELM327;
uint32_t rpm = 0;
uint32_t volts = 0;
void setup() {
Serial.begin(38400);
// Connecting to ELM327 WiFi
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.mode(WIFI_AP);
WiFi.begin(ssid);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("Connected to Wifi");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
if (client.connect(server, 35000))
Serial.println("connected");
else {
Serial.println("connection failed");
ESP.restart();
while (1)
;
}
Serial.println("Start ELM init ");
myELM327.begin(client, true, 2000);
// modify sleep time? AT PP 0E SV EA OK 5 min
}
void resetDraw() {
if (nb_query_state == SEND_COMMAND) // We are ready to send a new command
{
myELM327.sendCommand("AT"); // Send the custom PID commnad
nb_query_state = WAITING_RESP; // Set the query state so we are waiting for response
} else if (nb_query_state == WAITING_RESP) // Our query has been sent, check for a response
{
myELM327.get_response(); // Each time through the loop we will check again
}
}
void loop() {
float tempRPM = myELM327.rpm();
if (myELM327.nb_rx_state == ELM_SUCCESS) {
rpm = (uint32_t)tempRPM;
Serial.print("RPM: ");
Serial.println(rpm);
} else if (myELM327.nb_rx_state != ELM_GETTING_MSG)
myELM327.printError();
}
The log shows that it’s searching for the protocol, but not connecting. I was going to suggest trying a different adapter, but from your screenshot, it appears to be working with Car Scanner. I don’t really know how to help at this point; the only suggestion I have is to go back to specifying the protocol in begin() with a much longer timeout.
Hi @jimwhitelaw myELM327.begin(client, true, 25000, ISO_15765_29_BIT_500_KBAUD);
void loop() { float tempRPM = myELM327.rpm();
if (myELM327.nb_rx_state == ELM_SUCCESS) { rpm = (uint32_t)tempRPM; Serial.print("RPM: "); Serial.println(rpm); draw(rpm); delay(500); myELM327.sendCommand("AT"); } else if (myELM327.nb_rx_state != ELM_GETTING_MSG) myELM327.printError(); if (myELM327.nb_rx_state == ELM_TIMEOUT) { resetDraw(); } }
No timeout now as delay raised to 25sec But value measured now each ~21 sec
UPDATE: in the car value is stuck with the first received. With the less delay and auto protocol it was showing up to 5 sec of updating value and then had timeout issue
13:40:31.177 -> Sending the following command/query: 010C1 13:40:52.336 -> Received char: ? 13:40:52.336 -> Received char: \r 13:40:52.336 -> Received char: \r 13:40:52.336 -> Received char: > 13:40:52.336 -> Delimiter found. 13:40:52.336 -> All chars received: 13:40:52.336 -> Expected response header: 410C 13:40:52.336 -> Response not detected 13:40:52.336 -> WARNING: Number of payload chars is less than the number of expected response chars returned by ELM327 - returning 0 13:40:52.336 -> RPM: 0.00 13:40:52.844 -> Clearing input serial buffer 13:40:52.844 -> Sending the following command/query: AT 13:40:52.882 -> Service: 1 13:40:52.882 -> PID: 12 13:40:52.882 -> Normal length query detected 13:40:52.882 -> Query string: 010C1 13:40:52.882 -> Clearing input serial buffer 13:40:52.882 -> Sending the following command/query: 010C1 13:41:13.946 -> Received char: ? 13:41:13.946 -> Received char: \r 13:41:13.946 -> Received char: \r 13:41:13.946 -> Received char: > 13:41:13.946 -> Delimiter found. 13:41:13.946 -> All chars received: 13:41:13.946 -> Expected response header: 410C 13:41:13.946 -> Response not detected 13:41:13.946 -> WARNING: Number of payload chars is less than the number of expected response chars returned by ELM327 - returning 0 13:41:13.946 -> RPM: 0.00 13:41:14.449 -> Clearing input serial buffer 13:41:14.449 -> Sending the following command/query: AT 13:41:14.488 -> Service: 1 13:41:14.488 -> PID: 12 13:41:14.488 -> Normal length query detected 13:41:14.488 -> Query string: 010C1 13:41:14.488 -> Clearing input serial buffer 13:41:14.488 -> Sending the following command/query: 010C1
How can this delay be reduced to at least 500msec between results ? Thnx in advance!
Hi @PowerBroker2 ! Thanks a lot for the library ! I have the same ERROR: ELM_TIMEOUT . Value received for a while and then error happens. Code below
Log below ELM_timeout_LOG.txt
Thanks in advance!
Update: No tft (plain) wifi example also shows timeout issue (library 3.3.0, esp32C3, ELM327 v2.3 VGATE iCar Pro)
Originally posted by @molotovec in https://github.com/PowerBroker2/ELMduino/issues/210#issuecomment-2175620529