Search code examples
raspberry-piraspbianraspberry-pi3

trying to start /usr/sbin/hostapd in a script conditionally


this code is running on a raspberry pi3

i have a script /etc/rc2.d/S05frameapp that conditionally starts hostapd ( looks to see if wifi has been setup or not)

in the script(this section gets run if no wifi has been setup set for this device)

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 &

from the nohup , in the /tmp/hostapd.log i see

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

but if i now log in (via hardwired network) and run the following it works...

#/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

so i am kinfod thinking this may be a timing issue? that is why i currently have the script run S05

thanks for any help


Solution

  • I found the issue. it is the order of starting hostapd and dnsmasq

    the fix is you need to start dnsmasq first, then start 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 &