尝试有条件地在脚本中启动/ usr / sbin / hostapd

时间:2017-05-22 16:23:52

标签: raspberry-pi raspbian raspberry-pi3

此代码在raspberry pi3上运行

我有一个脚本/etc/rc2.d/S05frameapp,有条件地启动hostapd(看看是否已经设置了wifi)

脚本中的

(如果没有为此设备设置wifi,则此部分会运行)

echo "restarting etho"
/sbin/ifup wlan0

echo "Starting hostapd";
/usr/bin/nohup /usr/sbin/hostapd -B -P /var/run/hostapd.pid /etc/hostapd/hostapd.conf >> /tmp/hostapd.log 2>&1 &

echo "Starting dnsmasq ";
/usr/sbin/service dnsmasq start;

echo "Starting wifi_config node";
cd /home/wifi_listener/
/usr/bin/nohup /usr/local/bin/node app.js >> /tmp/nodeapp.log 2>&1 &

来自nohup,在/tmp/hostapd.log中我看到了

cat /tmp/hostapd.log
Configuration file: /etc/hostapd/hostapd.conf
Failed to create interface mon.wlan0: -95 (Operation not supported)
Could not set channel for kernel driver
Interface initialization failed
wlan0: interface state UNINITIALIZED->DISABLED
wlan0: AP-DISABLED
wlan0: Unable to setup interface.
hostapd_free_hapd_data: Interface wlan0 wasn't started

但如果我现在登录(通过硬连线网络)并运行以下内容,则可以正常运行...

#/usr/sbin/hostapd -B -P /var/run/hostapd.pid /etc/hostapd/hostapd.conf
Configuration file: /etc/hostapd/hostapd.conf
Failed to create interface mon.wlan0: -95 (Operation not supported)
wlan0: Could not connect to kernel driver
Using interface wlan0 with hwaddr b8:27:eb:40:bd:a4 and ssid 
"WhatUlooknAtWillis"
wlan0: interface state UNINITIALIZED->ENABLED
wlan0: AP-ENABLED

所以我认为这可能是一个时间问题?这就是为什么我目前有脚本运行S05

感谢您的帮助

1 个答案:

答案 0 :(得分:1)

我发现了这个问题。 这是启动hostapd和dnsmasq的顺序

修复是你需要先启动dnsmasq,然后启动hostapd

echo "Starting dnsmasq ";
/usr/sbin/service dnsmasq start

echo "Starting hostapd";
/usr/bin/nohup /usr/sbin/hostapd -B -P /var/run/hostapd.pid /etc/hostapd/hostapd.conf >> /tmp/hostapd.log 2>&1 &