I am using my Raspberry Pi B+ to control a 32x32 LED matrix and I am trying to send commands from an Android app to my Pi over bluetooth to display text on the LED matrix. I am using Xamarin Android for the Android app and I am using the PyBluez library to handle the Bluetooth
Since what I'm making here is essentially a smart LED sign. I need to process of the Pi starting up and running the Python script PyPipe.py (Below) as stream lined as possible. In essence, I don't want to have to ssh into the Pi and start the script manually every time it the Pi shuts down.
I have been able to get the script to run on start up by putting this command to run the script in etc/rc.local
sudo ./PyPipe.py &
When I manually run the PyPipe.py script in the terminal the entire process works perfectly and executes without error, however, when the PyPipe.py script is run on startup the script errors out. For debugging purposes I made a test file that write out a few strings to a log file that tells me where the script gets in executing. The log file tells me that it throws an exception 111 Connection Refused when it tries to execute the advertise_service() method. this only happens when it runs from startup. Any Ideas on what im doing wrong?
from bluetooth import * server_sock=BluetoothSocket( RFCOMM ) server_sock.bind(("",PORT_ANY)) server_sock.listen(1) port = server_sock.getsockname() uuid = "94f39d29-7d6d-437d-973b-fba39e49d4ee" advertise_service( server_sock, "NicksPiServer", service_id = uuid, service_classes = [ uuid, SERIAL_PORT_CLASS ], profiles = [ SERIAL_PORT_PROFILE ], # protocols = [ OBEX_UUID ] ) print("Waiting for connection on RFCOMM channel %d" % port) client_sock, client_info = server_sock.accept() print("Accepted connection from ", client_info) try: while True: data = client_sock.recv(1024) if len(data) == 0: break print("received [%s]" % data) except IOError: pass print("disconnected") client_sock.close() server_sock.close() print("all done")