×

Discussion Board

Results 1 to 14 of 14
  1. #1
    Regular Contributor
    Join Date
    Sep 2009
    Posts
    285

    Python module for communicating via GPRS

    Hi!

    I am trying to build an application that communicates with a webserver using GPRS. Is there a tutorial/example/etc that gives the basics of GPRS communication using Python?

    I have generally always used the Python Code Examples site as a starting point for any module I have attempted to develop. However, the only GPRS related example I find is titled 'How to close an active GPRS connection'

    Does anyone know a site/book where I can get some tutorials, etc on GPRS communication?

    Thanks

  2. #2
    Nokia Developer Champion
    Join Date
    Feb 2008
    Location
    Ahmedabad, Gujarat, India
    Posts
    3,852

    Re: Python module for communicating via GPRS

    Quote Originally Posted by kedarm View Post
    Hi!

    I am trying to build an application that communicates with a webserver using GPRS. Is there a tutorial/example/etc that gives the basics of GPRS communication using Python?

    I have generally always used the Python Code Examples site as a starting point for any module I have attempted to develop. However, the only GPRS related example I find is titled 'How to close an active GPRS connection'

    Does anyone know a site/book where I can get some tutorials, etc on GPRS communication?

    Thanks
    hello kedarm

    sorry but if you let us know some specific problems then we can get you some pointers. Like if you want to use the network part in Python you can have a look at the urllib and httplibmodule that offers a lot.

    Apart from that you can go through this wiki article to get a basic idea of working with web servers using PyS60.

    Hope this helps you.

  3. #3
    Regular Contributor
    Join Date
    Sep 2009
    Posts
    285

    Re: Python module for communicating via GPRS

    Quote Originally Posted by gaba88 View Post
    sorry but if you let us know some specific problems then we can get you some pointers. Like if you want to use the network part in Python you can have a look at the urllib and httplibmodule that offers a lot.
    Hi!

    Well, I am trying to build an application that sends some data over GPRS to a server (say my computer at home), and then receives some data.
    It's just a very basic application, as I am still learning how to use GPRS, python, etc.

    Can I use Python socket programming methods to connect to a server on the net and transfer data? Something along the lines of, creating a tcp connection between the phone and my computer and sending data?

    Thanks
    Kedar

  4. #4
    Regular Contributor
    Join Date
    Jan 2009
    Location
    India
    Posts
    138

    Re: Python module for communicating via GPRS

    Quote Originally Posted by kedarm View Post
    Hi!

    Well, I am trying to build an application that sends some data over GPRS to a server (say my computer at home), and then receives some data.
    It's just a very basic application, as I am still learning how to use GPRS, python, etc.

    Can I use Python socket programming methods to connect to a server on the net and transfer data? Something along the lines of, creating a tcp connection between the phone and my computer and sending data?

    Thanks
    Kedar
    Hi kedarm,

    As Gaba88 suggested you can communication with urllib and httplib module, rest of this you can also used ftplib and TCP/IP socket modules in ftplib module but you must install the ftplib library on your phone then use ftplib module there is some example/sample code available please check it out.

    http://mobilenin.com/pys60/info_networking.htm

    hope this helps you.
    Pavan Pareta
    Sr. Software Engineer
    http://windows-mobile-dev.blogspot.com

  5. #5
    Regular Contributor
    Join Date
    Sep 2009
    Posts
    285

    Re: Python module for communicating via GPRS

    So, the normal POST methods and GET method from here should work, right?

  6. #6
    Nokia Developer Champion
    Join Date
    Feb 2008
    Location
    Ahmedabad, Gujarat, India
    Posts
    3,852

    Re: Python module for communicating via GPRS

    Quote Originally Posted by kedarm View Post
    So, the normal POST methods and GET method from here should work, right?
    hello kedar

    ya that should work, for sending data from your mobile to web server.

    Regards,

  7. #7
    Regular Contributor
    Join Date
    Sep 2009
    Posts
    285

    Re: Python module for communicating via GPRS

    Hi!

    First and foremost, thanks everyone for the help - the GPRS module is working fine! I used the standard GET method given in the Python documentation, and I can access the net.

    Is there any way one can pre-select the Access Point? When I start the module to access the internet, I have to choose an "Access Point" from a drop down menu. I get the following options -
    "Hutch Access"
    "Hutch MMS"
    "Hutch World"
    I get a similar menu with Airtel (another service provider).
    Is there some way to select the access point so that it chooses option 1 every time, instead of offering me the choice? I need to make the application as simple as possible, giving the user as few choices as possible.

    I am unsure if the following problem is country-specific (or service provider specific). I am using this phone in India and am using the GPRS facility offered by Vodafone (formerly Hutch) and Airtel.

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

    Re: Python module for communicating via GPRS

    Quote Originally Posted by kedarm View Post
    Hi!

    First and foremost, thanks everyone for the help - the GPRS module is working fine! I used the standard GET method given in the Python documentation, and I can access the net.

    Is there any way one can pre-select the Access Point? When I start the module to access the internet, I have to choose an "Access Point" from a drop down menu. I get the following options -

    I get a similar menu with Airtel (another service provider).
    Is there some way to select the access point so that it chooses option 1 every time, instead of offering me the choice? I need to make the application as simple as possible, giving the user as few choices as possible.

    I am unsure if the following problem is country-specific (or service provider specific). I am using this phone in India and am using the GPRS facility offered by Vodafone (formerly Hutch) and Airtel.
    Search the forum for "set default access point".
    Pankaj Nathani
    www.croozeus.com

  9. #9
    Regular Contributor
    Join Date
    Sep 2009
    Posts
    285

    Re: Python module for communicating via GPRS

    Hi!

    This thread is really useful.

    Here is my code to do the same. It checks in a file (ap.txt) for the default access point.

    Code:
    import socket, os
    def set_ap():
    	if (os.path.isfile(u"C:\\ap.txt"):
    		f = open(u"C:\\mordor\\ap.txt","r")
    		apid = f.read()
    		f.close()
    		apo = socket.access_point(int(apid))
    		socket.set_default_access_point(apid)
    	else:
    		apid = socket.select_access_point()
    		f = open(u"C:\\mordor\\ap.txt","w")
    		f.write(repr(apid))
    		f.close()
    		socket.set_default_access_point(apid)
    Hope this helps someone else searching for setting ap id..

  10. #10
    Regular Contributor
    Join Date
    Sep 2009
    Posts
    285

    Re: Python module for communicating via GPRS

    Hi!

    Just came across one more problem. Any idea how to go about this one?

    In the GPRS section of the app I am building, I send some data to a specific url. The code (which works fine on the computer) is rather simple -
    Code:
    import httplib, urllib
    params = urllib.urlencode({'test': 1})
    headers = {"Content-type": "application/x-www-form-urlencoded","Accept": "text/plain"}
    conn = httplib.HTTPConnection("sahyadrians.110mb.com:80")
    conn.request("POST", "/home.html", params, headers)
    response = conn.getresponse()
    print response.status, response.reason
    # 200 OK
    data = response.read()
    conn.close()
    This code works fine, both on the phone as well as on the computer. Now, if the server is down or the url (in conn.request) is wrong, one would expect to get a simple error from this script saying -
    404 Not Found
    However, when I tweaked the code (and gave a non-legitimate site) -
    Code:
    import httplib, urllib
    params = urllib.urlencode({'test': 1})
    headers = {"Content-type": "application/x-www-form-urlencoded","Accept": "text/plain"}
    conn = httplib.HTTPConnection("sahyadrians.110mb.com:80")
    conn.request("POST", "/non_existent_page.html", params, headers)
    response = conn.getresponse()
    print response.status, response.reason
    # 200 OK
    data = response.read()
    conn.close()
    I got the following errors -
    Traceback (most recent call last)
    File "<console>", line 1, in ?
    File "c:\resource\httplib.py",line 459, in request
    self._send_request(method, url, body, headers)
    File "c:\resource\httplib.py", line 470, in send_request
    self.putrequest(method,url)
    File "c:\resource\httplib.py", line 415, in putrequest
    raise CannotSendRequest
    Any idea why the code does not give me the (expected) 404 error? When I try the same in the emulator, I get the "404 Not Found" error (like expected)

    I tried using something like -
    try:
    conn.request("POST", "/non_existent_page.html", params, headers)
    except ValueError:
    print "Error"
    But it still throws an error.

    Any help would be super! Please...

    Thanks
    Last edited by kedarm; 2009-12-27 at 17:56. Reason: Added more information

  11. #11
    Super Contributor
    Join Date
    Nov 2007
    Location
    Sertaozinho/Brazil
    Posts
    768

    Re: Python module for communicating via GPRS

    kedarm,

    When accessing http://sahyadrians.110mb.com/non_existent_page.html from PC I was redirected to http://vobyz.com.br/ instead the (expected) 404 error. So, the request was valid, no error at all.

  12. #12
    Regular Contributor
    Join Date
    Sep 2009
    Posts
    285

    Re: Python module for communicating via GPRS

    Quote Originally Posted by marcelobarrosalmeida View Post
    kedarm,

    When accessing http://sahyadrians.110mb.com/non_existent_page.html from PC I was redirected to http://vobyz.com.br/ instead the (expected) 404 error. So, the request was valid, no error at all.
    Sorry - my bad! I wanted to give an example of a non-existent page. I didn't realize the server would automatically redirect non-existent page requests to http://vobyz.com.br/.
    I guess something like - http://www.iitm.ac.in/tinda or something would be a better example.

    The problem is, if attempting to access a legitimate address, and the server fails, the whole application will abort at the error.

    Sorry for the bad example.

  13. #13
    Regular Contributor
    Join Date
    Sep 2009
    Posts
    285

    Re: Python module for communicating via GPRS

    Hi!

    Just in case there was someone following this thread, I figured it out!

    Code:
    import socket, httplib
    conn = httplib.HTTPConnection("www.thissitesurelydoesnotexist:80")
    try:
    	conn.request("GET","")
    except socket.error, msg:
    	print "Error - ",msg
    Phew! That's a relief!

  14. #14
    Super Contributor
    Join Date
    Nov 2007
    Location
    Sertaozinho/Brazil
    Posts
    768

    Re: Python module for communicating via GPRS

    Quote Originally Posted by kedarm View Post

    Phew! That's a relief!
    Great ! Just an aside: you can handle dns errors and socket errors separately:

    Code:
    import socket
    s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
    try:
        s.connect(('nokiacom',2222))
    except socket.gaierror, e:
        print "ADDR ERROR: %s" % e
    except socket.error, e:
        print "ERROR: %s" % e

Similar Threads

  1. GPS data using positioning module in Python s60
    By selimsolmaz in forum Symbian
    Replies: 2
    Last Post: 2009-07-08, 09:26
  2. Python for S60 1.9.1 released
    By tvijayan in forum Symbian
    Replies: 30
    Last Post: 2009-02-26, 06:16
  3. threading module in Python 1.4.5
    By widetech1 in forum Symbian
    Replies: 1
    Last Post: 2009-02-04, 17:13
  4. need help of module Parser for python s60 1.4
    By shinestudio in forum Symbian
    Replies: 2
    Last Post: 2009-01-01, 12:07
  5. Camera Python Module
    By vp in forum Symbian
    Replies: 4
    Last Post: 2008-09-22, 09:56

Posting Permissions

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