0

For a recent project I try to make a python program that let me connect with the HC06 module. For that I use pybluez. But this wont work at all, so I tried to pair through terminal using bluetoothctl.

When scanning I discover the device:

[NEW] Device 98:D3:31:FD:9A:27 OKEY DOKEY MARIO

but when connecting:

[bluetooth]# connect 98:D3:31:FD:9A:27

Attempting to connect to 98:D3:31:FD:9A:27

Failed to connect: org.bluez.Error.Failed

[bluetooth]# connect OKEY DOKEY MARIO

Device OKEY DOKEY MARIO not available

How can I solve this?

0

What I did above works fine. I just needed an external USB bluetooth dongle. So the bluetooth module on my pc was the problem. Now I can connect and send messages. I used this small program to test the connection, send and then print the time for sending and receiving the message. Code is written in python.

    import bluetooth
    import socket
    import time

    import timeit

    size = 1024
    bd_addr = "98:D3:31:FD:9A:27"
    port = 1



    sock=bluetooth.BluetoothSocket( bluetooth.RFCOMM )
    sock.connect((bd_addr, port))
    time.sleep(5)
    start = timeit.default_timer()
    sock.send("hello!! \r\n")


    while 1:  
       data = sock.recv(size)
       if data:
          end = timeit.default_timer()
          print(data)
          print(end-start)

    sock.close()

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.