Hotspot – WiFi Access Point

When I was thinking of buying Raspberry Pi few months ago, I was also about to buy 3G router/AP. When I learned what RPi is, and I saw people trying to make AP out of it, I knew where to place my money :) I know I’ve chosen right… RPi as AP gives you enormous number of possibilities: wireless streaming of cartoons to your tablet when you’re in the car. Your wife (if you have one already ;) ) in the same time can watch Desperate Housewives… and you can focus on pleasure from driving. I hope you’re interested already so let’s do it.

Note: this tutorial assumes that your RPi already detects your WiFi dongle. If you need to install it, please check our other tutorial.
Please make sure your WiFi dongle supports AP mode. This tutorial and script was tested with TP-LINK WN725N based on RTL8188CUS chipset.

I know there have been many tutorials on how to do this, but I believe there is none that would be a complete guide for total newbie. I had to compile information from few tutorials to set everything right. Let’s go step by step and I will try to explain what and why you need to set up. There will be surprise at the end of article so so not miss anything :)

Before we’ll go to WHAT, I will try to explain WHY.

What AP needs to be capable of to be AP :) :

  • 1. Inform devices about AP existence (Broadcast SSID) or at least allow clients to connect
  • 2. Authenticate client
  • 3. Assign IP to the client devices
  • 4. Route packages to the “output” network and the other way around

In order to handle all of this, RPi needs the following tools:

  • hostapd – Host AccessPoint Daemon – will take care of 1.
  • wpa-supplicant – tool responsible for WPA authorization for 2.(most likely you have it installed already)
  • isc-dhcp-server – will take care of 3.
  • ip-tables – will take care of 4. (most likely you’ll have this installed already)

Let’s install these tools:

First we’ll take care of configuration of AP daemon and it’s security – we do it in /etc/hostapd/hostapd.conf .

NOTE: If you copy-paste hostapd.conf from our tutorial, remove comments. (thanks Arnold)

Now we need to set up /etc/hostapd/hostapd.conf as the configuration file. We do it in /etc/default/hostapd. Put the following line there:

OK, perfect. Now let’s configure the network settings for clients connecting to AP. We do it in /etc/dhcp/dhcpd.conf

Again we need to make sure that DHCP server uses this configuration. In /etc/default/isc-dhcp-server put the following lines:

The last line indicates network interface that will be serving DHCP requests.

We’re almost done. Let’s configure wlan0 for static IP adress (the same as router IP in dhcpd.conf file.
We do it in /etc/network/interfaces:

The last line will set routing rules after restart.
Let’s turn on packet forwarding in /etc/sysctl.conf by making sure that line

is un-commented or added.

We will configure routing now by executing (assuming eth0 is your WAN interface):

and lets save these setting in a file:

Because I had bloody RTL8188CUS chipset I had to replace original hostapd with the one prepared for my chipset.

In order to start AP on boot run the following commands:

We are done! Now restart your RPi:

There is much easier way to do all of this :) Use our configuration script and have AP set up in 2 minutes!

If something does not work, please check if there are any duplicate entries in /etc/network/interfaces – if true, remove them and check again.

Let me know if something does not work! just comment on the article.

Great articles that helped a lot:

http://www.jenssegers.be/

http://www.raspberrypi.org/phpBB3/viewtopic.php?t=31227

Here is your raspberry pi ampilight system!
  • http://www.irt.org/ Martin Webb

    One thing not clear from this article or any other article on hotspots and ad-hoc networks, is once set up and fully working, is it possible to SSH into the RPi from an ipad/iphone, or does setting the hotspot up just allow the ipad/iphone to simply use the RPi as a means to connect onwards through the RPi to other networks?
    I really need to be able to simply SSH into the RPi from an ipad/iphone when there are no other networks avaiable – e.g. when both the RPi and ipad/iphone are side-by-side, and I have no other keyboard/screen.

    • http://raspberry-at-home.pl/ Tomasz Szczerba

      Martin, I tested your scenario – raspberry pi served as a router with no connection to internet. I was able to connect with putty to it. I don’t own ipad/iphone and cannot test them but that should make no difference ;) Great idea btw. full control of raspi with only tables/smartphone :)

      • Jacek

        I have tested Raspi AP with an iPad. I was able to connect via SSH without any problem.

        • Arnold Kok

          Me too… I used ServerAuditor which is for free in the store.

        • Toni Torres Marí

          I also was able to connect with my android mobile phone via ssh to the rpi, but only if it’s connected to the ethernet cable, otherwise doesn’t connect. Can you confirm if this is it or only happening to me because I did something wrong? Thanks for this great script bdw

  • William Louis Roach-Barrette

    First I want to say, thanks for the article. I have been working on a rover using a RPi as a learning tool. Your script should help me no longer require a router to accompany the rover as I take it to classrooms. I do have a question however regarding how exactly to see what the RPi’s default ip address is so i can ssh into it. When i do an ifconfig I see no address to connect to and I will admit I no very little about the subtleties of networking. So, how exactly do i go about figuring out or assigning an ip address to the RPi so i can ssh into it?

    On another note, I also need to host a webpage on the Pi that students can access once they are connected. As it stands, when i try to launch the server “using a python script that I designed with the webiopi libraries” It throws up an error and will not display the ip address and port needed to access the webpage. Any ideas? Thanks for all your help thus far with the tutorial, If you could assist me with this it would be greatly appreciated

    • Jacek

      William, let me address your first question (I can’t tell how to help you with the second one)…

      The IP that your looking is defined in /etc/dhcp/dhcpd.conf as

      option routers 192.134.3.1 ; #your client’s gateway / router IP.

      Of course, your IP can be different depending on what the IP is in this line in your particular configuration. The other way to get the IP is to check network settings of the device you connect to RPi AP. RPi AP IP will be always a gateway at client’s network configuration.

      Let me know if that’s not clear…

      • William Louis Roach-Barrette

        Jacek, Thanks for the response. I examined the dhcpd.conf file and found:
        option router 192.168.1.1 ;
        to be the ip address. However, when I tried to ssh into the pi from a computer connected to it via wifi it timed out. I am sorry but I did not understand your second explanation about how to check the network settings. Could you explain it to me in greater detail?

        Here is some additional information that may or may not be causing an issue. On boot up I receive a few failed messages. These are the failures I receive as I launch the pi:
        [….] Configuring network interfaces…/etc/network/interfaces:11: interface wlan0 declared allow-hotplug twice
        ifup: couldn’t read interface file “/etc/network/interfaces”
        failed.

        [FAIL] check syslog for diagnostics …. failed!
        failed!
        [FAIL] startpar: service(s) returned failure: isc-dhcp-server … failed!

        • Jacek

          That’s weird. Can you share your interfaces file?

    • http://raspberry-at-home.pl/ Tomasz Szczerba

      Hi William,

      About hosting webpage on raspi, you gave us too little information to work with. What does error message say? What kind of web server you use?

      On a side note, I’m working on a couple of articles about using raspi as a web server but they are yet to come. Just to give you heads up – try cherooke ( http://cherokee-project.com/ ) it looks promising, it isn’t a resource hog as apache and it’s easy to setup and work with. Hovewer, if you have some time to spare try lighttpd ( http://www.lighttpd.net/ ) it’s faster and lighter than above but more complicated to setup.

      • William Louis Roach-Barrette

        Sorry for not being clear before. I modified the code from this tutorial to both create and program the rover I am using. http://trouch.com/2013/03/04/webiopi-in-the-magpi-cambot-tutorial/

        when I launch the server I receive the following output:

        2013-06-14 14:31:02 – WebIOPi – INFO – GPIO – Native mapped to RESET API /GPIO
        2013-06-14 14:31:02 – WebIOPi – INFO – Access protected by using login/password
        2013-06-14 14:31:02 – WebIOPi – INFO – HTTP Server binded on http://localhost:8000/

        Traceback (most recent call last):
        File “server.py”, line 93, in

      • William Louis Roach-Barrette

        Sorry for not being clear before. I modified the code from this tutorial to both create and program the rover I am using. http://trouch.com/2013/03/04/webiopi-in-the-magpi-cambot-tutorial/

        The web server worked fine until I ran this script, which im assuming has caused some conflicts that need to be resolved. When I launch the server I receive the following output:

        2013-06-14 14:31:02 – WebIOPi – INFO – GPIO – Native mapped to RESET API /GPIO
        2013-06-14 14:31:02 – WebIOPi – INFO – Access protected by using login/password
        2013-06-14 14:31:02 – WebIOPi – INFO – HTTP Server binded on http://localhost:8000/
        Traceback (most recent call last):
        File “server.py”, line 93, in
        2013-06-14 14:31:02-WebIOPi-INFOO-CoAP Server binded on coap://localhost:5683/

        File “/usr/local/lib/python2.7/dist-packages/WebIOPi-0.6.0-py2.7-linux-arm61.egg/webiopi/server.py”, line 153, in _init_ self.coap_server.enableMulticast()
        File “/usr/local/lib/python2.7/dist-packages/WebIOPi-0.6.0-py2.7-linux-arm61.egg/webiopi/server.py”, line 469, in enableMulticast return getattr(self._sock,name)(*args)
        socket.error: (Errno 19) No such device

        Thanks again for all your help thus far, I am at this point a little in over my head

        • http://raspberry-at-home.pl/ Tomasz Szczerba

          Perhaps you should try and find which line fails. Unfortunately It’s hard for me to say anything more helpful than that.

  • Arnold Kok

    Hi,

    After having tried several forum posts, using your post, I finally got my Raspberry Pi to work as an Access Point. I am very new to Linux, so I most of the time literally copied your suggestions (unless I know that I wanted something else (i.e. IP-ranges)).

    I had to install isc-dhcp-server twice… got a message about LSB script. The hostapd didn’t start. Seems like the issues I had before.

    Used the following command to troubleshoot:
    sudo hostapd -dd /etc/hostapd/hostapd.conf

    It showed that the information in /etc/dhcp/dhcpd.conf was incorrect.
    As I literally copied your suggestions there, I also included the remarks trailing on each line. Appearently that is not allowed. Removed all remarks. And now it seems to work!
    Thanks.
    Arnold

    • Jacek

      Thanks for the comment. I’m happy that the article was helpful. Thank you for the note about comments in hostapd.conf. I have added appropriate warning in the article.
      Cheers
      Jacek

  • Baseer

    I had to update this file to get this going

    /etc/network/interfaces:11: interface wlan0 declared allow-hotplug twice
    ifdown: couldn’t read interfaces file “/etc/network/interfaces”
    /etc/network/interfaces:11: interface wlan0 declared allow-hotplug twice
    ifup: couldn’t read interfaces file “/etc/network/interfaces”

    GREAT ARTICLE btw!!!

  • Paul

    Can’t believe how long I’ve been trying the various methods out there to set my Pi as an Access Point on Raspbmc, and finally this foolproof guide did the trick! You’re a star, thanks very much!

    P.S. Any idea why hostapd still works if I don’t specify the driver? It’s always been like that for me… The driver within syslog says it is rt2800usb. No matter, it works! :)

    • Jacek

      Thanks :)

      Your “P.S.” is quite interesting :) Are you using Raspi default version of hostapd?

      • Paul

        Yep, nothing changed there. I just don’t have the driver entry at all within /etc/hostapd/hostapd.conf

  • Ender

    So everything worked except when I reboot my RPi and check the status of isc-dhcp-server ($ sudo service isc-dhcp-server status) it says it is not running. I then check hostapd and that is running fine. So I try to manually start isc-dhcp-server ($ sudo service isc-dhcp-server start) and it fails. It is not until I “$ sudo ifdown wlan0″ and then “$ sudo ifup wlan0″ that I can manually start isc-dhcp-server. I have a TP-Link 725N v2.

    Any help on this matter would be greatly appreciated as I have searched the internet and not been able to find anything similar. Thank you.

    • Ender

      Nevermind. It seems to be working now. Was not working on the first 3 reboots or so and then all of a sudden, now it works with every reboot. Did not change anything so I am not sure what happened.

      • Jacek

        Actually I had exactly the same issue with v1 of 725N after latest Raspbmc update. I was about to put a note in the article that it is not working anymore and suddenly it got fixed :)
        You wrote that you managed to start AP on 725N v2 – i tried to do this but couldn’t start hostapd. Could you share what hostapd version are you using (default or downloaded from our site) and what is in your hostapd.conf file?

        • Ender

          The original problem I posted still remains. I thought it had fixed itself but alas it has not. isc-dhcp-server fails to start on boot up and when I try to start it manually it fails unless I do ifdown/ifup wlan0.

          Hostapd, on the other hand, is working fine. It loads on boot up everytime. I am not sure exactly what version of hostapd I am using since I followed so many tutorials to try to get this to work (without success). I am pretty sure I am using whatever hostapd was downloaded when I did $ sudo apt-get install hostapd. As for the .conf file, it is exactly how you have it in your article (minus the comments).

  • thomas

    Great article JaceK! Thank you.

    The ap_setup.sh script worked perfect on “Rasbian 2013-05-25-wheezy-raspbian” fresh install, with TL-WN725N. I also had the problem with dhcp server. I solved it by restarting both hostapd and isc-dhcp-server on start up. I used /etc/rc.local file for this.

    $ sudo nano /etc/rc.local

    and added these lines:

    sudo service hostapd stop
    sudo service isc-dhcp-server stop
    sudo ifdown wlan0
    sudo ifup wlan0
    sudo service hostapd restart
    sudo service isc-dhcp-server restart

    and then reboot rasp.

    • Jacek

      Thanks for sharing! :)

  • Chris Blaxhall

    Awesome work.
    I couldn’t get the RPI to reload iptables on boot with any combination of up, pre-up or post-up and instead used a script in if-up.d as per http://virtualitblog.blogspot.com.au/2013/05/installing-iptables-on-raspberry-pi.html
    Now works a treat.
    Thanks for the great work.

  • drmaq

    I have a problem where the script terminates after I choose one of my two wireless adapters. please see attached log output form the program

    • Jacek

      Does the script terminate at this step?

      • drmaq

        Yes

      • codac

        I have the same problem, as I’d love to use your script in order to create a wifi repeater without eth0

        • Jacek

          Have you tried to go through the tutorial and change the parts that are responsible for routing? Script may not be prepared for your needs.

          • codac

            Yes I’ve done that. The AP works, but all of a suddon I can’t ping the router, neither 8.8.8.8 or any other IP outside of the RasPi. Any idea what might be the issue?
            How do I check if the client has properly connected to the specified WiFi?
            Maye its the iptables?

  • Andrzej Pruszynski

    I’ve got D-Link Wireless N150 Micor USB Adapter which announces itself as Realtek RTL8188CUS (lsusb). I used Jacek / Tomek script and near everything went as expected but double entry: ‘/etc/network/interfaces:11: interface wlan0 declared allow-hotplug twice’ reported already too months ago by Baseer.

    In order to be able to configure Access Point (AP) on the fly and see clients status, etc., I suggest to add ‘ctrl_interface=/var/run/hostapd’ line to /etc/hostapd/hostapd.conf file. After restarting the hostapd or your PI AP, you can use command:

    sudo hostapd_cli

    Another interesting thing about RTL8188CUS is a possiblity of reducing power consumption by using appropriate parameter while inserting driver module.

    Consumed current (in mA), by default, is:

    – associated idle: 85.6
    – unassociated idle: 80.2
    – associated Idle (enable power save) – LPS: 34.5
    – unassociated Idle (enable power save) – IPS-NORMAL: 18.9
    – unassociated Idle (enable selective suspend): 0.72

  • Jaap van den Dries

    Hi Jacek,

    Before I buy an TP-LINK WN725N (I’ve now a wrong adapter) I want to ask you this: I have a model A, without ethernet. My intention making the RPi an AP is to download pictures from it made with a time-lapse script, somewhere in the field. I just want to connect to the RPi with SSH, sharing internet or 3G is not important.

    Is that possible, can I just follow your instructions to the letter?

    • Jacek

      Jaap,

      I cannot think of a reason why it would not. Please remember to download hostapd and remaining packages first.
      Jacek

  • devnull

    Thanks, nice job, it works like a charm but I need I little help from my friends :)
    I configured wlan0 as AP (192.168.10.X) and wlan1 as WAN, yes, I’m using my rpi as a WiFi repeater and my problem is that I’d like to use a printer connected to eth0 (static 192.168.10.168) via CUPS but clients connected to wlan0 (AP) can’t see 192.168.10.168, ping says that IP is unreachable
    What I’m doing wrong? Any ideas?

    • Jacek

      I assume you’re using DHCP server… What is the netmask in /etc/dhcp/dhcpd.conf?

      • devnull

        /etc/network/interfaces

        auto lo
        iface lo inet loopback

        iface eth0 inet static
        address 192.168.10.10
        netmask 255.255.255.0

        auto wlan0
        allow-hotplug wlan0
        iface wlan0 inet static
        address 192.168.10.1
        netmask 255.255.255.0
        up iptables-restore < /etc/iptables.ipv4.nat

        allow-hotplug wlan1
        iface wlan1 inet dhcp

        /etc/dhcp/dhcpd.conf

        ddns-update-style none;
        default-lease-time 86400;
        max-lease-time 86400;
        subnet 192.168.10.0 netmask 255.255.255.0 {
        range 192.168.10.2 192.168.10.9 ;
        option domain-name-servers 8.8.8.8, 8.8.4.4 ;
        option domain-name "home";
        option routers 192.168.10.1 ;
        }

        Printer has an static IP too. 192.168.10.11
        Hosts connected to wlan0 can't reach eth0 (now 192.168.10.10) neither printer on eth0 (192.168.10.11)

        • Jacek

          Hi devnull,
          How did you configure iptables? You should have replaced eth0 with wlan1.
          If you did that, can you share your client (connected via wlan0) network settings? Can you reach (ping) your printer directly from Raspberry?

          Jacek

          • devnull

            I fixed the problem making a bridge between wlan0 and eth0

            iface br0 inet static
            bridge_ports eth0 wlan0
            address 192.168.10.1

            Thanks a lot

  • Jaap van den Dries

    Damn, first step! I get an error after typing “sudo apt-get -y install hostapd isc-dhcp-server iptables wpa_supplicant” > Unable to locate package wpa_supplicant, rebooted, I get many red warning from dhcp-server and more, and the same error when I try “sudo apt-get install wpa_supplicant” for the second time.

    • Jacek

      Jaap, as I wrote previously, you need to download all packages required for the installation and install them using offline. I guess you can also try connecting through your wifi adapter to the Internet and install packages online. At some point you will loose connection (especially, if you’re using our script), but at that time all packages should be already downloaded and installed.

  • Jaap van den Dries

    I have a model A so i presume that i can/must skip the routing and iptables

    • Jacek

      Yes, you don’t have a target to route to :)

  • Mario Neudeck

    Thanks for the good how to.
    My question regards to the weak signal. I use the RTL8188CUS chipset.
    Do you agree that one has only a good signal if one is in the same room like the Pi? When I leave the room the signal becomes very weak. Only if I’m in front of the Pi the signal is really good.
    I’m asking because it could also be possible that there is a misconfiguration. But I don’t think so because I took your how to.
    I would like to use the Pi to connect to a tor network. But if the signal is as weak as now it does not make any sense.
    Thanks,
    Mario

  • Albol

    I have certainly had much more success with your method than any of the other net-postings and have reached a stage where my pi is broadcasting it’s SSID. Devices trying to connect cannot get an IP and when I try to ping the pi’s eth0 static IP it returns no results. Also, if I run X on the pi with startx, then run Midori, it will not connet to the net. Something is obviously screwing eth0’s connection during your ap_setup.sh process, as eth0 initially works as I have done the whole procedure using SSH. I’ve tried this now from scratch, reinstalling Wheezy twice. Any ideas?

    • Jacek

      Can you share your interfaces file together with /etc/network/interfaces.bak file (produced by our script)? please send it to my email jacek @ raspberry – at – home . com

      As with regards to the problem with clients of AP, have you checked the logs of isc-dhcp-server?

  • Herschelle

    hey. thanks for the awesome script.
    i tried many others and none worked.

    i ran your script and rebooted and i could see the RPi SSID but not connect.
    i removed the “allow-hotplug wlan0″ from /etc/network/interfaces and rebooted and my phone connected on the first try.

    so something in your script works where the others did not.

    now to figure out how to get the xbmc remote on my phone to connect to the pi :)

    thanks again

  • Wrechid

    Hello, this is a great script for raspbmc… I tried it on xbian and it wouldn’t work… After running the script, xbian wouldn’t boot… :/ With raspbmc the wifi dongle indicater did not start blinking until I ran your script, but with xbian it’s blinking right after initial install of xbian… Is it possible that since xbian has already initialized the dongle that your script is unable to gain access to it…?

    • Jacek

      Hi,
      I would check /etc/network/interface if there are any diplicated entries. Our script is NOT the state of the art. It can do some misconfiguration if assumptions that we’ve made, are not true in particular version of the linux distribution. I would advice you to go through our tutorial and verify all the steps if they are not corrupting your default setup on Xbian.

      • Wrechid

        hello again… you was right… not sure about diplicated entries, but
        the interface file needed a few changes… one of the devs (mk01) over
        at the XBian forums help me through it… thanx again for the script…
        :)

        • codac

          Hello, your script got the same error, if two wifi adapters are present. The menu asks which adapter you want to chose. As soon as you select the adapters number, the script just quits.
          Furthermore I have the problem that with eth0, I have a proper internet connection. I can ping 8.8.8.8 from the RasPi. I do see the AP from wlan0 as well. Connecting to the AP with a netbook requires much longer than a normal connection. After the netbook is connected it shows, that the connection is limited. The netbook can’t ping eth0 or wlan0 and the RasPi cannot ping the netbook, although its connected to wlan0’s AP.
          Anny suggestion what the root cause might be?

          • Wrechid

            hello codac… yea, both scripts have the same objective, mine just has modified user inputs… i’ve never tried using 2 wifi dngles but now that it is brought up i’m looking into it now…

            as for the prolonged connect time while using eth0 as internet (WAN) connection, try using a different wireless channel… channels 1, 6, and 11 are the common ones…
            also, which xbmc distribution are you using, RaspBMC, XBian, etc…?

          • codac

            Thanks a lot Wrechid! Looking forward to the fix.

            Alright, I’ll try to change the channel.
            Unfortunately I’m not using XBMC, I’m using Wheezy Raspbian 25.09.2013 (http://www.raspberrypi.org/downloads) and (http://downloads.raspberrypi.org/raspbian_latest)
            As I’m using the RTL8188CUS chipset I’ve already changed the hostapd version to the one described by the tutorial.

          • Wrechid

            ok, i’m not setup for rasbian at the moment… i’ll install that later and verify it there… i did fix the little glitch after selecting which wlan to use… download my script from above, i updated it… also, try to keep eack wifi dongle on different channels… since they are so close to each other, they’ll interfere with each other…

          • codac

            Hey Wrechid, sorry for the very late reply.
            I was finally able to successfully test your two wifi dongle script (ap_setup_beta.sh) on the newest version of Wheezy (2014-01-07).
            I’ve made some changes to the script in order to improve the dialogue and in order to enable my iPhone 4S to connect to the Pi as well.
            I’d like to share the script, where am I supposed to send it to?

          • Wrechid

            hello codac,
            i didn’t forget about ya… i did get it to work on Raspbian, i’m just trying to fix the script so that it makes the adjustments for Raspbian…

          • codac

            Heya Wrechid, you’re a true lifesaver!
            I’ll test your script today as soon as I’m back home.
            Two things that I already recognized is:
            1. It would be nice to make the DHCP optional. In my case there is already a router running the DHCP, unfortunately I am not the owner of that router, so currently with the RasPi there would be two DHCP servers in one network.
            2. The AP always gets the “.1″ at the end of the network-ip address (for example 192.168.2.1). As I mentioned at 1. there is already a router present which has 192.168.2.1 and is actually the gateway. So I would need to set the APs IP address to another one (in my case 192.168.2.200), which I currently do on the last step where the menu offers to manually edit the /etc/network/interfaces file.

          • Wrechid

            Hello codac,
            I do see your point, but with an AP, it’s usually better to put it in a different IP range than what your primary router… Notice that the default IP for the AP is set at 192.168.10.1… That way the second dhcp server doesn’t interfere with the common 192.168.2.1 or 192.168.1.1 ones… And you’ll still get Internet through the RPi… :)
            I will look into the optional last number, but allowing to many variables gets confusing and more problems to the less experienced… :)

          • codac

            I have to admit you’ve got quite a point there :D
            Ok, so I’ve tried to set up two wifi adapters wlan0 being the WAN port and wlan1 being the ap. I can connect to the ap but with a limited connection and I won’t get a dhcp assigned ip address.

            /etc/hostapd/hostapd.conf:
            interface=wlan1
            ssid=pwned
            channel=1
            # WPA and WPA2 configuration
            macaddr_acl=0
            auth_algs=1
            ignore_broadcast_ssid=0
            wpa=2
            wpa_passphrase=supersecret
            wpa_key_mgmt=WPA-PSK
            wpa_pairwise=TKIP
            rsn_pairwise=CCMP
            # Hardware configuration
            driver=rtl871xdrv
            ieee80211n=1
            device_name=RTL8192CU
            manufacturer=Realtek
            hw_mode=g

            /etc/network/interfaces:
            auto lo

            iface lo inet loopback
            iface eth0 inet dhcp

            allow-hotplug wlan0
            ##iface wlan0 inet manual
            ##wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
            ##iface default inet dhcp
            iface wlan0 inet dhcp
            wpa-ssid “WLAN 12″
            wpa-psk “supersecret”
            allow-hotplug wlan1
            iface wlan1 inet static
            address 192.168.1.1
            netmask 255.255.255.0
            subnet 192.168.1.0
            up iptables-restore < /etc/iptables.ipv4.nat

            /etc/iptables.ipv4.nat:
            # Generated by iptables-save v1.4.14 on Mon Dec 2 21:53:00 2013
            *filter
            :INPUT ACCEPT [0:0]
            :FORWARD ACCEPT [0:0]
            :OUTPUT ACCEPT [0:0]
            -A FORWARD -i wlan0 -o wlan1 -m state –state RELATED,ESTABLISHED -j ACCEPT
            -A FORWARD -i wlan1 -o wlan0 -j ACCEPT
            COMMIT
            # Completed on Mon Dec 2 21:53:00 2013
            # Generated by iptables-save v1.4.14 on Mon Dec 2 21:53:00 2013
            *nat
            :PREROUTING ACCEPT [0:0]
            :INPUT ACCEPT [0:0]
            :OUTPUT ACCEPT [0:0]
            :POSTROUTING ACCEPT [0:0]
            -A POSTROUTING -o wlan0 -j MASQUERADE
            COMMIT
            # Completed on Mon Dec 2 21:53:00 2013

            /etc/wpa_supplicant/wpa_supplicant.conf:
            ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
            update_config=1

            /etc/default/hostapd:
            DAEMON_CONF="/etc/hostapd/hostapd.conf"

            /etc/dhcp/dhcpd.conf:
            ddns-update-style none;
            default-lease-time 86400;
            max-lease-time 86400;
            subnet 192.168.1.0 netmask 255.255.255.0 {
            range 192.168.1.2 192.168.1.9 ;
            option domain-name-servers 8.8.8.8, 8.8.4.4 ;
            option domain-name "home";
            option routers 192.168.1.1 ;
            }

            /etc/default/isc-dhcp-server:
            DHCPD_CONF="/etc/dhcp/dhcpd.conf"
            INTERFACES="wlan1"

            /etc/sysctl.conf:

            net.ipv4.ip_forward=1

          • Wrechid

            hello codac,
            everything there looks correct… one thing that caught my eye though is the wlan0 connecting to a ssid with a space in it… normally that isn’t a problem, but it still makes me wonder… are you able to ping after setting up the first wlan0…? try “ping -c 1 google.com”… i’ll add a space to my setup and see if it still works…
            what method are you using to set this up…? (ssh or terminal from Raspbian desktop)

            if you are using a usb hub, remember to give the hub separate power… the rpi will also need good power since wifi dongles do require a lot…

            when i set it up on my end, i do everything from ssh, without loading the raspbian desktop… i’m pretty sure that the wifi config tool that comes with raspbian would cause problems… what size sd card are you using…? i think a minimum of 4gb would be needed…

          • Wrechid

            just verified that it does work with spaces in the ssid… another thing, after the script is completely done and you do the last reboot, did you unplug the wired network…? with that plugged in, it will cause the dhcp server to fail…

          • codac

            Wrechid I didn’t forget to reply, I’m currently waiting for the delivery of new wifi adapters (EDIMAX EW-7811UN) as I currently think there might be hardware issues in the way…

          • Wrechid

            hello codac,
            i’ve tested this many more times… i even hooked up my usb hub so i could use a keyboard and mouse to try without ssh… i’ve tried it without loading Raspian desktop, and also tried it from with in the desktop using the LXTerminal… the only problem i had was when i try to put both wifi dongles in the usb hub at once… the hub kept freezing… as long as i unplugged the wired network afterwards and did a reboot, it worked every time… only other thing i can think of is something with your hardware setup… :/ keep me posted, will do what ever i can…

          • Wrechid

            i’ve verified that the space in ssid is not a problem… i did notice
            that both wifi adapters in the usb hub can be a problem… try putting
            one adapter in the rpi and the other in the usb hub… you’ll have to
            re-setup everything from scratch when moving the adapters to different
            usb ports…

          • Wrechid

            hello codac,
            i got a beta setup, would you please try it for me…? i’ve tested it a few times on a fresh install of Raspbian… i did everything from a ssh shell with both wifi dongles plugged in and wired connection (eth0) for ssh… before you run the script be sure to Expand Filesystem option from within raspi-config… i found that to be one problem for the iptables running out of room…
            http://wrechid.com/ap_setup_beta.sh

          • mk01

            @disqus_wlV0YF6SVO:disqus

            there is no difference between XBian (apt-get upgraded on 25.9.2013 by user) and Raspbian/Wheezy 25.9.2013.

            XBian is installed on top of it from standard .deb packages located at 3rd party APT repository.

            mk01

          • Wrechid

            i did notice some resemblances… :)

      • Wrechid

        Hello Jacek, I use your script often… I have been tinkering with it some and edited the user input of it… Applied some goof-proof, and the ability to make corrections… Added default value so a user could just hit all the way through it… :) also added the option to edit interfaces file before hostapd is started last time… Here’s a temporary link to what I have, not sure if I’m allowed to post this here… http://wrechid.com/ap_setup.sh

        • Jacek

          Wrechid, thanks a lot. I will check it out in my free time. Would you agree to put it in our tutorial as better version of what we did? (so that people won’t need to go through the comments :) ). All credentials will be kept :)

          • Wrechid

            I don’t mind… I don’t want any credit, I just like playing with scripts and writing different codes… :) Next I’m working on a way to add specific settings to interfaces file according to which distribution is installed… :)

  • Miguel Neto

    Hey, i had a raspberry model B,with the TP-LINK WN725N, and the wifi adapter are not detected, i had instaled berryboot on raspberry and try do what you say, but the berryboot console not understand the first code line (sudo apt-get update) . sorry my inglish. thanks for the help.

  • ToddB

    Awesome work guys – I’m not great with Linux and I tried on my own for a few weeks to make this work but struggled; your script did what I needed in minutes.
    Now to really take things to the next level, how hard do you think it’d be to make a script that checks to see if your home wifi is in range, and if so – running something like rsync to sync the local USB disk with a share on your home network? How awesome would it be if your car’s video library self-updated as you made new rips to a certain folder? Then I could have one in each car and never have to take them out – they’d get updated as movies are added/deleted provided we keep the source folder within the size limits of the USB drive we’re syncing too. Even better if we can trigger XBMC to rebuild the library while we’re there!

  • Steve Pearson

    Hi I’m new to this and I’m stuck close to the beginning, I cant find /etc/dhcp/dhcpd.conf so cant edit it, or do I need to make it ? the only .conf file in that directory is dhclient.conf

    Thank you

    • Jacek

      Have you installed hostapd first?

      • Steve Pearson

        Hi Jacek thanks for your reply

        I’ve started again with a fresh install just to make sure I’n not missing something

        this is what I get

        pi@raspberrypi ~ $ sudo apt-get -y install hostapd isc-dhcp-server iptables wpa_supplicant

        Reading package lists… Done

        Building dependency tree

        Reading state information… Done

        E: Unable to locate package wpa_supplicant

        pi@raspberrypi ~ $

        • Jacek

          Try to run this command first:
          sudo apt-get update

          • Steve Pearson

            Hi I ran that first

          • Bat!

            According to the Debian reference on my Pi, it should be wpasupplicant with no underscore, could that be the problem? I’m new at this so I don’t know.

          • http://stacklinux.com/ StackLinux

            yes it’s wpasupplicant. Don’t think the author used/tested these instructions. hehe

      • Steve Pearson

        also when you say

        NOTE: If you copy-paste hostapd.conf from our tutorial, remove comments. (thanks Arnold)

        do you mean like this ?

        interface=wlan0

        ssid=village_wifi

        channel=1

        # WPA and WPA2 configuration

        macaddr_acl=0

        auth_algs=1

        #WPA settings

        wpa=2

        wpa_passphrase=my_secret_pass

        wpa_key_mgmt=WPA-PSK

        wpa_pairwise=TKIP

        rsn_pairwise=CCMP

        #Hardware configuration

        driver=rtl871xdrv

        ieee80211n=1

        device_name=RTL8192CU

        manufacturer=Realtek

        hw_mode=g

        • Jacek

          yes

  • Simon

    Hi. The script seems to be working pretty well, but when i run sudo hostaps -dd /etc/hostapd/hostapd.conf i get this output.

    pi@raspberrypi ~ $ sudo hostapd -dd /etc/hostapd/hostapd.conf

    random: Trying to read entropy from /dev/random

    Configuration file: /etc/hostapd/hostapd.conf

    drv->ifindex=3

    l2_sock_recv==l2_sock_xmit=0x0x135e648

    BSS count 1, BSSID mask 00:00:00:00:00:00 (0 bits)

    Allowed channel: mode=1 chan=1 freq=2412 MHz max_tx_power=0 dBm

    Allowed channel: mode=1 chan=2 freq=2417 MHz max_tx_power=0 dBm

    Allowed channel: mode=1 chan=3 freq=2422 MHz max_tx_power=0 dBm

    Allowed channel: mode=1 chan=4 freq=2427 MHz max_tx_power=0 dBm

    Allowed channel: mode=1 chan=5 freq=2432 MHz max_tx_power=0 dBm

    Allowed channel: mode=1 chan=6 freq=2437 MHz max_tx_power=0 dBm

    Allowed channel: mode=1 chan=7 freq=2442 MHz max_tx_power=0 dBm

    Allowed channel: mode=1 chan=8 freq=2447 MHz max_tx_power=0 dBm

    Allowed channel: mode=1 chan=9 freq=2452 MHz max_tx_power=0 dBm

    Allowed channel: mode=1 chan=10 freq=2457 MHz max_tx_power=0 dBm

    Allowed channel: mode=1 chan=11 freq=2462 MHz max_tx_power=0 dBm

    Allowed channel: mode=1 chan=12 freq=2467 MHz max_tx_power=0 dBm

    Allowed channel: mode=1 chan=13 freq=2472 MHz max_tx_power=0 dBm

    Allowed channel: mode=0 chan=1 freq=2412 MHz max_tx_power=0 dBm

    Allowed channel: mode=0 chan=2 freq=2417 MHz max_tx_power=0 dBm

    Allowed channel: mode=0 chan=3 freq=2422 MHz max_tx_power=0 dBm

    Allowed channel: mode=0 chan=4 freq=2427 MHz max_tx_power=0 dBm

    Allowed channel: mode=0 chan=5 freq=2432 MHz max_tx_power=0 dBm

    Allowed channel: mode=0 chan=6 freq=2437 MHz max_tx_power=0 dBm

    Allowed channel: mode=0 chan=7 freq=2442 MHz max_tx_power=0 dBm

    Allowed channel: mode=0 chan=8 freq=2447 MHz max_tx_power=0 dBm

    Allowed channel: mode=0 chan=9 freq=2452 MHz max_tx_power=0 dBm

    Allowed channel: mode=0 chan=10 freq=2457 MHz max_tx_power=0 dBm

    Allowed channel: mode=0 chan=11 freq=2462 MHz max_tx_power=0 dBm

    Allowed channel: mode=2 chan=36 freq=5180 MHz max_tx_power=0 dBm

    Allowed channel: mode=2 chan=40 freq=5200 MHz max_tx_power=0 dBm

    Allowed channel: mode=2 chan=44 freq=5220 MHz max_tx_power=0 dBm

    Allowed channel: mode=2 chan=48 freq=5240 MHz max_tx_power=0 dBm

    Allowed channel: mode=2 chan=52 freq=5260 MHz max_tx_power=0 dBm

    Allowed channel: mode=2 chan=56 freq=5280 MHz max_tx_power=0 dBm

    Allowed channel: mode=2 chan=60 freq=5300 MHz max_tx_power=0 dBm

    Allowed channel: mode=2 chan=64 freq=5320 MHz max_tx_power=0 dBm

    Allowed channel: mode=2 chan=100 freq=5500 MHz max_tx_power=0 dBm

    Allowed channel: mode=2 chan=104 freq=5520 MHz max_tx_power=0 dBm

    Allowed channel: mode=2 chan=108 freq=5540 MHz max_tx_power=0 dBm

    Allowed channel: mode=2 chan=112 freq=5560 MHz max_tx_power=0 dBm

    Allowed channel: mode=2 chan=116 freq=5580 MHz max_tx_power=0 dBm

    Allowed channel: mode=2 chan=120 freq=5600 MHz max_tx_power=0 dBm

    Allowed channel: mode=2 chan=124 freq=5620 MHz max_tx_power=0 dBm

    Allowed channel: mode=2 chan=128 freq=5640 MHz max_tx_power=0 dBm

    Allowed channel: mode=2 chan=132 freq=5660 MHz max_tx_power=0 dBm

    Allowed channel: mode=2 chan=136 freq=5680 MHz max_tx_power=0 dBm

    Allowed channel: mode=2 chan=140 freq=5700 MHz max_tx_power=0 dBm

    Allowed channel: mode=2 chan=149 freq=5745 MHz max_tx_power=0 dBm

    Allowed channel: mode=2 chan=153 freq=5765 MHz max_tx_power=0 dBm

    Allowed channel: mode=2 chan=157 freq=5785 MHz max_tx_power=0 dBm

    Allowed channel: mode=2 chan=161 freq=5805 MHz max_tx_power=0 dBm

    Allowed channel: mode=2 chan=165 freq=5825 MHz max_tx_power=0 dBm

    Completing interface initialization

    Mode: IEEE 802.11g Channel: 1 Frequency: 2412 MHz

    RATE[0] rate=10 flags=0x1

    RATE[1] rate=20 flags=0x1

    RATE[2] rate=55 flags=0x1

    RATE[3] rate=110 flags=0x1

    RATE[4] rate=60 flags=0x0

    RATE[5] rate=90 flags=0x0

    RATE[6] rate=120 flags=0x0

    RATE[7] rate=180 flags=0x0

    RATE[8] rate=240 flags=0x0

    RATE[9] rate=360 flags=0x0

    RATE[10] rate=480 flags=0x0

    RATE[11] rate=540 flags=0x0

    Flushing old station entries

    ioctl[RTL_IOCTL_HOSTAPD]: Operation not supported

    Could not connect to kernel driver.

    Deauthenticate all stations

    +rtl871x_sta_deauth_ops, ff:ff:ff:ff:ff:ff is deauth, reason=2

    rtl871x_set_key_ops

    ioctl[RTL_IOCTL_HOSTAPD]: Operation not supported

    Failed to set encryption.

    Failed to clear default encryption keys (ifname=wlan0 keyidx=0)

    rtl871x_set_key_ops

    ioctl[RTL_IOCTL_HOSTAPD]: Operation not supported

    Failed to set encryption.

    Failed to clear default encryption keys (ifname=wlan0 keyidx=1)

    rtl871x_set_key_ops

    ioctl[RTL_IOCTL_HOSTAPD]: Operation not supported

    Failed to set encryption.

    Failed to clear default encryption keys (ifname=wlan0 keyidx=2)

    rtl871x_set_key_ops

    ioctl[RTL_IOCTL_HOSTAPD]: Operation not supported

    Failed to set encryption.

    Failed to clear default encryption keys (ifname=wlan0 keyidx=3)

    Using interface wlan0 with hwaddr 64:66:b3:06:2b:0e and ssid ‘Pi’

    Deriving WPA PSK based on passphrase

    SSID – hexdump_ascii(len=2):

    50 69 Pi

    PSK (ASCII passphrase) – hexdump_ascii(len=14): [REMOVED]

    PSK (from passphrase) – hexdump(len=32): [REMOVED]

    rtl871x_set_wps_assoc_resp_ie

    ioctl[RTL_IOCTL_HOSTAPD]: Operation not supported

    random: Got 20/20 bytes from /dev/random

    Get randomness: len=32 entropy=0

    GMK – hexdump(len=32): [REMOVED]

    Get randomness: len=32 entropy=0

    Key Counter – hexdump(len=32): [REMOVED]

    WPA: group state machine entering state GTK_INIT (VLAN-ID 0)

    Get randomness: len=16 entropy=0

    GTK – hexdump(len=16): [REMOVED]

    WPA: group state machine entering state SETKEYSDONE (VLAN-ID 0)

    rtl871x_set_key_ops

    ioctl[RTL_IOCTL_HOSTAPD]: Operation not supported

    Failed to set encryption.

    rtl871x_set_beacon_ops

    rtl871x_set_hidden_ssid_ops

    ioctl[RTL_IOCTL_HOSTAPD]: Operation not supported

    ioctl[RTL_IOCTL_HOSTAPD]: Operation not supported

    Failed to set beacon head/tail or DTIM period

    wlan0: Setup of interface done.

  • Jeffin

    Awesome, really thanks for this! It really helped me as a linux noob, and it’s even easier with your configuration script!
    One thing though, sometimes I need to connect my raspberry to my iphone personal hotspot. But on AP mode, my raspbmc cannot found any wifi. Is there any way to turn off the AP mode manually so my raspberry could connect normally to wifi connection just like before? I didn’t have LAN internet at home so sometimes I need to connect to wifi hotspot.

    Thanks! :D

  • Francisco Palomino

    I did the same as the tutorial I have the RTL8188CUS chipset
    I can see the access point in my phone

    But when I tried to get connect, I got an immediate answer that my phone is unable to join the network.

    I did a sudo hostapd -dd /etc/hostapd/hostapd.conf and at the very bottom I see.

    ioctl[RTL_IOCTL_HOSTAPD]: Invalid argument
    something I missing?
    Thanks, any help is appreciated.

    • Tanvi Jindal

      I am getting the same error. Were you able to figure this out? HElp would be really appreciated!

      • Francisco Palomino

        I did a fresh installation of Raspbmc.
        I ran the last three command lines at the end of this tutorial regarding the script and setup in two minutes.

        wget http://raspberry-at-home.com/files/ap_setup.sh
        chmod +x ap_setup.sh
        sudo ./ap_setup.sh
        I been answering the questions one by one and I did the setup.
        At the same time and due to several tries, seems like iphone keep older settings when trying to connect to the same SSID, so I reset Network Settings and everything worked fine!
        I used a TP-LINK as well with a fresh installation, ran the script and no problems at all.
        Post your results!.

        • Jacek

          Thanks Francisco! I hope this helps others as well!

      • sanchox

        I had the exact same issue. After running the script, my AP showed a SSID, but I would be immediately disconnected upon login. Without a reinstall, I followed the tutorial line by line (instead of relying on the script again). I found that the /etc/network/interfaces file was not correct. It had two sets of entries, one for static and one for manual. I edited it to match the tutorial and it worked like a charm :) GL

        • Tanvi Jindal

          Thanks for the reply, I am sorry I had been inactive for long time. I had fixed the issue too, had a wrong network interfaces file too. :/

  • http://stacklinux.com/ StackLinux

    The one problem I find (not just with this setup) is that if you go more than 20 feet in another room. Even though the signal level is still -50dBm or -60dbm the ping time starts to skyrocket and connection drops. See attached screenshot while testing just using youtube for example (which works perfect in the same room).

    IPs are differn’t because I’ve been trying multiple how-to’s to see if maybe its an issue with config and just gave this setup a try. Works find but move to the bedroom pings are perfect until load “even with signal well within good levels”. So far it only works well within 10 – 20 feet in the same root. My WiFi dongle is… http://www.amazon.com/gp/product/B00FADTN14/ I also tried with this one first: http://www.amazon.com/gp/product/B003MTTJOY/ The distance cause me to invest in the long range antenna which as far as signal is -60dBm in most rooms and 40dBm in the same room.

    The distance issue with high latency I thought was signal but I’m using another device with monitors signal while testing. Tested using Cisco router and even with -70dBm from 2 rooms away it works perfectly!

    Not sure if anyone else noticed this. Also I purchase a 2 Pi to make sure. Also I have multiple power supplies two of which are rated AND I tested at 5v 2amps. Most if not all of the first things to eliminate had already been tested.

    And yes I know I have the right drivers got them directly from here:
    http://www.realtek.com.tw/downloads/downloadsView.aspx?Langid=1&PNid=21&PFid=48&Level=5&Conn=4&DownTypeID=3&GetDown=false&Downloads=true

    As I said all the obvious things have been checked and rechecked. Multimpi Pi’s USB wifi dongles, even tried it with Arch Linux ARM all the same high pings and looses connection if you use from another room even with signal ALWAYS below -60dBm.

    Oh yes, I’ve tried differn’t channels. But mainly 1,6 and 11. ;)

    • Jacek

      I am always close to pi when using it as AP, but I assume that these small wifi adapters simply can’t handle longer distances.

  • TJC

    Jacek, thank you for the convenient script. It makes the installation very easy. The only manual change I made was to remove duplicate wlan0 entries in /etc/network/interfaces. I have a TP-Link TP-WN725Nv2 WiFi adapter which seems to use the Realtek 8188EUS chip. I can not get the TP-Link adapter to work with your instructions.

    I first install the driver for the TP-Link adapter for Raspbian Linux version 3.10.25+ #622 from http://www.raspberrypi.org/phpBB3/viewtopic.php?p=462982#p462982.

    With CHIPSET set to “no” I get a hostapd Segmentation fault during boot. The eth0 port works, I can ping the wlan0 address, but no SSID is broadcast.

    With CHIPSET set to “yes” I get hostapd ioctl[RTLIOCTL_HOSTAPD]: Operation not supported errors during boot. The eth0 port works, I can ping the wlan0 address, but no SSID is broadcast.

    In both cases ifconfig shows an IP address for wlan0, that it is UP, but not RUNNING.

    I have spent many hours searching for a solution, but nothing seems to work. Following your instructions gets me the furthest, but not to a working access point. Any suggestions you have would be appreciated.

  • Fero Nymous

    thx a lot for the script. I have also one problem that my ssid isn’t shown
    how can i fixed it??

    • Jacek

      Is hostapd running?

      • Fero Nymous

        i think that is runninge because i get a ip-adresse for dhcp but the 802.11 management says :: hostapdioctl(RTL_IOCTL_HOSTAPD]:operation not support
        9 times its written

  • 曹博堯

    wpa_supplicant should be wpasupplicant ?

  • Michael

    Hi Jacek
    i have a problem.
    hostapdhioctl[RTL_IOCTL_HOSTAPD]: Invalid argument
    Starting ISC DHCP server failed
    What did i wrong. I used ur script

  • Jonathas Kerber

    Thanks man, I had several troubles in trying to get hostapd working but your hostapd file worked perfectly. Can you tell what you’ve done?

    Regards

  • Oki Erie Rinaldi

    hey,, what about this second last step?

    i found the following:
    update-rc.d: warning: /etc/init.d/isc-dhcp-server missing LSB information
    update-rc.d: see
    System start/stop links for /etc/init.d/isc-dhcp-server do not exist.

    when i “update-rc.d isc-dhcp-server enable”.

  • Oki Erie Rinaldi

    Oke,, now my wireless turns to ‘unmanaged’. It can’t be active or inactive. What should I do?

  • John Samuel αΩ

    I can see the AP and connect with my phone, but I cannot connect to XBMC from the remote. I don’t think my phone can see any services on the rpi even though it is connected. Any ideas what I did wrong?

    • Jacek

      Do you have httpaccess enabled in xbmc?

      • John Samuel αΩ

        Yes. I can still access XBMC through wired network. It is available at 192.168.1.133 on my wired network. When connecting to AP though, it seems to be totally isolated from the onboard services.

        • Jacek

          So your wireless device does not have problems to connect to AP and it receives ip, right? Can you access other services on this pi, like ftp? What network mask you hdefined in hostapd.conf?

  • Ajay Jain

    I tried this tutorial, and I can view the network. However, I cannot browse the Internet on it. I don’t need an ethernet setup for this, do I?

    • Jacek

      How is your pi connected to the Internet? Do you have second wifi adapter? (I assume you don’t have ethernet cable connected)

      • Ajay Jain

        I do have a second wifi dongle. What would I do? Replace all instances of eth0 with wlan1 or just use that to connect to my Pi’s connection?

        • Jacek

          Yes, you should replace eth0 in iptables configuration

  • Claudio Clacly Spada

    Hi, I used the script and it works, I can see SSID but the mobile and the PC can’t connect to the AP. Can you help me? Thank you!

    EDIT: I have an usb dongle with realtek 8188CUS

  • Ugo

    I have tried several tutorials and the script solved it! (please put it as the first thing on the post!)
    sir, please post your paypal address, i want to pay you a beer! thank you very much

    • Jacek

      Ha! Thanks a lot! no such need :) you post is enough to make me feel happy :) If you want to spend some money though, you can always visit lightberry.eu :)