I am currently using raspberry pi 4 in my school project and i would like the Pi autoconnect during startup. However, i failed to do that. i have tried:
- File rc.local
- crontab -e My python script can run during startup but only bluetooth connection part does not work. I can assure that my script is working but by run it using pyhton software such as Geany,Thony python IDE etc.
The bluetooth part in my code as such:
if os.path.exists('/dev/rfcomm0') == False:
path = 'sudo rfcomm bind 0 00:15:02:09:14:E5'
os.system (path)
time.sleep(1)
bluetoothSerial = serial.Serial( "/dev/rfcomm0", baudrate=9600 )
I tried to connect with HC-05 bluetooth module with arduino. I need the python script work without monitor to run the code where as the system 'on' it will work.
How can my python script connect bluetooth automatically during startup?
systemd
is better than the alternatives: blog.usedbytes.com/2019/11/run-at-startup-without-rc.local for starting your code. rfcomm, was deprecated by the BlueZ project in 2017. If you are following a tutorial that uses them, there is a chance that it might be out of date. The same functionality can be done with the standard Python Socket library blog.kevindoran.co/bluetooth-programming-with-python-3