win10使用虚拟蓝牙串口登录各种嵌入式linux(树莓派/荔枝派/香橙派/nanopi)设备

由于有个项目需要调试wifi,之前为了方便一直都是电脑和linux开发板连接到一个固定的wifi然后通过ip地址连接shell的,这就产生了一个问题,在linux开发板切换wifi时会失去连接,又不方便通过串口进行控制,于是想着通过蓝牙对开饭进行登录控制,参考的是树莓派社区的教程。
前提条件

移植好蓝牙驱动
移植好bluez协议栈

先是创建一个btserial.sh脚本文件。

vim btserial.sh

在脚本文件里输入如下脚本命令,第一行命令是定义蓝牙名称,我这边设置成handy_aml。第二行命令行是打开使能蓝牙,第三行是打开蓝牙的串行通信功能。第四行是将蓝牙收到的数据映射到getty终端,登录用户为root,波特率115200。最后两行为使能打开射频串行口协议功能。

#!/bin/bash -e

#Edit the display name of the amlogic device so you can distinguish
#your unit from others in the Bluetooth console
#(very useful in a class setting)

echo PRETTY_HOSTNAME=handy_aml > /etc/machine-info

# Edit /lib/systemd/system/bluetooth.service to enable BT services
sudo sed -i: 's|^Exec.*toothd$| \
ExecStart=/usr/lib/bluetooth/bluetoothd -C \
ExecStartPost=/usr/bin/sdptool add SP \
ExecStartPost=/bin/hciconfig hci0 piscan \
|g' /lib/systemd/system/bluetooth.service

# create /etc/systemd/system/rfcomm.service to enable
# the Bluetooth serial port from systemctl
sudo cat <<EOF | sudo tee /etc/systemd/system/rfcomm.service > /dev/null
[Unit]
Description=RFCOMM service
After=bluetooth.service
Requires=bluetooth.service

# remap bluetooth channel 1 to getty
[Service]
ExecStart=/usr/bin/rfcomm watch hci0 1 getty rfcomm0 115200 vt100 -a root

[Install]
WantedBy=multi-user.target
EOF

# enable the new rfcomm service
sudo systemctl enable rfcomm

# start the rfcomm service
sudo systemctl restart rfcomm

保存该脚本到/root路径下。编辑/etc/rc.local文件,使系统在启动时执行该脚本,在exit 0前添加脚本执行命令。sudo /root/btserial.sh &整个rc.local文件内容如下所示:

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

sudo /root/btserial.sh &

exit 0

保存退出,重启系统后可通过蓝牙登录linux开发板。我这里使用到的是putty进行登录测试。先打开电脑的蓝牙功能,进入到蓝牙配置页面,打开蓝牙更多选项。
在这里插入图片描述
在弹出的窗口下选择COM端口,点击添加按钮,选择传出,添加搜索到的handy_aml设备,确认退出,记下虚拟出的蓝牙端口号。
在这里插入图片描述
打开putty,选择端口方式登录,输入刚才创建好的虚拟蓝牙端口,波特率115200,点击连接,电脑会以蓝牙连接的方式连接linux开发板。
在这里插入图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

lxh1205509119

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值