Bluetooth 配置并运行蓝牙后运行脚本-Rasperry Pi 3

Bluetooth 配置并运行蓝牙后运行脚本-Rasperry Pi 3,bluetooth,raspberry-pi,raspbian,raspberry-pi3,Bluetooth,Raspberry Pi,Raspbian,Raspberry Pi3,我试图在开机时自动调用一个使用蓝牙的程序。但是,在配置和运行蓝牙之前调用该程序 我试着用两种方式调用该程序: 在init.d中使用脚本,并在init:Required Start:$all中使用以下行向update rc.d注册 从/etc/rc.local调用它 这两种方法都没有达到预期效果。它们都启动程序,但在蓝牙配置和运行之前 强制脚本或程序在蓝牙后运行的最佳方法是什么 下面是引导序列中的一些选择行,以便您可以看到我遇到的问题: [ OK ] Started Login Service.

我试图在开机时自动调用一个使用蓝牙的程序。但是,在配置和运行蓝牙之前调用该程序

我试着用两种方式调用该程序:

在init.d中使用脚本,并在init:Required Start:$all中使用以下行向update rc.d注册 从/etc/rc.local调用它 这两种方法都没有达到预期效果。它们都启动程序,但在蓝牙配置和运行之前

强制脚本或程序在蓝牙后运行的最佳方法是什么

下面是引导序列中的一些选择行,以便您可以看到我遇到的问题:

[ OK ] Started Login Service.
[ OK ] Started Getty on tty1.
**Where my program is currently executing**
[ OK ] Started Configure Bluetooth Modems connected by UART.
[ OK ] Reached Target Bluetooth
**Where I want my program to be executing**

Raspbian GNU/Linux 8 tty1
login:

通过使用crontab,我可以使用以下代码行:

@reboot sleep 5 && node /home/pi/workspace/my_program

虽然不理想,但它目前仍有效。我愿意接受任何更好的答案。

Debian 8 Jessie的新初始化系统是systemd。Debian7Wheezy中的老方法是带有运行级别和/etc/inittab的Sysv。使用crontab运行程序的一个缺点是,如果脚本执行崩溃,它将永远消失。如果脚本结束称为respawn,则自动重新启动脚本

如您所见,Bluetooth服务正在运行,并显示已达到目标。要创建您自己的服务,该服务在蓝牙启动后运行,并使用systemd重新启动,只需在/etc/systemd/system/i.e.my_program.service中创建一个文件即可

并激活它

systemctl enable my_program.service
重新启动或手动启动

systemctl daemon-reload
systemctl start my_program.service

如果有人终止进程或重新启动,my_程序将在几秒钟后自动重新启动。

适用于运行Raspbian 9 stretch的任何人

我尝试了@andpei的答案,我的应用程序仍然没有等待蓝牙启动。我可以通过增加需求来解决这个问题

[Unit]
Desription=my_program with systemd, respawn, after bluetooth
After=bluetooth.target
Requires=bluetooth.target

另请注意:蓝牙服务必须启用systemctl enable Bluetooth,以便在我的_程序之前启动蓝牙。
[Unit]
Desription=my_program with systemd, respawn, after bluetooth
After=bluetooth.target
Requires=bluetooth.target