0

In order to reach my Raspberry Pi 3 B +, I need it to broadcast an access point upon booting.

I am aware that there are common issues with crontab @reboot and systemctl running when networking is still down.

I have a working access point setup; however, the code seems to fail only when started through a service, ap.

When I manually execute the following script, ap.sh, it successfully initiates an access point (touch yes.txt lets me know it has run):

#!/bin/bash
cd /home/pi/ap/
sleep 30
ifconfig wlan0 down
iwconfig wlan0 mode monitor
ifconfig wlan0 up
ifconfig wlan0 up 192.168.1.1 netmask 255.255.255.0
hostapd hostapd.conf &
touch yes.txt

(hostapd hostapd.conf & works, along with the rest of ap.sh)

However, as I mentioned before, I need a service to run this script, and so I made ap.service:

[Install]
WantedBy=multi-user.target
[Unit]
Description=Access Point Service
Wants=network-online.target
After=network-online.target
[Service]
User=root
Group=root
ExecStart=/home/pi/ap/ap.sh
ExecStartPre=/bin/sleep 10
Type=simple

After my Pi boots, I see the following message when I check service status ap:

Nov 17 00:27:18 raspberrypi systemd[1]: Starting Access Point Service...
Nov 17 00:27:28 raspberrypi systemd[1]: Started Access Point Service.
Nov 17 00:27:28 raspberrypi ap.sh[590]: Error for wireless request "Set Mode" (8B06) :
Nov 17 00:27:28 raspberrypi ap.sh[590]: SET failed on device wlan0 ; Operation not supported.

As I understand it, the error is being thrown by hostapd. I'm not sure why though, since ap.sh works perfectly well and the ap service is run by root.

Also, the service successfully sleeps for thirty seconds, initiates wlan0 with an IP address, and creates yes.txt in /home/pi/ap, meaning that the failure seems to be isolated in hostapd

Any help would be much appreciated!


Jaromanda X
  • 2,415
  • 1
  • 13
  • 14

1 Answers1

1

As far as I see you only want to setup a stand alone access point but there are some things mixed up. First you are using deprecated commands ifconfig and iwconfig. You should use its modern successors ip from iproute2 and iw.

Everywhere you are using sleeps. When nothing works a sleep mostly helps but it indicates that there is something wrong with service dependencies.

Then you want to use monitor mode to spy your neighbors WLAN networks but this mode isn't needed for an access point and it isn't supported by the built-in wifi device on a Raspberry Pi at all. And this is what you give the error message

Nov 17 00:27:28 raspberrypi ap.sh[590]: Error for wireless request "Set Mode" (8B06) :
Nov 17 00:27:28 raspberrypi ap.sh[590]: SET failed on device wlan0 ; Operation not supported.

Just don't use it.

In ap.sh you manage everything by hand but interfaces are usually managed by dhcpcd or systemd-networkd. hostapd is managed by its service and started with sudo systemctl start hostapd.service. You do it again in ap.sh and send it to the background with &. If you want to run it as daemon you should use its option -B. But ap.sh is called by the ap.service that starts programs to run as service in the background and this background service sends hostapd into the background, hmm... To start a program running oldstyle as daemon you should use Type=forking in the systemd unit but not starting it within a bash script. But as said there is already a service to start/stop hostapd.

As you see there is much to do to clean up your setting. I suggest you start over again with a new setup. For example there isn't much to do to by following this Setting up a Raspberry Pi as an access point - the easy way and look at section Setting up a stand alone access point.

Ingo
  • 42,107
  • 20
  • 85
  • 197