Receiving uploaded GPRS data through a socket (Python)

gpstrack

New Member
Messages
10
Reaction score
0
Points
0
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...
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
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.
 

gpstrack

New Member
Messages
10
Reaction score
0
Points
0
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..?
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
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.
 

gpstrack

New Member
Messages
10
Reaction score
0
Points
0
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.
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
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:

gpstrack

New Member
Messages
10
Reaction score
0
Points
0
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?
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
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:

gpstrack

New Member
Messages
10
Reaction score
0
Points
0
Ok, thanks! That sounds possible :biggrin:

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

gpstrack

New Member
Messages
10
Reaction score
0
Points
0
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! :biggrin:

Thanks for the help.
 

raven47

New Member
Messages
3
Reaction score
0
Points
0
Hi gpstrack,

I want to do something similar. I used a php script I found on the web to listen on a predifined port to anything coming in. But I can't get my php script running at my localhost.

The php script is:
<?php
// Server IP address
$address = "127.0.0.1";
// Port to listen
$port = 1000;
set_include_path("C:\Program Files\EasyPHP-5.3.2\php\ext");
$mysock = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not bind to address\n") ;
socket_bind($mysock, $address, $port) or die('Could not bind to address');
socket_listen($mysock, 5);
$client = socket_accept($mysock);

read 1024 bytes from client
$input = socket_read($client, 1024);

write received data to the file
writeToFile('abc.txt', $input);

socket_close($client);

socket_close($mysock);
?>

<?
/**
* write string to file
*/
function writeToFile($strFilename, $strText)
{
if($fp = @fopen($strFilename,"w "))
{
$contents = fwrite($fp, $strText);
fclose($fp);
return true;
}else{
return false;
}

}
?>

what is wrong with this script?

Thanks in advance, raven47
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
Don't threadjack and don't revive old threads without very good reason. Start your own thread.

Use
PHP:
, [html] or [code] tags (as appropriate) to separate & format code.
 

raven47

New Member
Messages
3
Reaction score
0
Points
0
Hi Gpstrack,
I am really paralised :frown:without knowing what to do and how to do the following:

The project consists on a R/C airplane model with a celular Telit module (i.e GM862/3) that has to send every 3 to 4 sec some data (position, altitude, speed, course, bearing etc etc). The Telit module will have a Python script that will do that job.

Here is the part where I am just paralised!:confused:
- Build a Website to receive online gprs data from a celular Telit module GM862/3 mounted on a R/C airplane.
- The Telit module has a python script that sends gprs data to a Website.
- The Website has to display the airplane's position on a google map.
- The Website has to save all gprs data to a database.
I read your post and I think you may give me a fresh start to do this project.
Thanks in advance
 

lemon-tree

x10 Minion
Community Support
Messages
1,420
Reaction score
46
Points
48
Raven47, try reading what Misson said...good, now do it again. This thread was long dead the first time you posted, now your digging it out of its grave again. If you have a genuine problem, start your own thread.

For the record: Gpstrack hasn't logged in since 2009, so there is an overwhelming probability that you are not going to get any answer. Continuing to post to a dead thread won't change that.
 
Top