天天看点

android wifi热点 信道,wifi 热点配置最优信道(示例代码)

wifi热点服务hostapd启动需要配置hostad.conf文件,其中有一个参数channel是用来配置信道的,信道的可选参数如下:

# channel 1-14 is 2.4 GHz ; channel 36, 40, 44, 46, 48, 52, 56, 60,

# 64, 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 149,

# 153, 157, 161 is 5GHz

# The channels that are available for use in a particular country differ

# according to the regulations of that country.

如果只是要配置正确在可选范围内随便填一个就可以了,但是如果需要选出一个当前环境下最优的一个信道,就需要动动手指了。

我们需要戒指iwlist工具来扫描一下,然后就可以找到最优信道了

ifconfig wlan0 up

iwlist wlan0 scan

iwlist wlan0 scan

iwlist wlan0 scan

扫面了三次,现在我们可以去看下最优信道是哪个了,我的网卡是rtl8188eu,通过以下指令获取

[[email protected]_p3 /]# cat /proc/net/rtl8188eu/wlan0/best_channel

The rx cnt of channel 1 =8

The rx cnt of channel 2 = 11

The rx cnt of channel 3 = 12

The rx cnt of channel 4 = 15

The rx cnt of channel 5 = 20

The rx cnt of channel 6 = 31

The rx cnt of channel 7 = 22

The rx cnt of channel 8 = 17

The rx cnt of channel 9 = 13

The rx cnt of channel 10 = 12

The rx cnt of channel 11 = 14

The rx cnt of channel 12 = 9

The rx cnt of channel 13 = 7

The rx cnt of channel 14 = 0

best_channel_5G = 36

best_channel_24G = 1

[[email protected]_p3 /]#

如果没有走scan扫描直接去cat 那么channel后面接收到的数据包全都是0

The result of “cat /proc/net/rtl…/wlan0/best_channel” has two parts. The first

part is received packet count at all supported channels during site survey.

Developers can use these statics to decide your own best channel. The second

part is the simple estimated best channels for 5G and 2.4G band for reference

only. HT40+ rule is used to estimate the best channel when the primary

channel is at 1, 6, 36, 44, etc., and the primary channel with minimum

received packet count is selected

我们要找的是计数包最小的那个通道(14通道除外),类似于干扰最小的信道。

wifi热点启动后我们可以在手机上安装wifi魔盒一类的wifi查看器,查看当前环境下的各个热点、信道、信号质量等信息。

android wifi热点 信道,wifi 热点配置最优信道(示例代码)