• Announcements

    • MannDude

      Current state of vpsBoard   02/04/2017

      Dear vpsBoard members and guests:

      Over the last year or two vpsBoard activity and traffic has dwindled. I have had a change of career and interests, and as such am no longer an active member of the web hosting industry.

      Due to time constraints and new interests I no longer wish to continue to maintain vpsBoard. The web site will remain only as an archive to preserve and showcase some of the great material, guides, and industry news that has been generated by members, some of which I remain in contact to this very day and now regard as personal friends.

      I want to thank all of our members who helped make vpsBoard the fastest growing industry forum. In it's prime it was an active and ripe source of activity, news, guides and just general off-topic banter and fun.

      I wish all members and guests the very best, whether it be with your business or your personal projects.

      -MannDude
wlanboy

Creating an WLAN access point with your Raspberry Pi

5 posts in this topic

Install required packages:

sudo apt-get install hostapd dnsmasq

Set static ip to your wlan interface:

nano /etc/network/interfaces

content: (check for a single wlan0 entry!)

iface wlan0 inet static
address 192.168.20.1
netmask 255.255.255.0

Add a configuration to hostap:

nano /etc/default/hostapd

content: (add config file line):

# Defaults for hostapd initscript
# 
# See /usr/share/doc/hostapd/README.Debian for information about alternative
# methods of managing hostapd.
# 
# Uncomment and set DAEMON_CONF to the absolute path of a hostapd configuration
# file and hostapd will be started during system boot. An example configuration
# file can be found at /usr/share/doc/hostapd/examples/hostapd.conf.gz
# 
DAEMON_CONF="/etc/hostapd/hostapd.conf"

If you are not sure what driver is needed check your usb devices (driver name will be disbplayed)

lsusb -t
lsusb -t
/: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=dwc_otg/1p, 480M
|__ Port 1: Dev 2, If 0, Class=vend., Driver=smsc95xx, 480M
|__ Port 5: Dev 3, If 0, Class=vend., Driver=rtl8192cu, 480M

 

Create hostapd.conf:
 

nano /etc/hostapd/hostapd.conf

content:

# interface for ap
interface=wlan0
# driver of wlan stick
driver=rtl871xdrv

ctrl_interface=/var/run/hostapd
ctrl_interface_group=0

# wlan ap configuration
ssid=RaspberryPi
channel=1
hw_mode=g
ieee80211n=0

# wlan security
wpa=2
wpa_passphrase=super-secure-password
wpa_key_mgmt=WPA-PSK
wpa_pairwise=CCMP
rsn_pairwise=CCMP

# country code
country_code=US

 

Add dnsmasq configuration:

nano /etc/dnsmasq.conf

Content: (two important lines)

# Configuration file for dnsmasq.

# If you want dnsmasq to listen for DHCP and DNS requests only on
# specified interfaces (and the loopback) give the name of the
# interface (eg eth0) here.
# Repeat the line for more than one interface.
interface=wlan0
 
# Uncomment this to enable the integrated DHCP server, you need
# to supply the range of addresses available for lease and optionally
# a lease time. If you have more than one network, you will need to
# repeat this for each network on which you want to supply DHCP
# service.
dhcp-range=192.168.20.100,192.168.20.200,255.255.255.0,12h

#set default gateway (if wanted)
#dhcp-option=3,192.168.20.1

 

Restart services:
 

sudo service hostapd restart
sudo service dnsmasq restart

 

Enable IP forwarding:

nano /etc/sysctl.conf

Uncomment:

# Uncomment the next line to enable packet forwarding for IPv4
net.ipv4.ip_forward=1

Activate settings:

sudo sysctl -p

 

Setup forwarding rules:

nano /etc/network/if-up.d/apforwarding && chmod +x /etc/network/if-up.d/apforwarding 

content:

# !/bin/sh
iptables --table nat --append POSTROUTING --out-interface eth0 -j MASQUERADE
iptables --append FORWARD --in-interface wlan0 -j ACCEPT

 

Reboot your Raspberry Pi.

4 people like this

Share this post


Link to post
Share on other sites

Wow thanks for this! I think this might be useful for me if I ever get around to using it!

Share this post


Link to post
Share on other sites

Oh snap.... how did I never catch this before? Gosh, I've been so busy lately. I've been looking for a good tutorial on this, as everyone I've ever found, for one reason or another, has failed me in the past.

 

When I get some free time I plan on reorganizing some things at home and one of the things on my 'to do' list is get one of my Pi's back up. I'll report back!

Share this post


Link to post
Share on other sites
On 2.12.2015 at 1:16 PM, MannDude said:

When I get some free time I plan on reorganizing some things at home and one of the things on my 'to do' list is get one of my Pi's back up. I'll report back!

Any news on your Raspberry Pi?

Share this post


Link to post
Share on other sites

This is a good tutorial I need to bookmark already.

Been doing more and more with ARM platform.  Nothing mega exciting, but more.  Using them more than VPS / dedis these days.

Share this post


Link to post
Share on other sites

  • Similar Content

    • By wlanboy
      They upgraded the Raspberry Pi Model B - called it B+.
      Same price tag with some neat features:
      They upgraded the GPIO header from 26 pins to 40 pins They doubled the USB 2.0 ports to 4. They changed the SD card adapter to Micro SD They replaced the linear regulators with switching ones to reduce the power consumption about 1W. They added a dedicated low-noise power supply for the audio circuit
      Nice looking one.
      They keep the old B model for fans but if you want to buy a Raspberry Pi - take the B+ one.
    • By wlanboy
      Two really cool projects about a detailed map of the Raspberry Pi and the Arduino.
      Move the mouse over one electronic element and the map popups the name and description:
       
      Go to the RaspMap and the ArduMap.
       
    • By wlanboy
      This is the second part of my RaspberryPi tutorial series.
      You can find the first part
      You can find the second part
       
      We now create a sound board:

       
      This time we plit the power lines to make the wirering easier.
      Each button is connected to ground on the buttom side and connected to a line where a GPIO pin and a resistor (the 1k Ohm ones) are connected to the + power line.
      The buttons are connected to the GPIO pins #18, #22, #23, #24 and #25.
      The GPIO pin #17 is connected to the buzzer (PT-1504P).
      The buzzer itself is connected to the ground.
       
      If you like the colorful square buttons -> visit AdaFruit.
       
      Create a script (nano ~/board2.sh) with following content:
      #!/bin/bash echo enable pins 17,18,22,23,24,25 echo 17 > /sys/class/gpio/export echo 18 > /sys/class/gpio/export echo 22 > /sys/class/gpio/export echo 23 > /sys/class/gpio/export echo 24 > /sys/class/gpio/export echo 25 > /sys/class/gpio/export echo setting directions echo out > /sys/class/gpio/gpio17/direction echo in > /sys/class/gpio/gpio18/direction echo in > /sys/class/gpio/gpio22/direction echo in > /sys/class/gpio/gpio23/direction echo in > /sys/class/gpio/gpio24/direction echo in > /sys/class/gpio/gpio25/direction echo 0 > /sys/class/gpio/gpio17/value function callbeep { for (( i = 0; i <= $1; i++ )); do : do echo 1 > /sys/class/gpio/gpio17/value sleep 1 echo 0 > /sys/class/gpio/gpio17/value done } echo start loop while [ 1 ] do value1=`cat /sys/class/gpio/gpio18/value` value5=`cat /sys/class/gpio/gpio22/value` value2=`cat /sys/class/gpio/gpio23/value` value3=`cat /sys/class/gpio/gpio24/value` value4=`cat /sys/class/gpio/gpio25/value` echo $value1 - $value2 - $value3 - $value4 - $value5 if [ $value1 -eq 0 ] then callbeep 1 sleep 1 fi if [ $value2 -eq 0 ] then callbeep 2 sleep 1 fi if [ $value3 -eq 0 ] then callbeep 3 sleep 1 fi if [ $value4 -eq 0 ] then callbeep 4 sleep 1 fi if [ $value5 -eq 0 ] then callbeep 5 sleep 1 fi done echo "done" So what are we doing here?
      Initializing GOIP pins Setting the direction Ensure that the buzzer is deactivated (echo 0) Define the function "callbeep" which Loop $1 + 1 times: Enable buzzer Wait 1 second Deactivate buzzer Start endless loop to check buttons Read states of buttons Call method "callbeep" if button is pressed  
      This time the buttons are connected to the power line +.
      So energy is floating as long as a button is pressed, because if it is pressed the circuit is grounded.
       
      That's it - the third part is finished.
      Hopefully you had some fun.
       
      Please add comments and/or suggestions - both are welcomed.
    • By wlanboy
      This is the second part of my RaspberryPi tutorial series.
      You can find the first part
       
      We now add a third LED and a touch button.

       
      Full view on board:

       
      The third yellow LED is quite simple:
      Connect the cathode of the LED with the - power line Connect the anode of the LED to a resistor (1kOhm) Connect the GPIO #22 to the resistor  
      The push button needs more wires because all inputs of the Raspberry Pi can only be managed with 3.3V.
      You can kill parts of the Raspberry Pi if you set any GPIO pin to input when it is connected to a 5V source!
       
      This is a reason why I like the Arduino because the Arduino can handle outputs and inputs with 5V.
       
      And that is one reason why each breadboard does have two power line sides - one for 5V and one for 3.3V.
       
      Second power line Connect the 3.3V pin to the + line Connect the ground pin to the - line Button Connect the top left side of the button to the + power line Connect the top right side of the button to a resistor (1kOhm) Connect the resistor to the - power line Connect the GPIO #25 to pin between the top right side of the button and the resistor If the button is pressed all pins are connected to each other.
      So the power starts at the 3.3V pin of the Pi, flows through the top left corner to the top right corner.
      Most of the engery cannot pass the resitor and is searching for "another" way - and finds the wire to the GPIO #25.
       
      If someone is listening on the value of the GPIO #25 he/she can check if the button is pressed.
      Because it is a mechanical button and you press them quite hard (in relation to its dimension) the button itself has some vibration that causes some "button pressed" values after the initial press.
      So we have to wait some time before we recheck if the button is pressed.
       
      At this point all tutorials point to Phyton, because it is easier to implement complex checks but I will stick to the bash.
       
      Create a script (nano ~/board.sh) with following content:
      #!/bin/bash echo enable pins 22,23,24,25 echo 22 > /sys/class/gpio/export echo 23 > /sys/class/gpio/export echo 24 > /sys/class/gpio/export echo 25 > /sys/class/gpio/export echo setting directions echo out > /sys/class/gpio/gpio22/direction echo out > /sys/class/gpio/gpio23/direction echo out > /sys/class/gpio/gpio24/direction echo in > /sys/class/gpio/gpio25/direction echo flash green LED echo 1 > /sys/class/gpio/gpio23/value echo 0 > /sys/class/gpio/gpio24/value echo start loop to check button at gpio 25 while [ 1 ] do value=`cat /sys/class/gpio/gpio25/value` echo value of button pin=$value if [ $value -eq 1 ] then echo 1 > /sys/class/gpio/gpio22/value echo flash yellow LED sleep 1 else echo 0 > /sys/class/gpio/gpio22/value echo deflash yellow LED sleep 1 fi done So what are we doing here?
      Export pins to user space Set direction of pins (out(put) and in(put) Enable green LED and disable red LED Start endless loop to check button read value of GPIO #25 check if it is 1 (because it is a digital pin) light yellow LED if it is 1 and disable yellow LED if it is 0 wait 1 second  
      A short video of the button in action:
      https://vimeo.com/87405517
       
      That's it - the second part is finished.
      Hopefully you had some fun.
       
      Please add comments and/or suggestions - both are welcomed.
       
      I have added a second picture with a free sight on the complete board on request.
    • By wlanboy
      This is the start of my RaspberryPi tutorial series.
       
      I will start with the basic stuff first to ensure that everyone who wants to do electronic projects is able to to it with his RaspberryPi.
      All of my old electronic projects are based on the ATmega chips but it is much easier to build up a project with the Raspberry Pi because you have a full stack linux in the background if you need a bash, a network connection or higher programming languages like Javascript, Python or Ruby.
       
      If you want to start you should do yourself a favor and buy a breadboard:

      A breadboard helps to build prototypes fast because it does not require soldering to build connections.
      Additionally you need less wires to build up a circuit because most connections you want to build are allready provided by the breadboard.
       
      The power buses (+/-) are on the left and right side. So once ground is connected to - all other elements connected to one bus are connected to the ground to.
      Same with the power line.
      Between the power lines there are two separated areas where all points of one line are connected to each other.
      So if you put two elements in points of the same line they are connected with each other.
       
      That's it - you know what a breadboard does.
       
      So how does the whole setup look like?

      I use a Cobbler to connect my Raspberry Pi with the breadboard.
      It helps a lot because all wires stick to the board and don't knot on the Raspberry Pi.
       
      We should now look at the wires:
      Orange Grounds the - power line 2x Yellow Both yellow wires do connect the ground line to the cathode of each LED 2x resistors (brown/black/yellow/silver) 1kOhm +/-10% Both resistors connect the anode of each LED with the neighbor side of the breadboard They "protect" the LEDs to ensure that not too much power is transfered Greed and red Connect the Raspberry Pi pins #23 and #24 with the lines of the anodes of the green and red LED  
      So what did we build?
      A circuit - a closed loop of energy.
      E.g. The power level of the pin #23 is set to HIGH, then the power is flowing through the resistor to the anode of the LED.
      The LED emmits light and the rest of the energy is going through the cathode of the LED to the ground of the breadboard and afterwards to the ground of the Raspberry Pi.
       
       
      Time to bring light to the LEDs.
      Open a ssh connection to the Raspberry Pi and sudo.
       
      All pins you want to use have to be exported to the userspace:
      echo 23 > /sys/class/gpio/export echo 24 > /sys/class/gpio/export A gpio looks like that:
      ls -al drwxr-xr-x 3 root root 0 Feb 22 23:30 . drwxr-xr-x 6 root root 0 Apr 9 2013 .. -rw-r--r-- 1 root root 4096 Feb 22 23:30 active_low -rw-r--r-- 1 root root 4096 Feb 22 23:30 direction -rw-r--r-- 1 root root 4096 Feb 22 23:30 edge drwxr-xr-x 2 root root 0 Feb 22 23:30 power lrwxrwxrwx 1 root root 0 Feb 22 23:30 subsystem -> ../../../../class/gpio -rw-r--r-- 1 root root 4096 Feb 22 23:30 uevent -rw-r--r-- 1 root root 4096 Feb 22 23:30 value Afterwards we have to define if the Raspberry Pi should send or receive from the pin: (we want to send = out)
      echo out > /sys/class/gpio/gpio23/direction echo out > /sys/class/gpio/gpio24/direction Now we can enable the pins:
      echo 1> /sys/class/gpio/gpio23/value echo 1> /sys/class/gpio/gpio24/value And disable them:
      echo 0 > /sys/class/gpio/gpio23/value echo 0 > /sys/class/gpio/gpio24/value This can be combined to a bash script:
      nano switchon.sh && chmod +x switchon.sh Content:
      #!/bin/bash echo enable pin $1 echo $1 > /sys/class/gpio/export echo out > /sys/class/gpio/gpio$1/direction echo 1 > /sys/class/gpio/gpio$1/value Call it with the pin number as parameter:
      bash ~/switchon.sh 23 And the green LED is shining.
       
      That's it - the first part is finished.
      Hopefully you had some fun.
       
      Please add comments and/or suggestions - both are welcomed.
       
      The second part of this tutorial can be