WiFi AP (RT5370) on Raspberry Pi

26.02.2017: Howto tested & working ๐Ÿ™‚

Today, we will look at howto create AP hotspot on Raspberry Pi usingย Ralink RT5370 chipset (see previous article).

First step should be update your repositories and update system to lastest:

sudo aptitude update; sudo aptitude -y upgrade

Then, reboot will be good thing to do..

sudo shutdown -r now

After boot, login, run sudo su – and lsusb command and you should see something like this:

pi@raspberrypi ~ $ sudo su -
root@raspberrypi:~# lsusb
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 004: ID 148f:5370 Ralink Technology, Corp. RT5370 Wireless Adapter

Install hostapd and dnsmasq:

aptitude install hostapd dnsmasq

Edit file with network settings to some static IP of wlan0:

nano /etc/network/interfaces

And wlan0 section should like:

allow-hotplug wlan0
iface wlan0 inet static
  address 192.168.100.1
  netmask 255.255.255.0

#wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet manual

(close nano with Ctrl+X, then Y and Enter)

After that, get down and up wlan0 interface and check, if you have your IP set it up on interface

ifdown wlan0; ifup wlan0
ifconfig wlan0 # this command should wrote these informations

# as you can see, there is right IP
wlan0 Link encap:Ethernet HWaddr xx:xx:xx:xx:xx:xx
inet addr:192.168.100.1 Bcast:192.168.100.255 Mask:255.255.255.0
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

Create new configuration for hostapd in /etc/hostapd/hostapd.conf and put there this info:

# you can create it with command
nano /etc/hostapd/hostapd.conf

#write info below into file
interface=wlan0
driver=nl80211
ssid=RaspberryPi_AP
hw_mode=g
channel=6
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=Your_fav_super_password
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP

Edit files /etc/default/hostapd and uncomment DAEMON_CONF, and add path to config. So line will looks like this:

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

Then, you can finally restart hostapd, and you have your hotspot up and running.

/etc/init.d/hostapd restart

# allow hostapd after boot
update-rc.d hostapd enable

Your hotspot is running, but you need to run some DHCP client for your clients which will use your hotspot. Edit and change these parameters in dnsmasq (and restart it):

#edit dnsmasq by following command
nano /etc/dnsmasq.conf

#find and change following parameters.. (or you can add these on end of the file 
interface=wlan0ย 
except-interface=eth0
dhcp-range=192.168.100.2,192.168.100.150,255.255.255.0,12h

# restart dnsmasq
/etc/init.d/dnsmasq restart

# allow dnsmasq after boot
update-rc.d dnsmasq enable

Then, you need to do NAT.. so..

#edit file /etc/sysctl.conf and uncomment this line
net.ipv4.ip_forward=1

# run this command to load it
sysctl -p

#run these command for allow forwarding..
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT

# save iptables to file which will load after start
iptables-save > /etc/iptables.nat

# create file with forwarding in /etc/network/if-up.d
echo '#!/bin/bash' > /etc/network/if-up.d/forwarding; echo 'iptables-restore < /etc/iptables.nat' >> /etc/network/if-up.d/forwarding; chmod +x /etc/network/if-up.d/forwarding

I found problem after reboot (and hostapd start) that wlan0 doesnt have IP assigned. You can solve it by chage fileย /etc/default/ifplugd and change it like this:

INTERFACES="eth0"
HOTPLUG_INTERFACES="eth0"
ARGS="-q -f -u0 -d10 -w -I"
SUSPEND_ACTION="stop"

Source:ย http://elinux.org/RPI-Wireless-Hotspot

Help with hostapd and IP:ย http://sirlagz.net/2013/02/10/how-to-use-the-raspberry-pi-as-a-wireless-access-pointrouter-part-3b/

57 thoughts on “WiFi AP (RT5370) on Raspberry Pi”

  1. It’s awesome that you are guiding peepz with process, and I really appreciate it! I did ran into a problem setting up my rPI for AP and that is panda wireless’s RT5370!! I tired to put it as NL80211 and it did not work.

  2. I have to admit, after long investigating I ended up with exact the same setup as above (plus, control on tx power – in /etc/network/interfaces add up line
    “up iwconfig wlan0 txpower 1mW”).

    Just, time to time, at reboot or unplugging accidentally wlan0 (!!), wireless interface doesn’t seems to pick up either the IP address or the power saving configs.
    In any of these case, hostapd won’t work.

    Tried ifup/ifdown/ifconfig wlan0 up [+down], changed file configs… nothing.

    Ok, sounds very little professional, but keep rebooting and don’t lose faith ๐Ÿ™‚
    Yesterday night I’ve been out of luck; this morning worked at the first attempt; later in the afternoon took me only five reboots before having it run! (with no config changes!! Might be the air moisture…)
    Now, ask me whether I’m going to touch it again?!?

    Have fun!

    1. Hi Michele,

      did you checked dmesg and /var/log/messages? It can tell you why it’s not up ๐Ÿ™‚

  3. Uh, thank you for the extra quick reply!
    Actually, I was lazy enough to try just
    tail /var/log/messages and nothing was in there – to be fully honest, I was a bit pi**ed and I KNEW it HAD to work, since it was working until a few seconds before I shut down the “server”, minutes earlier.
    So, restart after restart, and coffee after coffee I ran 2AM…

    Nevertheless I knew from first setup that something wasn’t playing nice between hostapd and/or dnsmasq and/or this particular card (Ralink Technology, Corp. RT5370 Wireless Adapter) and/or the low-power setup (running under solar panel, every mW counts!).
    Struggle a little with configs again, shut down some services here and there and, as best practice, I postponed to the next day.

    It worked, indeed, with no human intervention other than a good nap ๐Ÿ™‚

    Have a good 2015!

    1. Hi,

      yea, sometimes debugging is really hard ๐Ÿ™‚ My Rpi is as “XBMC / Airplay” behind my TV last months.. so I didn’t play with it for some time ๐Ÿ™

      Sometimes only a good nap is the best solution.

      To you too! ๐Ÿ™‚

  4. Ronny,
    I *unfortunately* had to switch off everything again, and *again* had to struggle with the interface not coming up.
    In a matter of fact I could bring it down and up with “service networking stop/start”, but the tx power wouldn’t be handled anymore.

    For further references, /etc/netoworking/interfaces on wlan0 looks like this:

    allow-hotplug wlan0
    iface wlan0 inet static
    address 192.168.7.111
    netmask 255.255.255.0
    wireless-power off
    up iwconfig wlan0 txpower 1mW

    To make a long story short (actually, I tried to cut it short from the very beginning!) I realized the only problem is that, for unknown and uninvestigated reason, wlan0 doesn’t come up with an IP address and

    $sudo ifconfig bla bla bla

    doesn’t seems to work.

    But, ladies and gentleman, the answer is:

    —>>>> sudo su <<<—
    #ifconfig wlan0 192.168.7.111

    (of course everything else had to work on its own… hostapd, dnsmasq, iptables settled down right, etc…)

    Have fun.

    1. Hi Michele,
      and did you tried part of article where is “I found problem after reboot”? ๐Ÿ™‚

      Otherwise, I am going to find some free SD card (and time) this week to test your txpower option.. ๐Ÿ™‚

      1. Haha, it seems I’m quite often *living* this part of article ๐Ÿ™‚

        But, as for spending my best professional skills, I kept rebooting until tea chilled off. Then, after a good sip&nap, I thought that # and $ are two different things and I was right ๐Ÿ™‚

        Leave the SD where it is, and take care of your loved one ๐Ÿ˜‰
        (more, in private… haha)

  5. I have RPi2 (RT5370) follow each step but just after do this:

    /etc/init.d/hostapd restart

    I get:
    [ok] Stopping advanced IEEE 802.11 management: hostapd.
    [FAIL] Starting advanced IEEE 802.11 management: hostapd failed!

    I really apreciete your help

    Regards

    1. Hi,

      open one more window with PuTTy (or which program are you using to SSH to your Pi) and do this “sudo tail -f /var/log/messages”. Then open second window and restart hostapd and check what shows up in first window with log.

  6. Hi, i did it your way step by step, have the same wifi stick etc.

    I get no errors, but when i search for wifi on my smartphone, the rpi won’t show up ๐Ÿ™

    1. Hi,

      can you send logs and configuration (without any password) to pastebin and link it here?

  7. i have successfully created a access point with my raspberry pi 2 but i am unable to connect with it from other devices… plz help

  8. i have no idea how many attempts I’ve done at this – and yours worked. I think it was the except-interface=eth0 part that did it.

    thanks!

  9. when I run the command “/etc/init.d/dnsmasq restart” I get the following error:
    “Restarting dnsmasq (via systemctl): dnsmasq.serviceJob for dnsmasq.service failed. See ‘systemctl status dnsmasq.service’ and ‘journalctl -xn’ for details.”

    The Pi is connect to an existing router via a cable and has a RT5370 USB dongle. Can’t find any AP. Any thoughts?

      1. The output is:

        root@raspberrypi:~# systemctl status dnsmasq.service
        ● dnsmasq.service – dnsmasq – A lightweight DHCP and caching DNS server
        Loaded: loaded (/lib/systemd/system/dnsmasq.service; enabled)
        Drop-In: /run/systemd/generator/dnsmasq.service.d
        └─50-dnsmasq-$named.conf, 50-insserv.conf-$named.conf
        Active: failed (Result: exit-code) since Sun 2016-01-10 08:24:46 UTC; 32s ago
        Process: 28629 ExecStart=/etc/init.d/dnsmasq systemd-exec (code=exited, status=2)
        Process: 28626 ExecStartPre=/usr/sbin/dnsmasq –test (code=exited, status=0/SUCCESS)

        Jan 10 08:24:46 raspberrypi dnsmasq[28626]: dnsmasq: syntax check OK.
        Jan 10 08:24:46 raspberrypi dnsmasq[28629]: dnsmasq: failed to bind DHCP server socket: Address already in use
        Jan 10 08:24:46 raspberrypi systemd[1]: dnsmasq.service: control process exited, code=exited status=2
        Jan 10 08:24:46 raspberrypi systemd[1]: Failed to start dnsmasq – A lightweight DHCP and caching DNS server.
        Jan 10 08:24:46 raspberrypi systemd[1]: Unit dnsmasq.service entered failed state.

  10. Re-installing Jessie (Lite) fixed this issue.

    I tried to make an AP from my PI several different ways. Probably an existing DHCP server was interfering with dnsmasq.

    1. Hi,

      yes, according to log “Jan 10 08:24:46 raspberrypi dnsmasq[28629]: dnsmasq: failed to bind DHCP server socket: Address already in use” there was something on that port ๐Ÿ™‚ but great to hear that you solve that!

      1. Hi,
        Can you explain how to fix that error?
        My log :-
        โ— dnsmasq.service – dnsmasq – A lightweight DHCP and caching DNS server
        Loaded: loaded (/lib/systemd/system/dnsmasq.service; enabled)
        Drop-In: /run/systemd/generator/dnsmasq.service.d
        โ””โ”€50-dnsmasq-$named.conf, 50-insserv.conf-$named.conf
        Active: failed (Result: exit-code) since Mon 2016-07-25 12:12:59 EAT; 2s ago
        Process: 4118 ExecStart=/etc/init.d/dnsmasq systemd-exec (code=exited, status=2)
        Process: 4114 ExecStartPre=/usr/sbin/dnsmasq –test (code=exited, status=0/SUCCESS)

        Jul 25 12:12:59 Richardpi dnsmasq[4114]: dnsmasq: syntax check OK.
        Jul 25 12:12:59 Richardpi dnsmasq[4118]: dnsmasq: failed to bind DHCP server socket: Address already in use
        Jul 25 12:12:59 Richardpi dnsmasq[4118]: failed to bind DHCP server socket: Address already in use
        Jul 25 12:12:59 Richardpi dnsmasq[4118]: FAILED to start up
        Jul 25 12:12:59 Richardpi systemd[1]: dnsmasq.service: control process exited, code=exited status=2
        Jul 25 12:12:59 Richardpi systemd[1]: Failed to start dnsmasq – A lightweight DHCP and caching DNS server.
        Jul 25 12:12:59 Richardpi systemd[1]: Unit dnsmasq.service entered failed state.

        1. Hi Richard!

          Something is running on port 67.

          Could you try to do systemctl stop dnsmasq.service and then netstat -tulnp | grep :67 ?

          It should show you if something is listening on that port

  11. my /etc/network/interfaces file reads differently to yours, I can’t find a reference to wpa-roam at all. Will this be an issue? Using a rpi 2 B with raspian wheezy. This is how my file reads:

    auto lo
    iface lo inet loopback

    autho eth0
    allow-hotplug eth0
    iface eth0 inet manuak

    autowlan0
    allow-hotplug wlan0
    iface wlan0 inet manual
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

    auto wlan1
    allow-hotplug wlan1
    iface wlan1 inet manual
    wap-conf /etc/wpa-supplicant/wpa_supplicant.conf

    If you can please help me that would be great, I want to move forward with your tutorial but want to know if this will create any issues, or if something needs to be added to the file before progressing.
    Thanks! – Todd

  12. Not working at all!
    Maybe you could be a little more clear with the instructions. Rather than using the ROOT comand, it would be easier for us noobe’s if it was in ssh.

    Getting ready to reload Rasbian onto SD….

    1. Hi wizard!

      How I can be clear with instructions? Which part? What and where is used ROOT command? All its done via ssh ๐Ÿ™‚

  13. I wave problem with TL-WN722N

    Erro:

    root@arm:~# hostapd /etc/hostapd/hostapd.conf
    Configuration file: /etc/hostapd/hostapd.conf
    nl80211: Could not configure driver mode
    nl80211: deinit ifname=wlan0 disabled_11b_rates=0
    nl80211 driver initialization failed.
    wlan0: interface state UNINITIALIZED->DISABLED
    wlan0: AP-DISABLED
    hostapd_free_hapd_data: Interface wlan0 wasn’t started

    The device is working, but i can’t configure it was AP.

  14. Hey guys, so I followed the instructions and so far all it does is disable my wifi all together. The error I get is that “No wireless interfaces found”.

    Here is my interfaces file

    auto lo
    iface lo inet loopback auto eth0

    auto eth0
    allow-hotplug eth0
    iface eth0 inet manual

    allow-hotplug wlan0
    iface wlan0 inet static
    address 192.168.100.1
    netmask 255.255.255.0

    iface default inet manual

    Thanks for your help

  15. lsusb:

    Bus 001 Device 006: ID 148f:5370 Ralink Technology, Corp. RT5370 Wireless Adapter
    Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
    Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp.
    Bus 001 Device 001: ID ld6b:0002 Linux Foundation 2.0 root hub

    lshw: no command found, cant connect to install it

    Thanks

    1. Hm.. I will try to get it working over weekend.. and let you know if howto is still working or not ๐Ÿ™‚

          1. Hi,

            so I was trying that.. and I get this after I edit my /etc/network/interfaces:
            root@raspberrypi:~# ifconfig wlan0
            wlan0 Link encap:Ethernet HWaddr 00:12:b4:a1:5a:59
            inet addr:192.168.100.1 Bcast:192.168.100.255 Mask:255.255.255.0
            UP BROADCAST MULTICAST MTU:1500 Metric:1
            RX packets:0 errors:0 dropped:0 overruns:0 frame:0
            TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
            collisions:0 txqueuelen:1000
            RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

            What is your output of ifconfig wlan0?

  16. wlan0 Link encap:Ethernet HWaddr 00:0f:60:04:ec:b6
    inet addr:192.168.100.1 Bcast:192.168.100.255 Mask:255.255.255.0
    intet6 addr: fe80::8960:892f:c401:cde1/64 Scope:Link
    UP BROADCAST MULTICAST MTU:1500 Metric:1
    RX packets:0 errors:0 dropped:0 overruns:0 frame:0
    TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
    collisions:0 txqueuelen:1000
    RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

      1. When I go through the tutorial, No hotspot is created. My wifi and ethernet on the PI is gone as well. It says that no wireless interfaces can be found. Thanks

        1. But according to your last answer with ifconfig wlan0, there is wlan0 activated ๐Ÿ™‚ in which part of howto it fails?

          1. This is why its so weird because all the diagnostics show wlan0 is up and running.

            The interface first cuts out when I run

            ifdown wlan0; ifup wlan0

            Thanks

          2. Can you show me ifconfig -a and also you are connected thru ethernet or wifi?

  17. I followed all all your instructions. I have it working but when i clone the img to another card i get no network interface. I have tried everything…

    any suggestions would be greatly appreciated!

      1. I fixed it. I am mixing with another package and somewhere i did something to make it not work. I have no clue where. I started from a fresh jessie img and only did the AP setup and cloned it and worked fine.
        Thanks!

  18. Hi guys please HELP! I tried this on retropie and it’s working, but I can’t make it to work on raspbian jessie lite -__-

    Log says no servers found for dnsmasq on boot. I have to restart dnsmasq in order for it to work properly but I can’t scan it over the network. I manually added server on dnsmasq.conf, rebooted and error was still there, I tried added resolv-file=/source but still no avail.

    1. Hi Miko,

      I think best and quickest solution will be try whole howto again (best in clean installation), because it was working well week ago, when I was trying that on latest Raspbian ๐Ÿ™‚

  19. Hi. I have my RPi AP setup according to your instructions. The RPi AP is attached via ethernet to my home modem/router. When I execute “/etc/init.d/hostapd restart” the network SSID shows up on my other devices and everything works fine for a little while… sometimes after a few hours or maybe a few days the SSID no longer shows up. To get it to work again I have to connect via SSH (the RPi still shows up in my modem/router’s client list) and re-execute “/etc/init.d/hostapd restart,” and the RPi AP’s SSID shows up and life is good again.

    How do I avoid having to SSH and restart hostapd all the time? Is it a problem with my wifi adapter (TL-WN722N)?

    Note 1: simply rebooting RPi doesn’t work, I always have to manually restart hostapd.

    Note 2: Also, I’ve run “service –status-all” while the problem is occurring and both hostpad and dnsmasq are still running.

    Note 3: ifconfig shows that wlan0 always has the correct IP address 192.168.100.1.

    Note 4: Running “ping -I wlan0 192.168.100.1” both before (when SSID is not showing up) and after hostapd restart gives the same successful ping results.

    Here is an output from my log while executing “/etc/init.d/hostapd restart”:

    root@pi:~# sudo tail -f /var/log/messages
    Aug 20 06:25:08 pi rsyslogd: [origin software=”rsyslogd” swVersion=”8.4.2″ x-pid=”459″ x-info=”http://www.rsyslog.com”] rsyslogd was HUPed
    Aug 20 11:47:17 pi kernel: [35307.854693] IPv6: ADDRCONF(NETDEV_UP): wlan0: link is not ready
    Aug 20 11:47:18 pi kernel: [35308.793377] IPv6: ADDRCONF(NETDEV_CHANGE): wlan0: link becomes ready

    I don’t know why hostapd fails on its own so frequently or how to check that it’s down other than noticing the SSID not showing up on other devices. Could you please help with:

    1. How to discovery why the SSID drops from time to time requiring the hostapd restart?
    2. If this is not possible, how to have the RPi AP check on itself if it is working (broadcasting SSID and other devices able to connect) then I can have a cron check if it’s working and if not simply restart hostapd (sort of like a scheduled self-test which executes restart if needed)?

    1. Hi,

      did you execute “update-rc.d hostapd enable”? Because hotspotd should start after reboot or it’s doesn’t work after reboot (hostapd running, but SSID is not up)?

      When you see SSID missing, could you check systemctl status hostapd.service what logs will be there at last before restart?

      You can for sure restart hostapd in cron, but don’t know on which trigger so far (how to recongnize, that AP is down).

  20. Thanks for the reply!

    How do you execute “update-rc.d hostapd enable?” Is this simply typed into the command line? That is what I did when I got to this step in your instructions.

    In the meantime I will check systemctl status hostapd.service next time the problem arrises.

    1. Ad. update-rc.d: Yes, if you are root, you do not need to call sudo ๐Ÿ™‚ (sudo is command to call command as root). Let me know your findings ๐Ÿ™‚

Leave a Reply

Your email address will not be published. Required fields are marked *