rockymeza / wifi

[unmaintained] WiFi tools for linux
http://pypi.python.org/pypi/wifi
BSD 2-Clause "Simplified" License
305 stars 151 forks source link

Can't connect on Raspberry Pi (Jessie) #102

Open Grandpa-G opened 8 years ago

Grandpa-G commented 8 years ago

I am using wifi class in python (indentation not showing here, changed password).

for cell in wifiList: if 'RGC' in cell.ssid: scheme = Scheme.for_cell('wlan0', 'gateway', cell, 'xFarm') scheme.save() print 'saved' print('Connecting to %s' % cell.ssid) try: scheme.activate() print 'Connect' except: print 'Connection failed' break

When it gets to activate, the pi disconnects my xrdp session, can't be pinged, and I have to restart it to get another wifi connection by default reboot.

my interfaces file at the end looks like:

iface wlan0-gateway inet dhcp wpa-psk bfa650e4fea5f81ff34e051b6e13e3e94398b90000d1735cfc3f40c3532afde5 wpa-ssid RGC wireless-channel auto

The normal connection wifi entry is

iface wlan0 inet manual wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

Am I doing something wrong? Does the wpa_supplicant.conf format still work with your scheme format? Ideas?

rockymeza commented 8 years ago

You can do this to see what wifi is calling out to.

scheme = # ...
print(' '.join(['/sbin/ifup'] + self.as_args()))

Then you can run that command manually. Then can you post that output here?

Thanks,

Grandpa-G commented 8 years ago

I am no longer using wifi

nox1203 commented 8 years ago

On fully updated Jessie I run the following code after boot:

from wifi import Cell, Scheme

for scheme in Scheme.all():
    scheme.delete()
cell = Cell.all("wlan0")[0]
scheme = Scheme.for_cell('wlan0', "nox1203", cell, passkey="pass")
scheme.save()
scheme.activate()

and get the following:

Traceback (most recent call last):
  File "test.py", line 8, in <module>
    scheme.activate()
  File "/usr/local/lib/python2.7/dist-packages/wifi/scheme.py", line 176, in activate
    return self.parse_ifup_output(ifup_output)
  File "/usr/local/lib/python2.7/dist-packages/wifi/scheme.py", line 183, in parse_ifup_output
    raise ConnectionError("Failed to connect to %r" % self)
wifi.exceptions.ConnectionError: Failed to connect to Scheme(interface='wlan0', name='nox1203', options={'wpa-psk': 'fdd89aca0489ddf5b88286c495371ecd695b1b341a3d1263f90e34277f02852a', 'wpa-ssid': u'nox1203', 'wireless-channel': 'auto'}

But if I run the same code one more time it connects to the wifi. Please request additional data if needed.

rockymeza commented 8 years ago

hmm, that's weird.

Can you do this:

scheme = # ...
print(' '.join(['/sbin/ifup'] + self.as_args()))

and paste the output here?

Thanks,

nox1203 commented 8 years ago

Added print statement. I changed self.as_args() to scheme.as_args(). I got this:

/sbin/ifup wlan0=wlan0-nox1203 -o wpa-psk=fdd89aca0489ddf5b88286c495371ecd695b1b341a3d1263f90e34277f02852a -o wpa-ssid=nox1203 -o wireless-channel=auto

It is identical on both runs.

rockymeza commented 8 years ago

Can you try running that command directly and post the output here?

On Fri, Jul 15, 2016 at 4:40 AM nox1203 notifications@github.com wrote:

Added print statement. I changed self.as_args() to scheme.as_args(). I got this:

/sbin/ifup wlan0=wlan0-nox1203 -o wpa-psk=fdd89aca0489ddf5b88286c495371ecd695b1b341a3d1263f90e34277f02852a -o wpa-ssid=nox1203 -o wireless-channel=auto

It is identical on both runs.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/rockymeza/wifi/issues/102#issuecomment-232785510, or mute the thread https://github.com/notifications/unsubscribe/AABVGF7XR7Dshh0e65MdDrWSN1mbaThBks5qVp6mgaJpZM4Ia6_n .

-Rocky

nox1203 commented 8 years ago

pi@raspberrypi:~ $ sudo /sbin/ifup wlan0=wlan0-nox1203 -o wpa-psk=fdd89aca0489ddf5b88286c495371ecd695b1b341a3d1263f90e34277f02852a -o wpa-ssid=nox1203 -o wireless-channel=auto /sbin/ifup: interface wlan0 already configured

ifconfig says: wlan0 Link encap:Ethernet HWaddr 00:c1:41:31:0b:b3
inet6 addr: fe80::15ca:99a6:a787:2c0f/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)

rockymeza commented 8 years ago

oh, you were already connected. Can you disconnect and then run this command?

nox1203 commented 8 years ago

I was not connected. There is no inet ip for wlan. nmap 192.168.1.* does not give anything for raspberry pi.

rockymeza commented 8 years ago

oh sorry, I mean, your interface was already up. Can you turn off the interface first? /sbin/ifdown wlan0

On Fri, Jul 15, 2016 at 6:01 AM nox1203 notifications@github.com wrote:

I was not connected. There is no inet ip for wlan. nmap 192.168.1.* does not give anything for raspberry pi.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/rockymeza/wifi/issues/102#issuecomment-232805664, or mute the thread https://github.com/notifications/unsubscribe/AABVGHHkRL0nWMGJM2G4wA3F3yvBdRwSks5qVrHNgaJpZM4Ia6_n .

-Rocky

nox1203 commented 8 years ago

pi@raspberrypi:~ $ sudo /sbin/ifdown wlan0 pi@raspberrypi:~ $ sudo /sbin/ifup wlan0=wlan0-nox1203 -o wpa-psk=fdd89aca0489ddf5b88286c495371ecd695b1b341a3d1263f90e34277f02852a -o wpa-ssid=nox1203 -o wireless-channel=auto Internet Systems Consortium DHCP Client 4.3.1 Copyright 2004-2014 Internet Systems Consortium. All rights reserved. For info, please visit https://www.isc.org/software/dhcp/

Listening on LPF/wlan0/00:c1:41:31:0b:b3 Sending on LPF/wlan0/00:c1:41:31:0b:b3 Sending on Socket/fallback DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 4 DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 10 DHCPREQUEST on wlan0 to 255.255.255.255 port 67 DHCPOFFER from 192.168.1.1 DHCPACK from 192.168.1.1 bound to 192.168.1.109 -- renewal in 34477 seconds.

ashwinprasadme commented 8 years ago

I'm having a similar issue, I need to run the command 2-3 times before it connects to the network. Any fixes for this? I'm on Jessie too

ComradePashka commented 7 years ago

Hi, rockymeza! Few days ago I found and tried to use your library at the Raspberry Pi and got same issue. As you recomended, I added line:

   print subprocess.check_output(["ifdown", IF_WLAN])

before call to activate() and it looks like now I get successful connection.

And few details probably will be useful for you:

P.S. IF_WLAN is constant with name of my WLAN interface

knro commented 7 years ago

I was about to report a new issue, but I think this is related. Basically there is a small bug I believe in line 172 in scheme.py

subprocess.check_output(['/sbin/ifdown', self.interface], stderr=subprocess.STDOUT)

For interface names like wlan0-foobar, this would fail. A simple change fixes it. self.interface should be replaced with self.iface

That solved my problem.

mmeendez8 commented 7 years ago

Same thing happening here! I follow @rockymeza advice but the same error is appearing! It's even worst for me, I could not connect once!!

I am using a very simple script based on @nox1203 commentary and adding the ifdown command before calling activate(). Any idea?