树莓派4B openwrt 接入手机蓝牙共享网络教程

手机usb 共享网络给 openwrt 依赖内核模块
确认 OpenWrt 系统是否已经安装了需要的内核模块。
支持安卓:kmod-usb-net-rndis
支持苹果:kmod-usb-net-ipheth usbmuxd

手机蓝牙共享网络接入openwrt
Smartphone Bluetooth Tethering

https://openwrt.org/docs/guide-user/hardware/bluetooth/bluetooth.tether

  1. 方案以 openwrt: 23.05.3 版本、手机为红米note9手机为例
    因openwrt 禁用了树莓派4B的蓝牙设备,需要准备一个usb蓝牙设备

  2. 安装usb蓝牙驱动 参照如下
    https://openwrt.org/docs/guide-user/hardware/bluetooth/usb.bluetooth

  3. 参照文档 https://openwrt.org/docs/guide-user/hardware/bluetooth/bluetooth.tether
    配置 手机蓝牙共享网络接入openwrt 配置

3.1 安装依赖包
Required OpenWrt packages:
kmod-input-uinput
bluez-daemon
bluez-utils
dbus
dbus-utils

3.2 Modify Default Configuration files

In /etc/bluetooth/main.conf, change the last line to AutoEnable=true
In /etc/dbus-1/system.d/bluetooth.conf, add

<allow send_type="method_call"/>
<allow send_type="method_return"/>

to the root policy block. The root policy block should now look like

3.3 Pair and Trust Smartphone

While logged into your OpenWrt device, type in the command bluetoothctl.

Make sure that your smartphone Bluetooth is enabled and then issue the command scan on.

Wait for your smartphone Bluetooth MAC address to appear and then type pair XX:XX:XX:XX:XX:XX where XX represents the Bluetooth MAC address of your smartphone. For example, for my IPhone, I type pair 50:BC:96:9D:DD:21 and accept any pins.

When your smartphone has paired successfully, type trust XX:XX:XX:XX:XX:XX where XX represents the Bluetooth MAC address of your smartphone. For example, for my IPhone, I type trust 50:BC:96:9D:DD:21

命令如下:
先打开手机设置-》我的设备-》全部参数-》状态信息中-》蓝牙地址
记录下蓝牙地址信息 9C:5A:81:14:C1:85 为例
3.3.1 执行 bluetoothctl pair 9C:5A:81:14:C1:85 , 弹出确认信息中 yes
3.3.2 执行 bluetoothctl trust 9C:5A:81:14:C1:85

3.4 Connect To Your Smartphone

执行 dbus-send --system --type=method_call --dest=org.bluez /org/bluez/hci0/dev_9C_5A_81_14_C1_85 org.bluez.Network1.Connect string:‘nap’
其中 9C_5A_81_14_C1_85 换成自己手机的蓝牙地址, 注意:手机个人热点中 蓝牙网络共享打开, 此时蓝牙中会显示连接到openwrt设备上

While logged into your OpenWrt device with the default Access Point configuration, issue the following command

dbus-send --system --type=method_call --dest=org.bluez /org/bluez/hci0/dev_XX_XX_XX_XX_XX_XX org.bluez.Network1.Connect string:‘nap’
where XX represents the Bluetooth MAC address of your smartphone. For example, for my IPhone, I would type the command

dbus-send --system --type=method_call --dest=org.bluez /org/bluez/hci0/dev_50_BC_96_9D_DD_21 org.bluez.Network1.Connect string:‘nap’
You should now get an indication on your smartphone that your OpenWrt router is connected. Get an IP address and route your Internet traffic though your smartphone by issuing the following commands.

uci set network.wan=interface
uci set network.wan.proto=‘dhcp’
uci set network.wan.ifname=‘bnep0’
uci commit
ifup wan
The output of the ifconfig command should now contain a block which looks something like the below

bnep0 Link encap:Ethernet HWaddr 5C:F3:70:9B:95:CD
inet addr:172.20.10.14 Bcast:172.20.10.15 Mask:255.255.255.240
inet6 addr: fe80::5ef3:70ff:fe9b:90cb/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:11071 errors:0 dropped:0 overruns:0 frame:0
TX packets:11379 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:4383378 (4.1 MiB) TX bytes:1936379 (1.8 MiB)
Note that HWaddr is the Bluetooth MAC address of the USB Bluetooth dongle connected to your OpenWrt device.

If your smartphone becomes separated from your OpenWrt router, simply re-issue the command

dbus-send --system --type=method_call --dest=org.bluez /org/bluez/hci0/dev_XX_XX_XX_XX_XX_XX org.bluez.Network1.Connect string:‘nap’
This process can be easily automated by writing a script using the l2ping command. The script I use with my IPhone is below

#!/bin/sh
while [ 1 ]
do
if [ ! -e /proc/sys/net/ipv4/conf/bnep0 ]
then
if [ $(l2ping -c 1 50:BC:96:9D:DD:21 2>/dev/null | grep -c “1 received”) = 1 ]
then
dbus-send --system --type=method_call --dest=org.bluez /org/bluez/hci0/dev_50_BC_96_9D_DD_21 org.bluez.Network1.Connect string:‘nap’
fi
fi
sleep 30
done
When I take my IPhone away from my stationary OpenWrt router and then return, my OpenWrt router will re-tether to my IPhone for Internet access within 30 seconds.

3.5 进入 openwrt 管理控制台
在网络-》接口中 点击添加新接口 名称bluewan ,设备指定 bnep0 设备, 防火墙设置中 选择wan , 高级设置中 使用网关跃点15(越高级别越低)
保存并应用后, 测试网络是否正常

3.6 设置负载均衡
进入 openwrt 管理控制台
网络-》负载均衡 -》接口-》添加 名称 : bluewan , 跟踪的主机或ip地址 www.baidu.com (测试网络连通)
网络-》负载均衡 -》成员-》添加 名称 : blue_wan 跃点数 15, 权重:2(越低级别越低)
网络-》负载均衡 -》策略-》修改 添加 blue_wan
网络-》负载均衡 -》规则 使用 默认balanced 规则

在状态-》负载均衡 中查看状态是否正常

3.7 自动连接设置
创建/opt/shell/bluewifi.sh 文件
内容如下:
#!/bin/sh
while [ 1 ]
do
if [ ! -e /proc/sys/net/ipv4/conf/bnep0 ]
then
if [ $(l2ping -c 1 9C:5A:81:14:C1:85 2>/dev/null | grep -c “1 received”) = 1 ]
then
dbus-send --system --type=method_call --dest=org.bluez /org/bluez/hci0/dev_9C_5A_81_14_C1_85 org.bluez.Network1.Connect string:‘nap’
fi
fi
sleep 300
done

其中 9C:5A:81:14:C1:85 和 9C_5A_81_14_C1_85 为共享网络手机的蓝牙地址

执行 chmod a+wrx /opt/shell/bluewifi.sh 授权执行权限

在 /etc/init.d 文件下 创建没有后缀名的 bluenet 文件,内容如下
#!/bin/sh /etc/rc.common

START=99

start() {
echo “bluenet started”
sh /opt/shell/bluewifi.sh > /dev/null&
echo “bluenet started finished”
}

执行 chmod a+wrx/etc/init.d/bluenet 授权执行权限

进入openwrt 管理控制台
系统-—》启动项 中 搜索 bluenet ,点击已禁用 变为 启用状态, 重启后,自动连接已开启蓝牙共享网络,并打开蓝牙的手机网络。

  • 16
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
树莓派4B可以安装OpenWrt系统。首先,准备硬件和软件环境。硬件环境包括一台电脑(使用笔记本,WIN7系统)、一张TF卡(存储空间16GB以上)和读卡器,以及树莓派4B。软件环境包括系统烧入软件(如balenaEtcher)、telnet/ssh软件(如putty)和openwrt镜像文件(可以从openwrt官网下载对应的镜像文件)。 接下来,将TF卡插入树莓派4B,并将电脑的IP地址配置为192.168.1.X网段。然后启动putty,并使用ssh连接192.168.1.1。连接后,默认登录用户为root,没有密码。可以进入系统后使用passwd命令设置密码。 最后,在GitHub的https://github.com/SuLingGG/OpenWrt-Rpi/releases/tag/bcm27xx-bcm2711页面中下载openwrt-bcm27xx-bcm2711镜像文件。 请注意,树莓派4BOpenWrt安装过程需要按照具体环境和版本进行操作,建议参考官方文档或相关教程以获得更详细和准确的步骤说明。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [树莓派4B搭建openwrt系统和WEB服务](https://blog.csdn.net/wazh012/article/details/109168375)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *3* [树莓派4b刷入OpenWrt-2022年增强篇](https://blog.csdn.net/u011536031/article/details/122769087)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值