Wednesday, October 23, 2013

Raspberry Pi using as access point

Hostapd + dnsmasq for Raspberry Pi 

Last time I used Android phone as a keyboard and mouse to remotely control the RPi X-server, but it required WiFi connection to login the RPi if I need to control the terminal. 

This time I tried to make RPi work as an access point to directly communicate with Android phone.
  1. hostapd settingsInstall hostapd package.
    sudo apt-get install bridge-utils hostapd
    Get hostpad that is for the RTL8188CUS chipset which is used for Edimax EW-7811Uh.
    wget http://dl.dropbox.com/u/1663660/hostapd/hostapd.zipunzip hostapd.zip
    Replace the hostapd that is installed with the package.
    sudo mv /usr/sbin/hostapd /usr/sbin/hostapd.original
    sudo mv hostapd /usr/sbin/hostapd.edimax
    sudo ln -sf /usr/sbin/hostapd.edimax /usr/sbin/hostapd
    sudo chown root.root /usr/sbin/hostapd
    sudo chmod 755 /usr/sbin/hostapd
    If eth0 and wlan0 need to be bridged, edit the interfaces file.
     sudo nano /etc/network/interfaces
    Modify the file as below. (after the part related to wlan0)
    auto br0
    iface br0 inet dhcp
    bridge_ports eth0 wlan0
     Create hostapd.conf file
    sudo nano /etc/hostapd/hostapd.conf
    Add the following lines.
    interface=wlan0
    driver=rtl871xdrv
    bridge=br0
    ssid=[NETWORK NAME]
    channel=6
    wmm_enabled=0
    wpa=1
    wpa_passphrase=[PASSWORD]
    wpa_key_mgmt=WPA-PSK
    wpa_pairwise=TKIP
    rsn_pairwise=CCMP
    auth_algs=1
    macaddr_acl=0
    Run hostapd and see if network is detected by Android phone.
    sudo hostapd -dd /etc/hostapd/hostapd.conf
    Modify hostpad file if you want to run hostapd at the startup.
    sudo nano /etc/default/hostapd
    Uncomment "DAEMON_CONF" in the file and add the path to the file.
    DAEMON_CONF="/etc/hostapd/hostapd.conf"
    Reboot the system and see if hostapd is automatically run.
    sudo shutdown -r now


  2. dnsmasq settings
    hostapd is to make it RPi as access point.
    Now, we install dnsmasq to automatically assign the IP address to the clients.
    Install dnsmasq.
    sudo apt-get install dnsmasq
    This will automatically start the dnsmasq, so stop it.
    sudo service dnsmasq stop
    Create the new configuration file.
    sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.original
    sudo touch /etc/dnsmasq.conf
    Edit the file as below.
    interface=wlan0
    expand-hosts
    domain=local
    dhcp-range=10.0.0.10,10.0.0.20,24h
    dhcp-option=3,10.0.0.1
     Edit the interfaces file again.
    sudo nano /etc/network/interfaces
    Comment out or delete the part modified previously, then modify it as below. (section1) 
    #auto br0
    #iface br0 inet dhcp
    #bridge_ports eth0 wlan0
    iface wlan0 inet static
    address 10.0.0.1
    network 10.0.0.0
    netmask 255.255.255.0
    broadcast 10.0.0.255
     Reboot the RPi
    sudo shutdown -r now
    

  3. Connecting the Android phone to RPi
    After rebooting RPi, you will see the network name on your phone.
    Connect to the network and make sure the IP is obtained.
    Then, launch the SSH apps and try login RPi.
    I used "ConnectBot" app.
    You can also use "Simple Computer Remote" app to control the RPi once X-server is started.

Hardware:
    Raspberry Pi
    EW-7781Uh WiFi dongle

    PS Vita Portable Charger 
   
Summary:
RPi is now connected to an Android phone directly without WiFi network.
This will allow me to access to RPi at anywhere.


Reference:     
http://willhaley.com/blog/raspberry-pi-hotspot-ew7811un-rtl8188cus/
http://ariandy1.wordpress.com/2013/04/07/setting-up-wifi-access-point-with-edimax-ew-7811un-on-raspberry-pi/

1 comment:

  1. Can we setup RPI as access pt to do video streaming to android phone?? Using gstreamer as mentioned by u prev.?

    ReplyDelete