Quantcast
Viewing all articles
Browse latest Browse all 5154

Beginners • raspberrypi bluetooth

I'm tryting to connect with raspberry pi 4(64-bit os) and ardinuo uno R3 using HM-10 bluetooth moudle.
I followed the procedure and made a Bluetooth connection between the two, but there was a problem when I tried to communicate data exchange. I tried many ways, but it was unsuccessful, so I'm asking for help.

The Bluetooth module and Raspberry Pi are connected, there is no problem with the circuit, and even communication is possible between the mobile phone and Arduino's Bluetooth module. However, I don't know why an error occurs when I try to communicate with Raspberry Pi.

Number one is code.
Number two is about the error.
Number three is the list I've tried.

1-1. arduino code

Code:

import bluetoothserver_socket=bluetooth.BluetoothSocket( bluetooth.RFCOMM )port = 1server_socket.bind(("",port))server_socket.listen(1)client_socket,address = server_socket.accept()print("Accepted connection from ",address)while 1: data = client_socket.recv(1024) print("Received: %s" % data) if (data == "q"):  print ("Quit")  breakclient_socket.close()server_socket.close()
1-2. raspberry pi code. (using python3.8)

Code:

from bluetooth import *client_socket=BluetoothSocket( RFCOMM )client_socket.connect(("34:15:13:88:77:45", 1))print("bluetooth Connected!")msg = input("send message : ")client_socket.send(msg)print("Finished")client_socket.close()
2. error

Code:

(myenv) cuk24@raspberrypi:~/2024prj/ardtest $ python3 bluet.py Traceback (most recent call last):  File "<string>", line 3, in connect_bluetooth.error: (112, 'Host is down')During handling of the above exception, another exception occurred:Traceback (most recent call last):  File "bluet.py", line 4, in <module>    socket.connect(("34:15:13:88:77:45", 1))  File "<string>", line 5, in connectbluetooth.btcommon.BluetoothError: [Errno 112] Host is down
3-1. edit bluetooth service file: for use D-bus

Code:

# 블루투스 서비스 파일 열기sudo nano /lib/systemd/system/bluetooth.service# ExecStart 줄 찾아서 수정하기ExecStart=/usr/lib/bluetooth/bluetoothd --experimental# 변경 사항 적용, 블루투스 서비스 재시작sudo systemctl daemon-reloadsudo systemctl restart bluetooth
3-2. Bluetooth Authorization

Code:

sudo usermod -a -G bluetooth cuk24
3-3. trying to use rfcomm port

Code:

rfcommsudo rfcomm release 0sudo rfcomm bind 0 34:15:13:88:77:45 1

Statistics: Posted by gamjar — Fri May 10, 2024 6:42 am — Replies 0 — Views 5



Viewing all articles
Browse latest Browse all 5154