+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 15
Like Tree2Likes

Thread: Receiving uploaded GPRS data through a socket (Python)

  1. #1
    gpstrack is offline x10Hosting Member gpstrack is an unknown quantity at this point
    Join Date
    Nov 2009
    Posts
    10

    Lightbulb Receiving uploaded GPRS data through a socket (Python)

    I am trying to develop a script that runs on my server that receives and processes data uploaded from a GPRS device. The GPRS device allows me to set the IP address and port number.

    First of all, I just want the script to acknowledge that the GPRS device has connected to it.

    At the moment, on my local machine, I have a python script running, and everytime I ping my machine at the specific port, the script logs the connection attempt:


    Code:
    #!/usr/bin/env python
    
    import socket
    mysocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    mysocket.bind(("10.150.22.113",5000))
    mysocket.listen(5)
    
    
    while 1:
        newsocket, address = mysocket.accept()
    
        f = open('data.txt', 'a')
    
        s1 = str(newsocket)
        f.write(s1)
        s2 = str(' ')
        f.write(s2)
        s3 = str(address)
        f.write(s3)
        s4 = str('\n')
        f.write(s4)
    
        f.close()
    
        newsocket.close()
    I run this script through Python IDLE and then ping 10.150.22.113 (my IP) at port 5000 from a different machine on the network, and it works.

    Now, I need to have the script running on a static/public IP address so my GPRS device can address it.

    Does anybody have any suggestions as to how I could get this running on my x10 site?
    I don't necessarily have to use Python, if anybody has suggestions using a different language.


    PS.: I checked the acceptable usage policy to see if this is ok, and I think it is...
    dinomirt96 likes this.

  2. #2
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: Receiving uploaded GPRS data through a socket (Python)

    I thought there was something in the ToS about not running additional servers, but I don't see it. Even so, arbitrary ports are blocked by a firewall. Your best bet is to rewrite your script as a web service. The neat thing about Python is that XML-RPC is terribly simple to use. With xmlrpclib and SimpleXMLRPCServer (or DocXMLRPCServer), you can transparently invoke functions and methods on the server and get the result on the client. Of course there's nothing that says the server side script and client need to be Python. If you prefer SOAP, check out Suds.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  3. #3
    gpstrack is offline x10Hosting Member gpstrack is an unknown quantity at this point
    Join Date
    Nov 2009
    Posts
    10

    Re: Receiving uploaded GPRS data through a socket (Python)

    Thanks for the help, again.

    The problem here is that I can't put a client on the GPRS device. It just sends the data to whatever IP/port that it is told to. It might send data once every minute for five minutes and then stop.

    I need a script that monitors the port, and when the device sends something, the script on the server processes it and then waits for the next data.

    Any thoughts on that..?

  4. #4
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: Receiving uploaded GPRS data through a socket (Python)

    What's the reason the server can't be on your local network? What's the make and model of the device? Will the device work with hostnames, or only IP addresses?

    You'll probably need a paid service, on X10 or elsewhere, to run a server of your own. On X10, you'll need a VPS. Alternatively, you could get a static IP for yourself.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  5. #5
    gpstrack is offline x10Hosting Member gpstrack is an unknown quantity at this point
    Join Date
    Nov 2009
    Posts
    10

    Re: Receiving uploaded GPRS data through a socket (Python)

    I'm on my university network so I don't have a static IP and I'm behind a proxy. The device only works with IPs. It has no name and VERY limited documentation: GPS asset tracker

    I thought that might be the case! Just trying to keep costs down.
    karimirt47 likes this.

  6. #6
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: Receiving uploaded GPRS data through a socket (Python)

    Not much there to identify the device. It's pictured with a China Unicom SIM card, but that doesn't help. Pulled some sort of ID ("353686 00000 8830") off of a picture on the product page, but that doesn't lead anywhere. Accursed generics! Any identifying marks on the inside or back of the device?

    Do you have shell access on any publicly accessible University servers? What sort of proxy are you behind? NAT? Does the documentation say it only works with IPs, or did you try a name and fail?
    Last edited by misson; 11-17-2009 at 09:42 AM.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  7. #7
    gpstrack is offline x10Hosting Member gpstrack is an unknown quantity at this point
    Join Date
    Nov 2009
    Posts
    10

    Re: Receiving uploaded GPRS data through a socket (Python)

    There is a barcode on the inside: 353686000049640 and absolutely nothing else :happysad:

    NAT I think and no shell access!

    If I was going to pay for hosting, what do you think I would need on the hosting package to be able to run a simple script (similar to above)? Would it work if I paid for a server/static IP and unblock my specific port and then ran my script on that server?

  8. #8
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: Receiving uploaded GPRS data through a socket (Python)

    Static IP and unblocked port should do it. Generally speaking, a process needs root access to listen on ports < 1024. Because of this, and because ports under 1024 have well-defined uses, make sure you use a port >= 1024. Port 5000 will probably be fine, though it does have a specific use.

    Your server script will need to be made fault tolerant, including a mechanism to re-launch it should it or the computer go down.

    Depending on what this is for, you might be able to use University resources with help from a professor. For instance, if you turn this into a school project, you might be able to get a port forwarded from the NAT server to your computer.
    Last edited by misson; 11-17-2009 at 12:22 PM.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  9. #9
    gpstrack is offline x10Hosting Member gpstrack is an unknown quantity at this point
    Join Date
    Nov 2009
    Posts
    10

    Re: Receiving uploaded GPRS data through a socket (Python)

    Ok, thanks! That sounds possible

    Cheers for the help, I'll let you know if I get anywhere!

  10. #10
    gpstrack is offline x10Hosting Member gpstrack is an unknown quantity at this point
    Join Date
    Nov 2009
    Posts
    10

    Re: Receiving uploaded GPRS data through a socket (Python)

    Misson. Just thought I would let you know, I got a machine with a static IP from my university and I have my script running on the server. I have my GPRS device configured the send the data to my IP and port.. and it works perfectly!

    Thanks for the help.

+ Reply to Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. Sort Data
    By secretply in forum Programming Help
    Replies: 2
    Last Post: 06-15-2009, 12:25 PM
  2. Replies: 6
    Last Post: 08-25-2008, 09:43 AM
  3. HTML help...
    By anuj_web in forum Programming Help
    Replies: 5
    Last Post: 05-08-2008, 11:22 AM
  4. uploaded file contains binary data
    By chongkolai in forum Free Hosting
    Replies: 2
    Last Post: 09-24-2007, 11:42 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers