Single

香蕉派(Banana Pi)的正确吃法之开热点

前言

最近参展有个小车要做,我的想法是,开热点,mjpg-streamer,然后通过web控制就行了,找开热点的教程时看到了这个(https://blog.csdn.net/keyue123/article/details/53411609)用ap-hostpot的,但是好像这个库已经不在了,文章中用的链接已经打不开了,于是自己写一个吧。(这个教程后面有时间再探索,应该有镜像备份吧)
这里我用的是BPI-M2 Pro,系统是2021-06-21-ubuntu-20.04-server-bpi-m5-m2pro-aarch64-sd-emmc.img.zip
将系统写到emmc之后(具体教程看这里),可以直接开始了

正文

这个系统默认是没有开wlan0的,所以要手动打开

sudo ifconfig wlan0 10.5.5.1/24 up

将wlan0和eth0配置为桥连

sudo nano  /etc/netplan/50-cloud-init.yaml

可能还有其他名字,不过也一样
添加wifis和bridges,改后如下

# This file is generated from information provided by the datasource.  Changes
# to it will not persist across an instance reboot.  To disable cloud-init's
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
    ethernets:
        eth0:
            dhcp4: true
            match:
                macaddress: 02:00:00:20:03:01
            set-name: eth0
    wifis:
        wlan0:
            access-points:
            opennetwork: {}


    bridges:
        br0:
            interfaces: [eth0, wlan0]
            dhcp4: true
            dhcp6: true
  version: 2

接着需要安装hostapd

sudo apt update
sudo apt install hostapd

配置wifi文件

sudo nano /etc/hostapd/hostapd.conf

下面是我用的配置文件(具体配置设置可以看这里https://wiki.gentoo.org/wiki/Hostapd#802.11a.2Fn.2Fac_with_WPA2-PSK_and_CCMP

# AP使用的接口
interface=wlan0
# "g" 意思是2.4GHz的WiFi
hw_mode=g
# 使用的channel
channel=10
# 将使用的频率限制为该国允许的频率
ieee80211d=1
# the country code
country_code=FR
# 802.11n support
ieee80211n=1
wmm_enabled=1
ssid=BPI-Car
auth_algs=1
wpa=2
wpa_key_mgmt=WPA-PSK
rsn_pairwise=CCMP
wpa_passphrase=bananapi

ctrl+x,y,回车保存
接下来运行下面命令就能开启热点

sudo hostapd /etc/hostapd/hostapd.conf -B

这时能够搜到wifi了,但是连不上去,应为没有安装dhcp server,导致设备无法获取到ip
安装isc-dhcp-server

sudo apt install isc-dhcp-server

然后编辑文件/etc/default/isc-dhcp-server,将wlan0设置为INTERFACES:

sudo nano /etc/default/isc-dhcp-server

添加一下代码

INTERFACES="wlan0"

编辑/etc/dhcp/dhcpd.conf
sudo nano /etc/dhcp/dhcpd.conf
添加以下代码

subnet 10.5.5.0 netmask 255.255.255.0 {
  range 10.5.5.26 10.5.5.30;
  option domain-name-servers 8.8.8.8;
  option routers 10.5.5.1;
  option broadcast-address 10.5.5.255;
  default-lease-time 600;
  max-lease-time 7200;
}

重启dhcp

sudo service isc-dhcp-server restart

配置开机启动

sudo nano /etc/rc.local

添加以下代码

#!/bin/bash
sudo ifconfig wlan0 10.5.5.1/24 up
sleep 4

sudo service isc-dhcp-server restart
echo 1| sudo tee /proc/sys/net/ipv4/ip_forward
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
sudo hostapd /etc/hostapd/hostapd.conf -B

sudo chmod 755 /etc/rc.local

#!/bin/bash

#sudo nmcli radio wifi off
#sudo rfkill unblock wlan
sudo ifconfig wlan0 10.5.5.1/24 up
sleep 4

sudo service isc-dhcp-server restart
echo “1” > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
sudo hostapd /etc/hostapd/hostapd.conf -B

/home/pi/mjpg/mjpg_streamer -i “/home/pi/mjpg/input_uvc.so” -o “/home/pi/mjpg/output_http.so -w /home/pi/mjpg/www”

暂无评论

发表评论

zh_CNChinese