【问题标题】:How to initialize Bluetooth in a startup script with Yocto Poky Linux如何使用 Yocto Poky Linux 在启动脚本中初始化蓝牙
【发布时间】:2014-12-02 08:47:32
【问题描述】:

我有一个脚本可以在 Intel Edison 上初始化我的蓝牙设置。它允许配对和连接到运行 Yocto Poky Linux 的无头机器。建议我将启动脚本放在 /etc/init.d 并运行 update-rc.d myscript.sh defaults。该脚本运行但它没有工作(生成的引导错误说蓝牙设备未找到),因为蓝牙尚未启动。我做了一些研究,删除链接后,我确实 update-rc.d myscript.sh defaults 99 声称最后运行脚本但它没有任何区别 - 它仍然在引导序列中运行在同一个位置.我验证了链接上有 S99,所以看起来它们设置正确。 SO上有另一个帖子问了一个类似的问题,但那是一个Ubuntu系统,我的是Poky Linux。该解决方案建议将启动脚本放在我的系统上不存在的目录中。还有其他建议,把它放在 rc.local 中,我做了,得到了相同的结果,它在蓝牙初始化之前运行。

这是我的脚本。我的程序名为 nmea_thread,最后运行。其他一切都在初始化蓝牙。

#!/bin/sh
/usr/sbin/rfkill unblock bluetooth
/usr/bin/hciconfig hci0 up
/usr/bin/hciconfig hci0 piscan 
/usr/bin/hciconfig hic0 sspmode 0
/home/root/simpleAgent/simple-agent &
/home/root/nmea_thread 

【问题讨论】:

    标签: linux bluetooth yocto intel-edison


    【解决方案1】:

    蓝牙通常是异步初始化的,所以你不能确定你的脚本会在添加 hci0 后运行。好的解决办法是在后台等待BT初始化:

    #!/bin/bash
    
    if [ "$1" != "background" ]; then
         $0 background &
    else
        #Wait until BT is initialized
        for ((i = 0; i <= 100; i++)) do
          hciconfig hci0 && break
          usleep 100000
        done
        /usr/sbin/rfkill unblock bluetooth
        /usr/bin/hciconfig hci0 up
        /usr/bin/hciconfig hci0 piscan 
        /usr/bin/hciconfig hic0 sspmode 0
        /home/root/simpleAgent/simple-agent &
        /home/root/nmea_thread 
    fi
    

    【讨论】:

      【解决方案2】:

      hciattach 是正确的方法。 语法

      hciattach /dev/ttyAMA0 bcm43xx 3000000

      【讨论】:

        【解决方案3】:

        在初始化之前,您需要先刷新驱动程序。目前我不记得是怎么做的,但这就是我用树莓派和 yocto 做的。 请注意,如果您使用 systemV,您可以从脚本中调用它,它会起作用 使用 SystemD,您需要将其放入服务并等待。在这两种情况下都应该做Falshing。

        【讨论】:

          猜你喜欢
          • 2023-04-09
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-03-15
          • 1970-01-01
          • 2014-12-08
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多