×

Discussion Board

Results 1 to 15 of 15
  1. #1
    Regular Contributor
    Join Date
    Sep 2007
    Posts
    54

    Python able to access Wifi?

    hi, I've looked through the new Python release notes and noticed that there isn't any modules to access the Wifi. Does this means that there is no way to come up with a program that is able to use the internet using Wifi instead of GPRS? Sorry if my question sounds stupid but I've only been in Python for a while.. Thanks

  2. #2
    Regular Contributor
    Join Date
    Oct 2007
    Posts
    67

    Re: Python able to access Wifi?

    Neither are there any GPRS modules. Connection will use whatever protocol is defined in the access point definition.

  3. #3
    Registered User
    Join Date
    Jun 2005
    Posts
    386

    Re: Python able to access Wifi?

    @nick_santa83

    You don't access GPRS or WiFi or whatever directly. You just use the standard networking modules (like urllib or socket) and the user will be presented with a list of access points upon connecting.

  4. #4
    Registered User
    Join Date
    Dec 2006
    Posts
    7

    Re: Python able to access Wifi?

    I found this to be a very handy snippet of code for just that kind of thing:

    Code:
    import sys, socket, urllib
    
    apid = None
    #this next line brings up the access point menu
    apid = socket.select_access_point()
    if not apid:
        sys.exit()
    apo = socket.access_point(apid)
    socket.set_default_access_point(apo)
    apo.start()
    try:
        ip = apo.ip()
        print u"Connected to WiFi as %s" % ip
    except:
        print u"Failed to connect to WiFi"
    
    #Then you can use urllib as much as you want without the phone bugging you to pick an access point:
    
    url = "http://api.wefeelfine.org:8080/ShowFeelings?display=text&returnfields=sentence&feeling=happy&limit=1"
    web = urllib.urlopen(url)
    response = web.read()
    print response
    (borrowed this stuff from my Sydewynder app)

  5. #5
    Regular Contributor
    Join Date
    Sep 2007
    Posts
    54

    Re: Python able to access Wifi?

    Thanks a lot!

    any idea if this is the same for C++ and java or even windows mobile?
    Last edited by nick_santa83; 2007-10-30 at 05:24.

  6. #6
    Registered User
    Join Date
    Dec 2006
    Posts
    7

    Re: Python able to access Wifi?

    Not sure. I know some people have had trouble doing things with Java due to security restrictions, like recording sound, that seem to work fine with the Python modules. But I haven't tried this with the WiFi/Internet connections.

  7. #7
    Super Contributor
    Join Date
    Apr 2003
    Location
    USA, CA
    Posts
    7,191

    Re: Python able to access Wifi?

    nick_santa83
    In Java on S60 devices the user of the application uses the access point to be used. If the user selects WiFi access point, then Wifi is used. However there is no method/code for MIDlets themselves to select WiFi to be used.

    Hartti

  8. #8
    Regular Contributor
    Join Date
    Sep 2007
    Posts
    54

    Re: Python able to access Wifi?

    ok. Thanks

  9. #9
    Registered User
    Join Date
    Apr 2007
    Posts
    39

    Re: Python able to access Wifi?

    Very useful.

    How I can disconnect?

  10. #10
    Regular Contributor
    Join Date
    Mar 2003
    Location
    UK
    Posts
    125

    Re: Python able to access Wifi?

    Quote Originally Posted by launch View Post
    How I can disconnect?
    Call the access point object's 'stop' method. e.g.

    Code:
    import socket
    
    # Setup AP
    apid = socket.select_access_point()
    apo = socket.access_point(apid)
    socket.set_default_access_point(apo)
    
    # Start connection
    apo.start()
    
    # Do whatever
    do_my_thing()
    
    # Stop connection
    apo.stop()

  11. #11
    Registered User
    Join Date
    Apr 2007
    Posts
    39

    Thumbs up Re: Python able to access Wifi?

    Thank you aya42!

  12. #12
    Registered User
    Join Date
    Mar 2009
    Posts
    2

    Re: Python able to access Wifi?

    ok in python 1.4.* but in python 1.9.* how can use wifi?
    socket.select_access_point() doesn't exist anymore.

    I'm trying to use imap module, but it doesn't works because it doesn't establish a connection...

    any help?

  13. #13
    Nokia Developer Moderator
    Join Date
    May 2007
    Location
    21.46 N 72.11 E
    Posts
    3,795

    Re: Python able to access Wifi?

    Quote Originally Posted by cagnulein View Post
    ok in python 1.4.* but in python 1.9.* how can use wifi?
    socket.select_access_point() doesn't exist anymore.

    I'm trying to use imap module, but it doesn't works because it doesn't establish a connection...

    any help?
    Wlantools is what you need.
    http://www-rp.lip6.fr/~berger/pys60.html

    //Croozeus
    Pankaj Nathani
    www.croozeus.com

  14. #14
    Regular Contributor
    Join Date
    Mar 2003
    Location
    UK
    Posts
    125

    Re: Python able to access Wifi?

    Quote Originally Posted by cagnulein View Post
    ok in python 1.4.* but in python 1.9.* how can use wifi?
    socket.select_access_point() doesn't exist anymore.
    This should work on 1.4.x and 1.9.x...

    Code:
    import sys
    try:
        sys.modules['socket'] = __import__('btsocket')
    except ImportError:
        pass
    import socket
    
    socket.select_access_point()

  15. #15
    Registered User
    Join Date
    Jan 2010
    Posts
    3

    Re: Python able to access Wifi?

    Hi.
    I am writing an app to control my MPD (Music Player Daemon) with my Nokia E51 by wifi.
    There is a generic python client library which uses socket module.

    I am using pys60 1.9.7.
    Everything is working very well, but I wanted to add powersaving to my app.

    Here is code I wrote:
    Code:
    if e32.inactivity() > 120:
    	if connected:
    		disconnect()
    		del client
    else:
    	if connected == 0:
    		client = connect()
    connect function:
    Code:
    def connect():
    	global ip_serwera
    	global connected
    	client = mpd.MPDClient()           # create client object
    	try:
    		client.connect(ip_serwera, 6600)  # connect to ip:6600
    		connected = 1
    	except:
    		change_ip()
    	return client
    disconnect function:
    Code:
    def disconnect():
    	global client
    	global connected
    	if connected:
    		client.close()                     # send the close command
    		client.disconnect()                # disconnect from the server
    		connected = 0
    	return 1
    I import the library using code:
    Code:
    sys.path.append("E:\\Python")
    import mpd
    In the library function close sends "goodbye" to server and disconnect does:
    Code:
    def disconnect(self):
            self._rfile.close()
            self._wfile.close()
            self._sock.close()
            self._reset()
    But even after I do disconnect WiFi stays ON and uses battery.

    What can I do?

    WiFi connections is closed only after I close Python interpreter.
    Last edited by pingwing; 2010-01-07 at 14:07.

Similar Threads

  1. Disabling wifi access pooint during RConnection.Start
    By gkore in forum Symbian Networking & Messaging (Closed)
    Replies: 4
    Last Post: 2010-10-05, 18:28
  2. Nokia 6101 Locked 2 TMobile Midlet can't access internet...
    By Jason Glass in forum Mobile Java Networking & Messaging & Security
    Replies: 45
    Last Post: 2007-11-14, 02:19
  3. Access to ANI / MIN from Python
    By bleeckerj in forum Symbian
    Replies: 0
    Last Post: 2007-03-04, 20:31
  4. Create C++ Library and Access from Python
    By adywicaksono in forum Symbian
    Replies: 2
    Last Post: 2006-05-03, 19:23
  5. 9500: wifi driver access
    By msolsona in forum Symbian Networking & Messaging (Closed)
    Replies: 0
    Last Post: 2005-07-12, 08:29

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×