First, thx all for the answers combined they led me to this configuration ( I voted them all up).
Following, the different bash scripts I used for my setup:
Setup a custom local address
The dns.sh
setup a custom local DNS entry. This entry enables devices within the network to access the device, the user does not need to know/type an IP address into his browser address bar.
dns.sh
function customDNS() {
echo "starting local dns setup\n"
#fixed local ip
yes | apt-get install avahi-daemon
sed -i 's/raspberrypi/somename/' /etc/hosts
sed -i 's/raspberrypi/somename/' /etc/hostname
/etc/init.d/hostname.sh
echo "finished local dns setup\n"
#access point
apt-get install iw #Wireless tools
sudo apt-get install hostapd #Host Access Point Daemon
#config access point
cat $1/wlan.config > /etc/hostapd/hostapd.conf
chmod 600 /etc/hostapd/hostapd.conf
#add to autostart
echo DAEMON_CONF="/etc/hostapd/hostapd.conf" >> /etc/default/hostapd
#manual start with hostapd -dd /etc/hostapd/hostapd.conf
#router functions
Y | sudo apt-get install dnsmasq
cat $1/dnmasq.config >> /etc/dnsmasq.conf
}
wlan.config
This is the configuration for the wifi hotspot. The user can connect to this wifi hotspot in order to be able to see the somename.local
. This is important because both devices need to be in the same network to see each other.
# WLAN-Router
INTERFACE & DRIVERS
interface=wlan0
#driver=nl80211
WLAN-CONFIG
ssid=someName #name of the wifi
channel=1
hw_mode=g
wmm_enabled=1
country_code=DE
ieee80211d=1
ignore_broadcast_ssid=0#1 is hidden, 0 visible
auth_algs=1
WLAN-ENCRYPTION
wpa=2
wpa_key_mgmt=WPA-PSK
rsn_pairwise=CCMP
wpa_passphrase=somepassword
dnmasq.config
I'm not quite sure if this is required at all. I think it can be skipped. But I still have the problem, that my hotspot is not recognized as a valid hotspot. So some devices disconnect from it after a while. But this maybe because they try to address some IPs e.g.I read IOS devices check apple.com
#DHCP-Server activ for wifi interface
interface=wlan0
DHCP-Server non active for existing network
no-dhcp-interface=eth0
IPv4 & lease time
dhcp-range=192.168.1.2,192.168.1.254,24h
#DNS
dhcp-option=option:dns-server,192.168.1.1
Setup a Local Server
I setup a local server with nodejs serving my website to localhost:80
this can be accessed via http://somename.local
Connecting to users wifi
I made a setup page where the user can enter his wifi credentials. These are then added to /etc/wpa_supplicant/wpa_supplicant.conf
with
printf 'network={%s\n\tssid=\"#{wifi.name}\"%s\n\tpsk=\"#{wifi.pass}\"%s\n}' >> /etc/wpa_supplicant/wpa_supplicant.conf
At the same time the hotspot is deactivated, otherwise I guess the raspberry will not be able to connect to the wifi.
sed -i '/DAEMON_CONF/s/^/#/g' /etc/default/hostapd
I reboot the pi then and check if the wifi connection is active. I plan a rollback of the last steps if not.
When booting the server I send a message with websockets to the front end to notify the user about the successful reboot. The wifi is usually connected automatically by the device to the users original wifi (the hotspot no longer exists).
pros & Cons
Pros
- No cables needed
- users know how to connect to a wifi
- users know how to fill input fields
Cons
- devices are not connecting properly to the hotspot, they show it as no internet connection, or skip the connection after a while (I opened up a sperate thread for this issue: Open Splash Page After Connecting to Wifi Hotspot )
- it's still a bit of setup to connect to a wifi hotspot first and then enter your credentials
raspberrypi.local
? – Dmitry Grigoryev Nov 17 '16 at 09:22