如何使用 rfcomm 通过 bt 读取 elm327 obd2 原始数据?

如何使用 rfcomm 通过 bt 读取 elm327 obd2 原始数据?

我正在尝试读取我的汽车数据,我已将一个便宜的 elm327 bt obd2 连接器连接到它,并使用 lubuntu。

基本上这就是我所做的,但它并没有完全发挥作用,我最终得到了一个有问题的终端,我一次只能看到一个租船人,而且得不到任何回复

首先我将其配对并信任它:

[bluetooth]# pair 00:10:CC:4F:36:03
Attempting to pair with 00:10:CC:4F:36:03
[CHG] Device 00:10:CC:4F:36:03 Connected: yes
Request PIN code
[agent] Enter PIN code: 1234
[CHG] Device 00:10:CC:4F:36:03 UUIDs: 00001101-0000-1000-8000-00805f9b34fb
[CHG] Device 00:10:CC:4F:36:03 ServicesResolved: yes
[CHG] Device 00:10:CC:4F:36:03 Paired: yes
Pairing successful
[CHG] Device 00:10:CC:4F:36:03 ServicesResolved: no
[CHG] Device 00:10:CC:4F:36:03 Connected: no
[CHG] Device 00:10:CC:4F:36:03 Connected: yes
[CHG] Device 00:10:CC:4F:36:03 Connected: no
[CHG] Device 00:10:CC:4F:36:03 Connected: yes
[CHG] Device 00:10:CC:4F:36:03 Connected: no
[CHG] Device 00:10:CC:4F:36:03 Connected: yes
[CHG] Device 00:10:CC:4F:36:03 Connected: no
[CHG] Device 00:10:CC:4F:36:03 Connected: yes
[CHG] Device 00:10:CC:4F:36:03 Connected: no
[CHG] Device 00:10:CC:4F:36:03 Connected: yes
[CHG] Device 00:10:CC:4F:36:03 Connected: no
[NEW] Device 3C:5D:2A:64:34:DD 3C-5D-2A-64-34-DD
[CHG] Device 00:10:CC:4F:36:03 Connected: yes
[CHG] Device 00:10:CC:4F:36:03 Connected: no
[NEW] Device 48:CA:AB:30:69:81 48-CA-AB-30-69-81
[CHG] Device 00:10:CC:4F:36:03 RSSI: -51
[CHG] Device 00:10:CC:4F:36:03 RSSI: -40
[DEL] Device 48:CA:AB:30:69:81 48-CA-AB-30-69-81
[CHG] Device 00:10:CC:4F:36:03 Connected: yes
[CHG] Device 00:10:CC:4F:36:03 Connected: no
[DEL] Device 3C:5D:2A:64:34:DD 3C-5D-2A-64-34-DD
[CHG] Device 00:10:CC:4F:36:03 RSSI: -54
[bluetooth]# info 00:10:CC:4F:36:03
Device 00:10:CC:4F:36:03 (public)
        Name: OBDII
        Alias: OBDII
        Paired: yes
        Trusted: no
        Blocked: no
        Connected: no
        LegacyPairing: no
        UUID: Serial Port               (00001101-0000-1000-8000-00805f9b34fb)
        ManufacturerData Key: 0x0100
        ManufacturerData Value:
  03 36 4f cc 10 00                                .6O...          
        ManufacturerData Key: 0x7262
        ManufacturerData Value:
  32 32 78 78 11 22 33 44 55 66 aa bb 00 00        22xx."3DUf....  
        RSSI: -54
[bluetooth]# trust 00:10:CC:4F:36:03
[CHG] Device 00:10:CC:4F:36:03 Trusted: yes
Changing 00:10:CC:4F:36:03 trust succeeded

然后我使用 rfcomm 建立串行连接,我运行 sdptool 来了解其在哪个通道上,因此我运行:

user@user-20n20009pg:~$ sdptool records 00:10:CC:4F:36:03
Service Name: JL_SPP
Service RecHandle: 0x10004
Service Class ID List:
  "Serial Port" (0x1101)
Protocol Descriptor List:
  "L2CAP" (0x0100)
  "RFCOMM" (0x0003)
    Channel: 2
Profile Descriptor List:
  "Serial Port" (0x1101)
    Version: 0x0102

user@user-20n20009pg:~$ sudo rfcomm connect /dev/rfcomm0 00:10:CC:4F:36:03 2 &
[1] 1583
user@user-20n20009pg:~$ Connected /dev/rfcomm0 to 00:10:CC:4F:36:03 on channel 2
Press CTRL-C for hangup

当我使用屏幕连接时,它看起来像是在工作,但它只显示一个字符

user@user-20n20009pg:~$ sudo screen /dev/rfcomm0 38400

然后它会在另一个终端上打开并且:

>a

而且我似乎无法写入完整的 atz 命令,而且它每次只显示一个字符。

我尝试过其他波特率,如 9600、38400、115200,但目前没有任何效果

你知道我错过了什么吗?

答案1

这是我用来通过 rfcomm 连接蓝牙 GPS 的脚本,可能会给你一些想法:

#!/bin/bash
# Start a gps receiver with bluetooth output
# Then determine if the gps daemon is already running
xxx=`ps -eo pid,comm |grep [g]psd`
if [ -n "$xxx" ]; then 
  set `echo $xxx`
  pidgpsd=$1
fi

MYGPS=`grep "^[^#].*device.*;" /etc/bluetooth/rfcomm.conf |cut -f2 -d" "|cut -f1 -d";"`

#Determine if the rfcomm0 device has been created
if [ ! -e /dev/rfcomm0 ]; then
  # kill the old gpsd
  if [ -n "$pidgpsd" ]; then
    # for icon invocation, use gksudo
    pkexec kill $pidgpsd
    unset pidgpsd
  fi
  sdptool add --channel=1 OPUSH
  #gksudo rfcomm bind /dev/rfcomm0 00:0A:3A:2C:BC:44
  pkexec rfcomm bind /dev/rfcomm0 $MYGPS
  sleep 5
fi

# Start the new gpsd if necessary
if [ ! -n "$pidgpsd" ]; then
  #sudo gpsd -n -N -D2 /dev/rfcomm0
  pkexec -- gpsd -n -D2 /dev/rfcomm0
  echo "gpsd started"
  sleep 5
fi

# Create a ttyUSB0 link for broken viking
if [ ! -e /dev/ttyUSB0 ]; then
  sudo ln -s /dev/rfcomm0 /dev/ttyUSB0
fi

#/usr/local/bin/gpsdrive
#$HOME/work/gps/gpsdrive-2.11/build/src/gpsdrive
sudo viking

我已经 10 年没有玩过 Delorme Earthmate GPS 了,但 sdptool 的手册页除了 OPUSH 之外还提供了二十几种服务——您可以尝试其中一种。不幸的是,手册页并没有真正说明每项服务提供什么。

相关内容