poing
Posts: 1131
Joined: Thu Mar 08, 2012 3:32 pm

Re: [Tutorial] Using the RasPi as a WiFi hostspot (8 Nov 12)

Fri Nov 09, 2012 9:25 pm

anath3ma wrote: I'm using a ralink rt5370 wifi

So, how stable is USB and this adapter for everyone else? Am i alone with these problems? I really don't want to update/upgrade for fear of regressions, unless someone can verify that this combo works for them.
I have the same wifi dongle and It sure did work perfectly at one time :lol:

hunternet93
Posts: 336
Joined: Mon Dec 12, 2011 4:34 pm

Re: [Tutorial] Using the RasPi as a WiFi hostspot (8 Nov 12)

Sat Nov 10, 2012 1:35 pm

I just tested NAT on my Pi, after following the tutorial it's working well. I'm currently posting this connected via WiFi to my Pi which is connected through ethernet to my netbook which is connected to the internet through WiFi, and it actually works.

SirLagz
Posts: 1705
Joined: Mon Feb 20, 2012 8:53 am
Location: Perth, Australia
Contact: Website

Re: [Tutorial] Using the RasPi as a WiFi hostspot (8 Nov 12)

Sat Nov 10, 2012 3:00 pm

NAT Madness haha
Good to see that you guys got it going. :)
My Blog - http://www.sirlagz.net
Visit my blog for Tips, Tricks, Guides and More !
WiFi Issues ? Have a look at this post ! http://www.raspberrypi.org/phpBB3/viewtopic.php?f=28&t=44044

poing
Posts: 1131
Joined: Thu Mar 08, 2012 3:32 pm

Re: [Tutorial] Using the RasPi as a WiFi hostspot (8 Nov 12)

Sat Nov 10, 2012 3:06 pm

Sorry it took a while, but sleep and domestic duties took their toll ;)

I started with a fresh 2012-10-28 install and followed the new version of the tutorial closely.

One thing to note is that in point '3. Configure HostAPD.' I copied the whole text block (yes I'm lazy :D ) which caused a failure when I executed 'sudo service hostapd start', because all the lines but the first had a leading space.

After fixing that I saw the AP but could not connect. Running:

Code: Select all

sudo ps ax | grep udhcpd
gave:

Code: Select all

 2875 pts/0    S+     0:00 grep --color=auto udhcpd
which I presume means it's not running.

Then:

Code: Select all

sudo udhcpd -f
gave:

Code: Select all

udhcpd (v1.20.2) started
udhcpd: max_leases=235 is too big, setting to 19
udhcpd: can't open '/var/lib/misc/udhcpd.leases': No such file or directory
udhcpd: is interface wlan0 up and configured?: Cannot assign requested address
After reboot the output of the above was the same. Obviously something wrong with wlan0. Here's the contents of /etc/network/interfaces:

Code: Select all

auto lo

iface lo inet loopback
iface eth0 inet dhcp

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

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

up iptables-restore < /etc/iptables.ipv4.nat

poing
Posts: 1131
Joined: Thu Mar 08, 2012 3:32 pm

Re: [Tutorial] Using the RasPi as a WiFi hostspot (8 Nov 12)

Sat Nov 10, 2012 3:18 pm

I'll be dipped in dogsh*t :shock:

I removed the comments from /etc/hostapd/hostapd.conf en now it works!

(seeing the post of sirlagz I remembered him saying hostapd doesn't like comments in the config file)

:lol:

I'll keep this SD card as-is, do a few restarts, build another card with the webserver distro and will report back.

hunternet93
Posts: 336
Joined: Mon Dec 12, 2011 4:34 pm

Re: [Tutorial] Using the RasPi as a WiFi hostspot (8 Nov 12)

Sat Nov 10, 2012 4:58 pm

I removed the comments and extra spaces from the tutorial. It's odd that hostapd didn't start for you, I have a commented hostapd.conf and it works just fine.

poing
Posts: 1131
Joined: Thu Mar 08, 2012 3:32 pm

Re: [Tutorial] Using the RasPi as a WiFi hostspot (8 Nov 12)

Sun Nov 11, 2012 12:03 pm

Well, getting closer and closer...

After a restart I can sometimes log into the AP, but usually I can't. If I have no Ethernet cable it never seems to work (I'm creating an embedded project where usually the Pi will be started without the Ethernet cable plugged in).

If I can't log into the AP and I type:

Code: Select all

sudo ifconfig wlan0 192.168.2.1
sudo service udhcpd start
it works immediately.

Here's the output of "sudo udhcpd -f" before and after "sudo ifconfig wlan0 192.168.2.1":

Code: Select all

[email protected] ~ $ sudo udhcpd -f
udhcpd (v1.20.2) started
udhcpd: max_leases=235 is too big, setting to 19
udhcpd: is interface wlan0 up and configured?: Cannot assign requested address

[email protected] ~ $ sudo ifconfig wlan0 192.168.2.1

[email protected] ~ $ sudo udhcpd -f
udhcpd (v1.20.2) started
udhcpd: max_leases=235 is too big, setting to 19
Sending OFFER of 192.168.2.4
Sending ACK to 192.168.2.4
Then it works.

Still something wrong...

hunternet93
Posts: 336
Joined: Mon Dec 12, 2011 4:34 pm

Re: [Tutorial] Using the RasPi as a WiFi hostspot (8 Nov 12)

Sun Nov 11, 2012 12:58 pm

Sounds like wlan0 isn't getting an IP address at boot. Try adding the line:

Code: Select all

allow-hotplug wlan0
to /etc/network/interfaces right above the line

Code: Select all

iface wlan0 inet static
Not sure if that will fix the problem, but that's the only thing different about my setup and the tutorial that I could find.

poing
Posts: 1131
Joined: Thu Mar 08, 2012 3:32 pm

Re: [Tutorial] Using the RasPi as a WiFi hostspot (8 Nov 12)

Sun Nov 11, 2012 3:14 pm

Sadly that line is already in my interfaces file, see a few posts earlier.

But I started to 'play' with the interfaces settings, googled a bit and finally changed the wlan0 block as follows:

Code: Select all

allow-hotplug wlan0
iface wlan0 inet static
        address 192.168.2.1
        netmask 255.255.255.0
        network 192.168.2.0
        gateway 192.168.2.1
No doubt this is plain wrong, but from the moment I added these lines I could suddenly log into the Pi every time, albeit without Internet access.

I finally decided on a compromise: Did a fresh install of the webserver distro I'm going to use, ran the tutorial again without implementing point 4 which is about NAT-ing and now it seems I have easy connection every time, without Internet of course. Seems to (getting cautious :lol: ) indeed work like a charm.

As I don't need the mobile device to access Internet anyway I'll settle for this compromise, for I need to start coding PHP. I have no clue why it works for you but not for me, or it should be that my wired router has the 192.168.1.1 address, but I don't think so. Hope someone else can try and see if he/she has better luck.

poing
Posts: 1131
Joined: Thu Mar 08, 2012 3:32 pm

Re: [Tutorial] Using the RasPi as a WiFi hostspot (8 Nov 12)

Mon Nov 12, 2012 11:49 am

Just want to say omitting Nat-ing didn't help either :cry:

My Pi was in a bad mood today, for during about 20 restarts I could log in only once. I tried a lot of different things like different cables, different positions in the house (interference), hubs, PSUs, WiFi dongles (I have two) but nothing works reliably except logging in and typing:

Code: Select all

sudo ifconfig wlan0 192.168.2.1
sudo service udhcpd start
My only hope now is to create a startup script that waits a while after startup and then issues the above commands. I did try something but as a Linux newbie this is a bit over my head. Any help would be appreciated.

hunternet93
Posts: 336
Joined: Mon Dec 12, 2011 4:34 pm

Re: [Tutorial] Using the RasPi as a WiFi hostspot (8 Nov 12)

Mon Nov 12, 2012 12:45 pm

Do you have NetworkManager or Wicd installed? If you do, you'll need to disable them.
I'm currently trying to figure out what could be the problem, it may end up being this evening because of my job. I'm sorry the tutorial isn't working for you, I still think we should be able to get it working. I might install a fresh Raspbian on a different SD card and run through the tutorial again, just to see if I missed something.
EDIT: I just rebooted my Pi and found I have the same problem where wlan0 isn't getting an IP address. I'm going to try a few things, I'll let you know if I figure it out.

anath3ma
Posts: 16
Joined: Fri Nov 09, 2012 4:38 pm

Re: [Tutorial] Using the RasPi as a WiFi hostspot (8 Nov 12)

Mon Nov 12, 2012 1:12 pm

News for anyone using rt2870 driver...

I've had horrible stability issues since last Wed. when i put this all together. Basically the problem would manifest in a kworker block and stack dump in syslog every 1-4hrs. After this the wifi would be wedged so hard that only replugging power would fix things.

As of 24hrs ago, I shut off WPA2, am running in the clear and the device is still alive!

Most chipsets do encryption on-chip. That said, hostap talks about bringing everything into userspace. So, where is my problem here? Should I be looking at firmware? drivers? hostap?

Thanks...


Context info below:

Did an apt get upgrade last Sat.

WLAN firmware:
latest as of last Friday.

uname -a
Linux raspberrypi 3.2.27+ #250 PREEMPT Thu Oct 18 19:03:02 BST 2012 armv6l GNU/Linux

Example of a device getting wedged
Nov 6 20:18:27 raspberrypi kernel: [ 1455.427675] phy0 -> rt2x00usb_vendor_request: Error - Vendor Request 0x06 failed for offset 0x101c with error -110.

Example stack dump:

Nov 6 20:14:13 raspberrypi kernel: [ 1201.259250] INFO: task kworker/0:1:15 blocked for more than 120 seconds.
Nov 6 20:14:13 raspberrypi kernel: [ 1201.259275] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
Nov 6 20:14:13 raspberrypi kernel: [ 1201.259302] kworker/0:1 D c03ef974 0 15 2 0x00000000
Nov 6 20:14:13 raspberrypi kernel: [ 1201.259364] [<c03ef974>] (__schedule+0x30c/0x648) from [<c03f025c>] (schedule+0x58/0x70)
Nov 6 20:14:13 raspberrypi kernel: [ 1201.259397] [<c03f025c>] (schedule+0x58/0x70) from [<c03f1188>] (__mutex_lock_slowpath+0xb8/0x148)
Nov 6 20:14:13 raspberrypi kernel: [ 1201.259436] [<c03f1188>] (__mutex_lock_slowpath+0xb8/0x148) from [<c03f1244>] (mutex_lock+0x2c/0x30)
Nov 6 20:14:13 raspberrypi kernel: [ 1201.259475] [<c03f1244>] (mutex_lock+0x2c/0x30) from [<c034a01c>] (rtnl_lock+0x1c/0x24)
Nov 6 20:14:13 raspberrypi kernel: [ 1201.259508] [<c034a01c>] (rtnl_lock+0x1c/0x24) from [<c034c4a0>] (linkwatch_event+0x18/0x44)
Nov 6 20:14:13 raspberrypi kernel: [ 1201.259545] [<c034c4a0>] (linkwatch_event+0x18/0x44) from [<c004ad04>] (process_one_work+0x160/0x478)
Nov 6 20:14:13 raspberrypi kernel: [ 1201.259587] [<c004ad04>] (process_one_work+0x160/0x478) from [<c004ba2c>] (worker_thread+0x188/0x370)
Nov 6 20:14:13 raspberrypi kernel: [ 1201.259625] [<c004ba2c>] (worker_thread+0x188/0x370) from [<c0051358>] (kthread+0x94/0x9c)
Nov 6 20:14:13 raspberrypi kernel: [ 1201.259668] [<c0051358>] (kthread+0x94/0x9c) from [<c000f020>] (kernel_thread_exit+0x0/0x8)

hunternet93
Posts: 336
Joined: Mon Dec 12, 2011 4:34 pm

Re: [Tutorial] Using the RasPi as a WiFi hostspot (8 Nov 12)

Mon Nov 12, 2012 1:23 pm

I was going to post and say I think I fixed the issue, but every time I do that something breaks. So I'll just say: The following solution will definitely, absolutely, and completely not work. It will turn your Pi into GLaDOS who will then either kill you with neurotoxin or make you test until you die. :?

If you still want to proceed, here's what I did:
Just change the line:

Code: Select all

allow-hotplug wlan0
to

Code: Select all

#allow-hotplug wlan0
I've rebooted my Pi 4 times and each time the IP was set correctly. I think the problem was that the networking service was waiting for wlan0 to be plugged in, even though it was already. If you comment out this line, it will set the IP on boot immediately. Good luck!

hunternet93
Posts: 336
Joined: Mon Dec 12, 2011 4:34 pm

Re: [Tutorial] Using the RasPi as a WiFi hostspot (8 Nov 12)

Mon Nov 12, 2012 2:48 pm

anath3ma wrote:News for anyone using rt2870 driver...

I've had horrible stability issues since last Wed. when i put this all together. Basically the problem would manifest in a kworker block and stack dump in syslog every 1-4hrs. After this the wifi would be wedged so hard that only replugging power would fix things.

As of 24hrs ago, I shut off WPA2, am running in the clear and the device is still alive!

Most chipsets do encryption on-chip. That said, hostap talks about bringing everything into userspace. So, where is my problem here? Should I be looking at firmware? drivers? hostap
Try this: Create the file /etc/modprobe.d/rx2x00usb.conf and add the line:

Code: Select all

options rt2x00usb nohwcrypt=1
Reboot and see if it's more stable.

poing
Posts: 1131
Joined: Thu Mar 08, 2012 3:32 pm

Re: [Tutorial] Using the RasPi as a WiFi hostspot (8 Nov 12)

Mon Nov 12, 2012 3:03 pm

hunternet93 wrote:I was going to post and say I think I fixed the issue, but every time I do that something breaks. So I'll just say: The following solution will definitely, absolutely, and completely not work. It will turn your Pi into GLaDOS who will then either kill you with neurotoxin or make you test until you die. :?
:lol:
hunternet93 wrote:If you still want to proceed, here's what I did:
Just change the line:

Code: Select all

allow-hotplug wlan0
to

Code: Select all

#allow-hotplug wlan0
I've rebooted my Pi 4 times and each time the IP was set correctly. I think the problem was that the networking service was waiting for wlan0 to be plugged in, even though it was already. If you comment out this line, it will set the IP on boot immediately. Good luck!
I think you nailed it this time! Works like a charm after a dozen reboots, didn't see that yet. Thanks, man!

hunternet93
Posts: 336
Joined: Mon Dec 12, 2011 4:34 pm

Re: [Tutorial] Using the RasPi as a WiFi hostspot (8 Nov 12)

Mon Nov 12, 2012 3:17 pm

poing wrote:
hunternet93 wrote:I was going to post and say I think I fixed the issue, but every time I do that something breaks. So I'll just say: The following solution will definitely, absolutely, and completely not work. It will turn your Pi into GLaDOS who will then either kill you with neurotoxin or make you test until you die. :?
:lol:
hunternet93 wrote:If you still want to proceed, here's what I did:
Just change the line:

Code: Select all

allow-hotplug wlan0
to

Code: Select all

#allow-hotplug wlan0
I've rebooted my Pi 4 times and each time the IP was set correctly. I think the problem was that the networking service was waiting for wlan0 to be plugged in, even though it was already. If you comment out this line, it will set the IP on boot immediately. Good luck!
I think you nailed it this time! Works like a charm after a dozen reboots, didn't see that yet. Thanks, man!
Great! I've updated the tutorial accordingly. Have you tried it with NAT yet? Of course, it'll probably accelerate global warming and emit deadly radiation... :shock:

anath3ma
Posts: 16
Joined: Fri Nov 09, 2012 4:38 pm

Re: [Tutorial] Using the RasPi as a WiFi hostspot (8 Nov 12)

Mon Nov 12, 2012 8:41 pm

hunternet93 wrote: Try this: Create the file /etc/modprobe.d/rx2x00usb.conf and add the line:

Code: Select all

options rt2x00usb nohwcrypt=1
Reboot and see if it's more stable.
Nope... but thanks for the suggestion.
Nov 12 14:54:45 raspberrypi kernel: [ 4.722464] rt2x00usb: Unknown parameter `nohwcrypt'

poing
Posts: 1131
Joined: Thu Mar 08, 2012 3:32 pm

Re: [Tutorial] Using the RasPi as a WiFi hostspot (8 Nov 12)

Tue Nov 13, 2012 2:10 pm

hunternet93 wrote: Great! I've updated the tutorial accordingly. Have you tried it with NAT yet? Of course, it'll probably accelerate global warming and emit deadly radiation... :shock:
Lol, it's certainly plug and 'play' ;)

I retried the tutorial today with a fresh install of the 2012-10-28 distro with a second Pi and a second dongle where I copied most of the text out of your tutorial into Putty to make sure everything was as written; Immediate success, including NAT-ing, so I think you got it right now.

Two last remarks:
- the line in /etc/network interfaces that has to be changed doesn't read (in my case at least) "iface wlan0 inet dhcp" as you indicated in the text but "iface wlan0 inet manual". Splitting hairs I guess.
- Where I live you're responsible for your network connection and you are obliged by law to take measures to prevent misuse, so an open AP is not a good idea. Especially as the Pi is basically aimed at kids who might not realize the implications while the parents bear the responsibility. Therefore I would change /etc/hostapd/hostapd.conf to (something like) this:

Code: Select all

interface=wlan0
driver=nl80211
ssid=My_AP
hw_mode=g
channel=4

macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=My_Passphrase
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
The above .conf file works for me.

Cheers and thanks again.

hunternet93
Posts: 336
Joined: Mon Dec 12, 2011 4:34 pm

Re: [Tutorial] Using the RasPi as a WiFi hostspot (8 Nov 12)

Tue Nov 13, 2012 2:48 pm

poing wrote:
hunternet93 wrote: Great! I've updated the tutorial accordingly. Have you tried it with NAT yet? Of course, it'll probably accelerate global warming and emit deadly radiation... :shock:
Lol, it's certainly plug and 'play' ;)

I retried the tutorial today with a fresh install of the 2012-10-28 distro with a second Pi and a second dongle where I copied most of the text out of your tutorial into Putty to make sure everything was as written; Immediate success, including NAT-ing, so I think you got it right now.
Yay!
Two last remarks:
- the line in /etc/network interfaces that has to be changed doesn't read (in my case at least) "iface wlan0 inet dhcp" as you indicated in the text but "iface wlan0 inet manual". Splitting hairs I guess.
Fixed!
- Where I live you're responsible for your network connection and you are obliged by law to take measures to prevent misuse, so an open AP is not a good idea. Especially as the Pi is basically aimed at kids who might not realize the implications while the parents bear the responsibility. Therefore I would change /etc/hostapd/hostapd.conf to (something like) this:

Code: Select all

interface=wlan0
driver=nl80211
ssid=My_AP
hw_mode=g
channel=4

macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=My_Passphrase
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
The above .conf file works for me.

Cheers and thanks again.
I added your conf file to the tutorial, thanks! I usually use an open network because the nearest house from where I live is half a mile away, but using WPA is definitely a good idea.

hunternet93
Posts: 336
Joined: Mon Dec 12, 2011 4:34 pm

Re: [Tutorial] Using the RasPi as a WiFi hostspot (8 Nov 12)

Tue Nov 13, 2012 2:50 pm

anath3ma wrote:
hunternet93 wrote: Try this: Create the file /etc/modprobe.d/rx2x00usb.conf and add the line:

Code: Select all

options rt2x00usb nohwcrypt=1
Reboot and see if it's more stable.
Nope... but thanks for the suggestion.
Nov 12 14:54:45 raspberrypi kernel: [ 4.722464] rt2x00usb: Unknown parameter `nohwcrypt'
Hmm. Short of buying a new wireless adapter, I'm not sure how to fix this. You could submit a bug report to whoever maintains the rt2x00usb driver.

poing
Posts: 1131
Joined: Thu Mar 08, 2012 3:32 pm

Re: [Tutorial] Using the RasPi as a WiFi hostspot (8 Nov 12)

Tue Nov 13, 2012 2:55 pm

Depending on what floor I'm on I count between 4 and 16 APs :lol: But then I live in the middle of a city.

And to celebrate here a few phone snaps of my embedded project in beta configuration :D
Runs for more than 12 hours on the battery:

Image

Image

Image

Image

Looks a bit akward, but it works.

hunternet93
Posts: 336
Joined: Mon Dec 12, 2011 4:34 pm

Re: [Tutorial] Using the RasPi as a WiFi hostspot (8 Nov 12)

Tue Nov 13, 2012 2:59 pm

Nice project. My first Pi project was the Pi strapped to a block of packing foam, connected through USB to an old cell phone with a data plan, stuffed in a Ziplock plastic container, connected to a USB car charger, sharing the data plan as WiFi in the car for a road trip.

raspbee
Posts: 40
Joined: Tue Sep 25, 2012 1:25 pm

Re: [Tutorial] Using the RasPi as a WiFi hostspot (8 Nov 12)

Fri Nov 16, 2012 6:39 pm

Wow, thanks for this amazing tutorial. I just followed it and it works... well, almost.
The hotspot is appearing and disappearing (I am really close to the raspberry) from my android phone. A friend said it might be conflicting with my local wlan router?

I wonder if it is possible to use the wlan dongle as internet connection AND as hotspot at the same time.

Actually I just want the raspberry pi to be a hotspot so I can control it outdoors with my phone through SSH. But when updating and installing new software a network connection might be handy ;-)

Of course I could attach a second wlan dongle but is that really required?

poing
Posts: 1131
Joined: Thu Mar 08, 2012 3:32 pm

Re: [Tutorial] Using the RasPi as a WiFi hostspot (8 Nov 12)

Fri Nov 16, 2012 9:23 pm

If you download WiFi Analyzer from the Play Store you can see what other WiFi access points are active and at what channel they operate.

I don't think you can make a dongle both hotspot and client, but not sure. Also not sure how to setup a second dongle, would like to know. But you can hotplug a network cable into a working Pi, no problem.

hunternet93
Posts: 336
Joined: Mon Dec 12, 2011 4:34 pm

Re: [Tutorial] Using the RasPi as a WiFi hostspot (8 Nov 12)

Sat Nov 17, 2012 4:03 am

raspbee wrote:Wow, thanks for this amazing tutorial. I just followed it and it works... well, almost.
The hotspot is appearing and disappearing (I am really close to the raspberry) from my android phone. A friend said it might be conflicting with my local wlan router?

I wonder if it is possible to use the wlan dongle as internet connection AND as hotspot at the same time.

Actually I just want the raspberry pi to be a hotspot so I can control it outdoors with my phone through SSH. But when updating and installing new software a network connection might be handy ;-)

Of course I could attach a second wlan dongle but is that really required?
Glad you liked the tutorial. You can try changing the "channel=" line in the file /etc/hostapd/hostapd.conf to something different and see if that helps.

As far as I know, it's sadly not possible to both connect to and act as a wireless hotspot unless you have a special wireless chipset, like the ones in some wireless routers. You could simply add a second dongle, or use the Ethernet connection. You can share the laptop's internet connection through Ethernet to the Pi, or just stop hostapd and udhcpd then connect to an access point with an internet connection.

I also had an idea about connection to the Pi over Bluetooth, which would be handy in some circumstances where you want to connect wirelessly while not needing a WiFi hotspot. My USB Bluetooth dongle died, so I haven't done it yet, but it's a thought.

Return to “Networking and servers”