If you do end up needing an alternative Bluetooth approach, my library here is one option.
https://github.com/petzval/btferret
Below is the shell of a Classic server program that will do the same thing. See section 2.2 in the documentation to install the Python module (btfpy.so). If the phone is already paired with the PI, unpair it first because this code will not recognize previous pairings. Run this code to pair and let the devices disconnect, then run it again and a Bluetooth serial terminal on the phone and re-connect. The code assumes that the terminal sends ASCII strings terminated with a line feed (10) character. Sending "hello" prompts the reply "HELLO" with a line feed termination. Sending "exit" terminates the program.
https://github.com/petzval/btferret
Below is the shell of a Classic server program that will do the same thing. See section 2.2 in the documentation to install the Python module (btfpy.so). If the phone is already paired with the PI, unpair it first because this code will not recognize previous pairings. Run this code to pair and let the devices disconnect, then run it again and a Bluetooth serial terminal on the phone and re-connect. The code assumes that the terminal sends ASCII strings terminated with a line feed (10) character. Sending "hello" prompts the reply "HELLO" with a line feed termination. Sending "exit" terminates the program.
Code:
# SAVE this as cserv.py## RUN# sudo python3 cserv.py#import btfpydef callback(node,line,len): if ('hello') in line.decode(): print("Got hello, reply HELLO") btfpy.Write_node(node,"HELLO\n",0) if ('exit') in line.decode(): return(btfpy.SERVER_EXIT) return(btfpy.SERVER_CONTINUE) if btfpy.Init_blue("devices.txt") == 0: exit(0)keyflag = btfpy.KEY_ON | btfpy.PASSKEY_LOCAL # works for most connecting clientsbtfpy.Classic_server(btfpy.ANY_DEVICE,callback,10,keyflag) # line end char = 10 line feedbtfpy.Close_all()Statistics: Posted by petzval — Wed Mar 12, 2025 11:06 am