spacecheese / bluez_peripheral

A library for building BLE peripherals using GATT and bluez
MIT License
42 stars 8 forks source link

Cronjob not working #30

Open targettadams opened 1 year ago

targettadams commented 1 year ago

I have a functioning python program written using bluez-peripheral which, when started from the terminal, runs fine and allows me to connect to my bluetooth peripheral (raspberry pi) and do everything I need to do. I want the program to run when the pi is booted. But when I schedule a cronjob, I don't see any advertisement once I've booted. The program seems to be running happily in the background, but I just can't connect to it.

Seen any similar issues or any suspicions about what the issue might be? I would really appreciate a quick response if possible as I am working to quite a tight deadline ...

targettadams commented 1 year ago

Stand at ease. I added a small delay to the scheduled task and it works fine. I think the program was being run before the bluetooth components had a chance to start up properly. 15 secs did the trick; could probably be less.

spacecheese commented 1 year ago

Hello. For this use case a systemd service is probably more reliable (in particular you can mark services as depending on other services such a bluetoothd) though cron should work. I'll keep this issue open for now since from your initial comment it sounds as though you didn't receive an exception when your service failed to register which sounds like a possible bug. I hadn't thought of this particular edge/ use case so I will investigate, thanks for the issue.

targettadams commented 1 year ago

Thanks for the suggestion. Giving my age away a bit, but systemd services didn't exist when I used to be a seasoned linux user. It was all cron. Yep - I've reimplemented as a service requiring bluetooth.service as a dependency and it now works. Much better than my arbitrary 15 sec delay in my cronjob script. Thanks.