繁体   English   中英

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

[英]How do I establish communication with ELM327 OBDII WiFi device with ESP32 module

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

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

  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 板,方便连接和车辆数据查询!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM