|
@@ -143,4 +143,123 @@ sudo python3 -c 'print("\26\01\62\65\72\6c\69\6e")' > /dev/rfcomm
|
|
|
#test empfang
|
|
|
cat /dev/rfcomm0
|
|
|
|
|
|
+sudo apt-get install python3-dev
|
|
|
+
|
|
|
+sudo apt install python3-pip
|
|
|
+
|
|
|
+python3 -m pip install setuptools
|
|
|
+
|
|
|
+python3 -m pip install wheel
|
|
|
+
|
|
|
+python3 -m pip install pybluez
|
|
|
+
|
|
|
+sudo apt autoremove
|
|
|
+
|
|
|
+# Python serial bluetooth transmitter / receiver
|
|
|
+
|
|
|
+sudo nano /etc/systemd/system/dbus-org.bluez.service
|
|
|
+
|
|
|
+changing
|
|
|
+
|
|
|
+ExecStart=/usr/lib/bluetooth/bluetoothd
|
|
|
+
|
|
|
+into
|
|
|
+
|
|
|
+ExecStart=/usr/lib/bluetooth/bluetoothd -C
|
|
|
+
|
|
|
+sudo sdptool add SP
|
|
|
+
|
|
|
+nano send_serial_bluetooth.py
|
|
|
+
|
|
|
+# Python Code Start
|
|
|
+
|
|
|
+#!/usr/bin/env python3
|
|
|
+
|
|
|
+import sys
|
|
|
+import bluetooth
|
|
|
+
|
|
|
+addr = none
|
|
|
+
|
|
|
+if len(sys.argv) < 2:
|
|
|
+ print("No device specified. Searching all nearby bluetooth devices for "
|
|
|
+ "the SampleServer service...")
|
|
|
+else:
|
|
|
+ addr = sys.argv[1]
|
|
|
+ print("Searching for SampleServer on {}...".format(addr))
|
|
|
+
|
|
|
+# search for the SampleServer service
|
|
|
+uuid = "00001101-0000-1000-8000-00805f9b34fb"
|
|
|
+service_matches = bluetooth.find_service(uuid=uuid, address=addr)
|
|
|
+
|
|
|
+if len(service_matches) == 0:
|
|
|
+ print("Couldn't find the SampleServer service.")
|
|
|
+ sys.exit(0)
|
|
|
+
|
|
|
+first_match = service_matches[0]
|
|
|
+port = first_match["port"]
|
|
|
+name = first_match["name"]
|
|
|
+host = first_match["host"]
|
|
|
+
|
|
|
+print("Connecting to \"{}\" on {}".format(name, host))
|
|
|
+
|
|
|
+# Create the client socket
|
|
|
+sock = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
|
|
|
+sock.connect((host, port))
|
|
|
+
|
|
|
+print("Connected. Type something...")
|
|
|
+while True:
|
|
|
+ data = input()
|
|
|
+ if not data:
|
|
|
+ break
|
|
|
+ sock.send(data)
|
|
|
+
|
|
|
+sock.close()
|
|
|
+
|
|
|
+# Python Code End
|
|
|
+
|
|
|
+sudo hciconfig hci0 piscan
|
|
|
+
|
|
|
+nano receive_serial_bluetooth.py
|
|
|
+
|
|
|
+# Python Code Start
|
|
|
+
|
|
|
+#!/usr/bin/env python3
|
|
|
+
|
|
|
+import bluetooth
|
|
|
+
|
|
|
+server_sock = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
|
|
|
+server_sock.bind(("", bluetooth.PORT_ANY))
|
|
|
+server_sock.listen(1)
|
|
|
+
|
|
|
+port = server_sock.getsockname()[1]
|
|
|
+
|
|
|
+uuid = "00001101-0000-1000-8000-00805f9b34fb"
|
|
|
+
|
|
|
+bluetooth.advertise_service(server_sock, "SampleServer", service_id=uuid,
|
|
|
+ service_classes=[uuid, bluetooth.SERIAL_PORT_CLASS],
|
|
|
+ profiles=[bluetooth.SERIAL_PORT_PROFILE],
|
|
|
+ # protocols=[bluetooth.OBEX_UUID]
|
|
|
+ )
|
|
|
+
|
|
|
+print("Waiting for connection on RFCOMM channel", port)
|
|
|
+
|
|
|
+client_sock, client_info = server_sock.accept()
|
|
|
+print("Accepted connection from", client_info)
|
|
|
+
|
|
|
+try:
|
|
|
+ while True:
|
|
|
+ data = client_sock.recv(1024)
|
|
|
+ if not data:
|
|
|
+ break
|
|
|
+ print("Received", data)
|
|
|
+except OSError:
|
|
|
+ pass
|
|
|
+
|
|
|
+print("Disconnected.")
|
|
|
+
|
|
|
+client_sock.close()
|
|
|
+server_sock.close()
|
|
|
+print("All done.")
|
|
|
+
|
|
|
+# Python Code End
|
|
|
```
|