diff --git a/CommObd2Can.cpp b/CommObd2Can.cpp index dd11fff..ceb142c 100644 --- a/CommObd2Can.cpp +++ b/CommObd2Can.cpp @@ -78,7 +78,7 @@ void CommObd2Can::mainLoop() { } } Serial.println(liveData->params.currentTime ); - if (lastDataSent != 0 && liveData->params.currentTime + 2 > lastDataSent) { + if (lastDataSent != 0 && (unsigned long)(millis() - lastDataSent) > 500) { Serial.print("CAN execution timeout. Continue with next command."); liveData->canSendNextAtCommand = true; return; @@ -92,7 +92,6 @@ void CommObd2Can::executeCommand(String cmd) { Serial.print("executeCommand "); Serial.println(cmd); - lastDataSent = 0; if (cmd.equals("") || cmd.startsWith("AT")) { // skip AT commands as not used by direct CAN connection liveData->canSendNextAtCommand = true; @@ -140,7 +139,7 @@ void CommObd2Can::sendPID(const uint16_t pid, const String& cmd) { Serial.print(msgString); } Serial.println(""); - lastDataSent = liveData->params.currentTime; + lastDataSent = millis(); } /** diff --git a/CommObd2Can.h b/CommObd2Can.h index 2ba644b..28dd2ec 100644 --- a/CommObd2Can.h +++ b/CommObd2Can.h @@ -18,6 +18,7 @@ class CommObd2Can : public CommInterface { int16_t rxRemaining; // Remaining bytes to complete message char msgString[128]; // Array to store serial string uint16_t lastPid; + unsigned long lastDataSent = 0; public: void connectDevice() override; void disconnectDevice() override;