1

I want to create a simple client/server app using bluetooth. I want to use an android as client and a Linux Mint 17 Cinnamon 64 bit as server.

I found and adapted this script :

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

Now, I want to connect my android to my PC. I followed those instructions.

This is some command I made :

➜  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

When I'm trying to tap on the name of my pc in my phone, It search and it mark "Connected to media audio" for a short time but in less than a minute, the connection is lost. I have this message when the connection succeed :

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

I want to use the Blue term app on Android.

What can I do to couple both devices?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.