hostapd configuration/Wifi Hotspot setup

Raspberry Pi related support

hostapd configuration/Wifi Hotspot setup

Postby cmh714 » 14 Nov 2014, 21:41

After much trials and errors, I have the RPi set as a hotspot. I used a script I found so all credit goes there. Not sure this is the best way to go about it, but until its baked in better, this seems to work. The script is very configurable for different connection scenarios.

So for my test setup, I have the Pi connected via Ethernet so I can configure the wifi to be a Wifi hotspot and basically stand-alone. The scenario could be many, but for me I wanted to be able to take the Pi wherever and connect to it via phone over wifi and stream music from the Pi without the Pi being connected to any other network. I tried first with an ad-hoc network setup but I could not for the life of me get that working.

Links and instructions coming....Stay tuned :)
cmh714
 
Posts: 417
Joined: 04 May 2014, 03:06

Re: hostapd configuration/Wifi Hotspot setup

Postby cmh714 » 14 Nov 2014, 21:57

Pre-requisites: Depending on your needs, you will need to get: dnsmasq and/or bridge-utils. Everything else we have already. Command for fetching: "pacman -S dnsmasq bridge-utils"
The example below only needed dnsmasq since I didnt need a Bridge.

This is the link to the script from github: https://github.com/oblique/create_ap
I recommend you read it and decide which settings you will need as I cannot go into all of them and everyone will want this setup a little differently depending on their needs.

There are 2 files you need from the above link: create_ap and create_ap.service
the create_ap file needs to be in the /usr/bin/ directory and it needs to be executable (chmod +x)
the create_ap.service file needs to be in the /etc/systemd/system/ directory and should be executable as well.
I had to select the RAW link, copy the file, and then open vi or nano, and paste it in.

From the instructions in the link decide which parameters you want for create_ap. You can test this all from the commandline, the script will run in your terminal window so you should see output, and when you connect you will see more output. When you have it working as you want, then edit the create_ap.service file to reflect the commandline parameters you want. Save the file.

To enable it, such that it starts at boot, use the command "systemctl enable create_ap"

ENJOY!! :)
cmh714
 
Posts: 417
Joined: 04 May 2014, 03:06

Re: hostapd configuration/Wifi Hotspot setup

Postby cmh714 » 14 Nov 2014, 22:35

Ok so for some reason when you enable this as a service so it can get started automatically, the wifi will start properly but then I get disconnected for some reason and cannot get reconnected, even though the interface says its up.

Using the command "systemctl start create_ap" works just fine, but after using enable is where it begins to fail. Will keep loking for the solution but look forward to others comments.
cmh714
 
Posts: 417
Joined: 04 May 2014, 03:06

Re: hostapd configuration/Wifi Hotspot setup

Postby cmh714 » 14 Nov 2014, 23:04

Ok, so when its a service for some reason the interface does NOT get an IP. If you run "systemctl restart create_ap" then it comes back up properly and is stable....unfortunately, jamming that into rc.local isnt working, so I keep trying :)
cmh714
 
Posts: 417
Joined: 04 May 2014, 03:06

Re: hostapd configuration/Wifi Hotspot setup

Postby cmh714 » 16 Nov 2014, 16:42

W00t!!!! Got this working very well. For anyone interested in how to write a killer bash script, I would recommend you take the script apart and figure out how it works. Really good stuff.

So after not being able to make the script work on startup automatically, I tried a bunch of things. First I figured it was some race condition so I tried reordering systemd stuff, but couldnt make that work. Then I figured I would take apart the script and just use what I need and install dnsmasq and try to make dnsmasq and hostapd work via systemd in a similar way to the scripts but I had the same experience, the interface would come up, but I could not attach correctly.

So then I went back to the script.....and back to a race condition.....and found NIRVANA :)

SOLUTION: edit the create_ap script, about 20 or so lines from the bottom, BEFORE the # Start dns + dhcp server section, put in a "sleep 15", save and reboot. You should have your WAP up and running. Trying 10 seconds failed, but 15 works fine.

I hope someone else will enjoy this :)
cmh714
 
Posts: 417
Joined: 04 May 2014, 03:06

Re: hostapd configuration/Wifi Hotspot setup

Postby rathmannm » 10 Dec 2014, 08:03

Thank you very much for sharing this. I am really struggling to get an AP working so I have come across your method but unfortunately this results in an error as well:

No Internet sharing
hostapd command-line interface: hostapd_cli -p /tmp/create_ap.wlan0.conf.Ho43xPzU/hostapd_ctrl
Configuration file: /tmp/create_ap.wlan0.conf.Ho43xPzU/hostapd.conf
nl80211: Driver does not support authentication/association or connect commands
nl80211 driver initialization failed.
hostapd_free_hapd_data: Interface wlan0 wasn't started

Error: Failed to run hostapd, maybe a program is interfering.

Any chance you have come across this or have any idea on how to resolve it?

Thanks,
Manuel
rathmannm
 
Posts: 2
Joined: 29 Nov 2014, 17:17

Re: hostapd configuration/Wifi Hotspot setup

Postby cmh714 » 10 Dec 2014, 16:25

Hmm, not sure on your errors but I will try and look at my setup...

I did not set the firewall up for Internet sharing so you would need to change that behavior. Look into the script and find the bridge section, IIRC.
cmh714
 
Posts: 417
Joined: 04 May 2014, 03:06

Re: hostapd configuration/Wifi Hotspot setup

Postby Mat » 26 Aug 2015, 07:30

cmh714 thank you for this. It was very simple to setup WiFi hotspot with your help and with create_ap script. Indeed wery powerfull script.

I had the same issue as rathmannm. Solution is simple, just increase sleep time as cmh714 suggested (in my case to "sleep 25"). I guess that runeaudio tries to setup WiFi adapter every time it boots and create_ap should be executed after runeaudio WiFi configuration. Otherwise runeaudio overrides results of create_ap script. If you have slower sd card you might need more sleep time to wait for runeaudio.
Mat
 
Posts: 21
Joined: 01 Jul 2015, 12:19

support RuneAudio Donate with PayPal


Return to Raspberry Pi

Who is online

Users browsing this forum: cmh714 and 9 guests