sylvie-2024

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

bluetooth_test.py (1461B)


      1 
      2 import bluetooth
      3 
      4 server_socket=bluetooth.BluetoothSocket( bluetooth.RFCOMM )
      5 port = 1
      6 server_socket.bind(("",port))
      7 server_socket.listen(1)
      8 client_socket,address = server_socket.accept()
      9 print("Accepted connection from ",address)
     10 
     11 while True:
     12     res = client_socket.recv(1024)
     13     client_socket.send(res)
     14     if res == 'q':
     15         print ("Quit")
     16         break
     17     else:
     18         print("Received:",res)
     19 
     20 client_socket.close()
     21 server_socket.close()
     22 
     23 # Commands used:
     24 # 1. sudo sdptool add SP
     25 # 2. rfcomm watch hci0
     26 # 3. minicom -b 9600 -o -D /dev/rfcomm0
     27 # 4. sudo nano /etc/systemd/system/dbus-org.bluez.service
     28 #	Then add lines:
     29 #	ExecStart=/usr/lib/bluetooth/bluetoothd -C
     30 #	ExecStartPost=/usr/bin/sdptool add SP
     31 # 5. sudo systemctl daemon-reload	
     32 # 6. sudo systemctl restart bluetooth.service
     33 # https://scribles.net/setting-up-bluetooth-serial-port-profile-on-raspberry-pi/
     34 #
     35 # To get this working properly, I've had to rebuild the kernel with RFCOMM TTY support
     36 # https://blog.hypriot.com/post/nvidia-jetson-nano-build-kernel-docker-optimized/
     37 # https://developer.nvidia.com/embedded/linux-tegra
     38 #
     39 # I've also had to systemctl disable bluetooth.service and then tmux into
     40 # sudo /usr/lib/bluetooth/bluetoothd -C
     41 # because the normal service simply refuses to run with compatibility mode for some reason?
     42 #
     43 # Either way, you can use the normal Bluez version (5.48) from the ppa.
     44 # It's easier to pair using the blueman program than the commandline.. too!