【问题标题】:How do I establish communication with ELM327 OBDII WiFi device with ESP32 module如何使用 ESP32 模块与 ELM327 OBDII WiFi 设备建立通信
【发布时间】:2020-05-10 11:30:06
【问题描述】:

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

【问题讨论】:

    标签: arduino android-wifi esp32 wifi elm327


    【解决方案1】:

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

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

    【讨论】:

    • 它就像一个魅力!简单高效的代码!
    猜你喜欢
    • 1970-01-01
    • 2016-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多