如何与带 ESP32 模块的 ELM327 OBDII WiFi 设备建立通信

问题描述 投票:0回答:1

我有一个项目,我必须在物联网的帮助下开发一个应用程序,该应用程序获取油箱液位值和里程表值的数据,因为这些值在市场上的普通 OBD 中不可用。我发现ELM327使用WLAN协议和串行通信通过WIFI进行通信。但我不知道如何与 Arduino esp32 模块建立这种通信。 任何关于这方面的想法都会有很大帮助。

arduino android-wifi esp32 wifi elm327
1个回答
0
投票

您可以通过正确的步骤轻松完成:

  1. 确保使用“BluetoothSerial.h”设置经典蓝牙
  2. 调用 .begin() 时,请确保包含第二个参数 (bool true)
  3. 调用 .connect("OBDII") 连接到您的 ELM327
  4. 确保在向 ELM327 发送命令/查询时仅发送回车符(无换行符!)

这是一个简单的示例程序(今天在我自己的ELM327上测试):

#include "BluetoothSerial.h"


BluetoothSerial SerialBT;


#define DEBUG_PORT Serial
#define ELM_PORT   SerialBT


void setup()
{
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, HIGH);

  DEBUG_PORT.begin(115200);
  ELM_PORT.begin("ESP32test", true);

  DEBUG_PORT.println("Attempting to connect to ELM327...");

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

  DEBUG_PORT.println("Connected to ELM327");
  DEBUG_PORT.println("Ensure your serial monitor line ending is set to 'Carriage Return'");
  DEBUG_PORT.println("Type and send commands/queries to your ELM327 through the serial monitor");
  DEBUG_PORT.println();
}


void loop()
{
  if(DEBUG_PORT.available())
  {
    char c = DEBUG_PORT.read();

    DEBUG_PORT.write(c);
    ELM_PORT.write(c);
  }

  if(ELM_PORT.available())
  {
    char c = ELM_PORT.read();

    if(c == '>')
      DEBUG_PORT.println();

    DEBUG_PORT.write(c);
  }
}

此外,ELMduino现在支持ESP32板卡,方便连接和车辆数据查询!

© www.soinside.com 2019 - 2024. All rights reserved.