控制流程及原理介绍:把pcDuino作为一个WiFi 路由器,视频服务器,可以传输实时视频并接受客户端的控制命令,实现从客户端控制小车的移动和摄像头的旋转。
一、把pcDuino变成WiFi无线路由器
pcDuino官网公布的内核一般情况下只有WiFi STA模式的驱动, 也没有IP forwarding的软件 iptables。 所以我们第一步需要替换pcDuino内核uImage 。
在这章用到的所有的文件能在
https://s3.amazonaws.com/linksprite/pcduino/wifiAP.rar 这里下载。
把wifiAP 拷贝到ubuntu 目录:
- ubuntu@ubuntu :~$ ls
- Desktop Downloads Pictures Templates c_enviroment wifiAP
- Documents Music Public Videos sample
- $ sudo mount /dev/nanda /boot
- $ sudo cp uImage /boot -f
- $ sudo cp evb.bin /boot -f
- $ sudo cp 3.4.292B.tar.bz2 /lib/modules/
- $ cd /lib/modules/ubuntu@ubuntu :/lib/modules
- $sudo tar -xvf 3.4.292B.tar.bz2
重启动:
- $sudo reboot
用‘$lsmod’命令查看软件模块:
- root@ubuntu :/home/ubuntu# lsmod

重启动后, 编辑/etc/modules, 去掉 rt5370sta.
- $sudo modprobe rt2800usb
- $echo 148F 5370 > /sys/bus/usb/drivers/rt2800usb/new_id
上面的命令也可以在调试串口编辑。

现在如果我们启动wlan, “$ifconfig wlan3 up”, 我们得到下面的出错信息:
- oot@ubuntu :~# ifconfig wlan3 up
- [ 1043.640000] phy0 -> rt2x00lib_request_firmware: Error – Failed to request
- Firmware.
- SIOCSIFFLAGS: No such file or directory
上面的出错信息表明没有USB WiFi Dongle的固件,我们需要把它放到正确的地方。
用命令“$modinfo rt2800usb” 来发现固件的名字为: rt2870.bin.
- root@ubuntu :~# modinfo rt2800usb
- filename: /lib/modules/3.4.29+/kernel/drivers/net/wireless/rt2x00/rt2800usb.ko
- license: GPL
- firmware: rt2870.bin
- description: Ralink RT2800 USB Wireless LAN driver.
- version: 2.3.0
- author: http://rt2x00.serialmonkey.com
拷贝固件到正确的位置:
- $sudo cp rt2870.bin /lib/firmware/
现在我们再次启动wlan, 就能发现我们有了WiFi连接了!
- ”$sudo ifconfig wlan3 up”
安装iptables:
- $sudo apt-get install iptables vim iw
安装完毕后,检查iptable是否正确安装:
- $sudo iptables -L
- root@ubuntu :~# iptables -L
- Chain INPUT (policy ACCEPT)
- target prot opt source destination
-
- Chain FORWARD (policy ACCEPT)
- target prot opt source destination
-
- Chain OUTPUT (policy ACCEPT)
- target prot opt source destination
下载然后编译hostapd:
编译的过程中需要“libnl-dev” 和 “libssl-dev”.我们需要先安装他们。
- $sudo apt-get install libnl-dev libssl-dev
Hostpad 1.0 可以从
http://hostap.epitest.fi/releases/下载。
完整的命令集为:
找打这行 “#CONFIG_IEEE80211N=y”, 去掉‘#’, 保存然后退出。
- ubuntu@ubuntu :~/hostapd-1.0/hostapd$ cp defconfig .config
-
- ubuntu@ubuntu :~/hostapd-1.0/hostapd$ make
- CC main.c
- CC config_file.c
- CC ../src/ap/hostapd.c
- CC ../src/ap/wpa_auth_glue.c
- CC ../src/ap/drv_callbacks.c
- CC ../src/ap/ap_drv_ops.c
- CC ../src/ap/utils.c
- CC ../src/ap/authsrv.c
-
- ubuntu@ubuntu :~/hostapd-1.0/hostapd$ sudo make install
- mkdir -p /usr/local/bin
- for i in hostapd hostapd_cli; do cp -f $i /usr/local/bin/$i; done
-
检查hostpad 是否安装正确:
- ubuntu@ubuntu :~/hostapd-1.0/hostapd$ hostapd -v
- hostapd v1.0
- User space daemon for IEEE 802.11 AP management,
- IEEE 802.1X/WPA/WPA2/EAP/RADIUS Authenticator
- Copyright (c) 2002-2012, Jouni Malinen <j@w1.fi> and contributors
-
现在我们开始配置hostpad.
我们希望我们的热点有下面的配置:
SSID: ssid=pcduino
Password: wpa_passphrase=1234567890
Encryption: wpa_key_mgmt=WPA-PSK
用下面的方法配置:
- root@ubuntu :~# nano /etc/hostapd.conf
-
- interface=wlan3
- driver=nl80211
- ssid=pcduino
- hw_mode=g
- channel=11
- dtim_period=1
- rts_threshold=2347
- fragm_threshold=2346
- macaddr_acl=0
- auth_algs=1
- ieee80211n=0
- wpa=2
- wpa_passphrase=1234567890
- wpa_key_mgmt=WPA-PSK
- wpa_pairwise=TKIP
- rsn_pairwise=CCMP
-
注意: wlan3 变了, 我们必须一直用 ‘‘ifconfig” 来检查。
配置好了后,我们用下面的命令来检查配置:
- root@ubuntu :~# hostapd -dd /etc/hostapd.conf
- random: Trying to read entropy from /dev/random
- Configuration file: /etc/hostapd.conf
- nl80211: interface wlan4 in phy phy0
- rfkill: initial event: idx=0 type=2 op=0 soft=0 hard=0
- rfkill: initial event: idx=1 type=1 op=0 soft=0 hard=0
- nl80211: Using driver-based off-channel TX
- nl80211: Register frame command failed (type=208): ret=-114 (Operation already in progress)
- nl80211: Register frame match – hexdump(len=1): 06
- nl80211: Failed to register Action frame processing – ignore for now
- nl80211: Add own interface ifindex 5
- nl80211: Set mode ifindex 5 iftype 3 (AP)
- nl80211: Create interface iftype 6 (MONITOR)
- nl80211: New interface mon.wlan4 created: ifindex=7
- nl80211: Add own interface ifindex 7
- BSS count 1, BSSID mask 00:00:00:00:00:00 (0 bits)
- nl80211: Regulatory information – country=00
- nl80211: 2402-2472 @ 40 MHz
- nl80211: 2457-2482 @ 40 MHz
- nl80211: 2474-2494 @ 20 MHz
- nl80211: 5170-5250 @ 40 MHz
- nl80211: 5735-5835 @ 40 MHz
- nl80211: Added 802.11b mode based on 802.11g information
- Allowed channel: mode=1 chan=1 freq=2412 MHz max_tx_power=20 dBm
- Allowed channel: mode=1 chan=2 freq=2417 MHz max_tx_power=20 dBm
- Allowed channel: mode=1 chan=3 freq=2422 MHz max_tx_power=20 dBm
- Allowed channel: mode=1 chan=4 freq=2427 MHz max_tx_power=20 dBm
- Allowed channel: mode=1 chan=5 freq=2432 MHz max_tx_power=20 dBm
- Allowed channel: mode=1 chan=6 freq=2437 MHz max_tx_power=20 dBm
- Allowed channel: mode=1 chan=7 freq=2442 MHz max_tx_power=20 dBm
- Allowed channel: mode=1 chan=8 freq=2447 MHz max_tx_power=20 dBm
- Allowed channel: mode=1 chan=9 freq=2452 MHz max_tx_power=20 dBm
- Allowed channel: mode=1 chan=10 freq=2457 MHz max_tx_power=20 dBm
- Allowed channel: mode=1 chan=11 freq=2462 MHz max_tx_power=20 dBm
- Allowed channel: mode=0 chan=1 freq=2412 MHz max_tx_power=20 dBm
- Allowed channel: mode=0 chan=2 freq=2417 MHz max_tx_power=20 dBm
- Allowed channel: mode=0 chan=3 freq=2422 MHz max_tx_power=20 dBm
- Allowed channel: mode=0 chan=4 freq=2427 MHz max_tx_power=20 dBm
- Allowed channel: mode=0 chan=5 freq=2432 MHz max_tx_power=20 dBm
- Allowed channel: mode=0 chan=6 freq=2437 MHz max_tx_power=20 dBm
- Allowed channel: mode=0 chan=7 freq=2442 MHz max_tx_power=20 dBm
- Allowed channel: mode=0 chan=8 freq=2447 MHz max_tx_power=20 dBm
- Allowed channel: mode=0 chan=9 freq=2452 MHz max_tx_power=20 dBm
- Allowed channel: mode=0 chan=10 freq=2457 MHz max_tx_power=20 dBm
- Allowed channel: mode=0 chan=11 freq=2462 MHz max_tx_power=20 dBm
- Completing interface initialization
- Mode: IEEE 802.11g Channel: 11 Frequency: 2462 MHz
- nl80211: Set freq 2462 (ht_enabled=0 sec_channel_offset=0)
- RATE[0] rate=10 flags=0×1
- RATE[1] rate=20 flags=0×1
- RATE[2] rate=55 flags=0×1
- RATE[3] rate=110 flags=0×1
- RATE[4] rate=60 flags=0×0
- RATE[5] rate=90 flags=0×0
- RATE[6] rate=120 flags=0×0
- RATE[7] rate=180 flags=0×0
- RATE[8] rate=240 flags=0×0
- RATE[9] rate=360 flags=0×0
- RATE[10] rate=480 flags=0×0
- RATE[11] rate=540 flags=0×0
- Flushing old station entries
接下来,我们安装dhcp 服务器:
- $sudo apt-get install dhcp3-server
安装完毕后,配置dhcp服务器:
- $sudo nano /etc/dhcp/dhcpd.conf
在文件的最后加下面几行:
subnet 192.168.0.0 netmask 255.255.255.0
{
range 192.168.0.2 192.168.0.10;
option routers 192.168.0.1; #router address
option domain-name-servers 8.8.8.8;
}
{
range 192.168.0.2 192.168.0.10;
option routers 192.168.0.1; #router address
option domain-name-servers 8.8.8.8;
}
重启hostapd:
配置 pcDuino的 WiFi IP 地址:
- root@ubuntu :~# ifconfig wlan4 192.168.0.1
打开DHCP:
- root@ubuntu :~# dhcpd wlan4 -pf /var/run/dhcp-server/dhcpd.pid
- Internet Systems Consortium DHCP Server 4.1-ESV-R4
- Copyright 2004-2011 Internet Systems Consortium.
- All rights reserved.
- For info, please visit https://www.isc.org/software/dhcp/
- Wrote 0 leases to leases file.
- Listening on LPF/wlan4/00:c3:16:a0:03:00/192.168.0.0/24
- Sending on LPF/wlan4/00:c3:16:a0:03:00/192.168.0.0/24
- Sending on Socket/fallback/fallback-net
使能IP forwarding:
- root@ubuntu :~# echo 1 >/proc/sys/net/ipv4/ip_forward
设置NAT:
- root@ubuntu :~# iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
当上面的配置都完成后, 我们可以看到一个名字为"pcduino"的热点!
注:调试的时候,用ifconfig查看自己的wifi,需根据实际情况修改wlan。
原文转至:http://www.pcduino.org/forum.php?mod=viewthread&tid=112&extra=page%3D1