无法通过蓝牙连接PC和Android

无法通过蓝牙连接PC和Android

我想使用蓝牙创建一个简单的客户端/服务器应用程序。我想使用 android 作为客户端,使用 Linux Mint 17 Cinnamon 64 位作为服务器。

我找到并改编了这个脚本:

import os
import glob
import time
from bluetooth import *

base_dir = '/home/dougui/devices/'
device_folder = glob.glob(base_dir)[0]
device_file = device_folder + '/w1_slave'

def read_temp_raw():
    f = open(device_file, 'r')
    lines = f.readlines()
    f.close()
    return lines

def read_temp():
    lines = read_temp_raw()
    while lines[0].strip()[-3:] != 'YES':
        time.sleep(0.2)
        lines = read_temp_raw()
    equals_pos = lines[1].find('t=')
    if equals_pos != -1:
        temp_string = lines[1][equals_pos+2:]
        temp_c = float(temp_string) / 1000.0
        temp_f = temp_c * 9.0 / 5.0 + 32.0
        return temp_c

server_sock=BluetoothSocket( RFCOMM )
server_sock.bind(("",PORT_ANY))
server_sock.listen(1)

port = server_sock.getsockname()[1]

uuid = "94f39d29-7d6d-437d-973b-fba39e49d4ee"

advertise_service( server_sock, "AquaPiServer",
        service_id = uuid,
        service_classes = [ uuid, SERIAL_PORT_CLASS ],
        profiles = [ SERIAL_PORT_PROFILE ])

while True:
    print ("Waiting for connection on RFCOMM channel %d" % port)

    client_sock, client_info = server_sock.accept()
    print("Accepted connection from ", client_info)

    try:
        data = client_sock.recv(1024)
        if len(data) == 0: break
        print("received [%s]" % data)
        client_sock.send(data)
        print("sending [%s]" % data)

    except IOError:
        pass

    except KeyboardInterrupt:

        print("disconnected")

        client_sock.close()
        server_sock.close()
        print("all done")

        break

现在,我想将我的 Android 设备连接到我的 PC。我跟着那些指示

这是我发出的一些命令:

➜  sudo hciconfig -a     
hci0:   Type: BR/EDR  Bus: USB
        BD Address: 00:11:22:98:76:54  ACL MTU: 1021:4  SCO MTU: 180:1
        UP RUNNING PSCAN ISCAN 
        RX bytes:18214 acl:297 sco:0 events:667 errors:0
        TX bytes:10341 acl:311 sco:0 commands:190 errors:15
        Features: 0xff 0x3e 0x09 0x76 0x80 0x01 0x00 0x80
        Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3 
        Link policy: RSWITCH HOLD SNIFF 
        Link mode: SLAVE ACCEPT 
        Name: 'oscar-0'
        Class: 0x640100
        Service Classes: Rendering, Audio, Telephony
        Device Class: Computer, Uncategorized
        HCI Version: 2.0 (0x3)  Revision: 0x50
        LMP Version: 2.0 (0x3)  Subversion: 0x3
        Manufacturer: Mitel Semiconductor (16)

➜  hcitool dev                       
Devices:
        hci0    00:11:22:98:76:54

➜  sudo hidd --connect 50:A4:C8:3F:47:B2
Can't get device information: Success

当我尝试点击手机中的电脑名称时,它会进行搜索并短暂标记“已连接到媒体音频”,但不到一分钟,连接就丢失了。连接成功时我收到此消息:

Nov 18 18:26:32 oscar kernel: [ 4968.066411] input: 50:A4:C8:3F:47:B2 as /devices/virtual/input/input26

我想在 Android 上使用 Blue term 应用程序。

我可以做什么来连接两个设备?

相关内容