You Are Here:

Community: Developer Discussion Boards

#1 Old Smile bt_gps & gsm_loc simple python app - 2005-01-17, 17:13

Join Date: Mar 2003
Posts: 4
lda2000
Offline
Registered User
Hi Guys,

I've just put together two smaller Python apps I've seen around in this discussion board.

The resulting app prints 1) info obtained by a BT gps (i.e. $GPRMC sentence, but may change as you like) and 2) GSM cell id.

My wish is to collect these info periodically (i.e. 2/3 minutes) and send them back via an HTTP POST to a specified host.... could anybody help? ;-)

Thanks

-Luca

____________________________________


# Simple BT App
#$GPRMC,161229.487,A,3723.2475,N,12158.3416,W,0.13,309.62,120598, ,*10


import socket,location,urllib

class BTReader:

def connect(self):
self.sock=socket.socket(socket.AF_BT,socket.SOCK_STREAM)
address,services=socket.bt_discover()
print "Discovered: %s, %s"%(address,services)
target=(address,services.values()[0])
print "Connecting to "+str(target)
self.sock.connect(target)

def readposition(self):
try:
buffer=""
ch = self.sock.recv(1)
while(ch !='\n'):
buffer+=ch
ch = self.sock.recv(1)
# print buffer


if (buffer[0:6]=="$GPRMC"):
(GPRMC,utc,status,lat,latns,lon,lonew,knots,course,date,xx1,xx2)=buffer.split(",")
return "GPS (%s,%s,%s,%s,%s)"%(utc,lat+latns,lon+lonew,knots,course)
except Error:
return "Error!\n"
return ""

def close(self):
self.sock.close()

class GSM_loc:

def upd(self):
self.loc = location.gsm_location()
return "GSM (MCC:%s MNC:%s LAC:%s CID=%s)"%(self.loc[0], self.loc[1], self.loc[2], self.loc[3])


gsm = GSM_loc()

bt=BTReader()
bt.connect()

i=0
while (i<15):
print gsm.upd()
print bt.readposition()
i+=1

bt.close()
Reply With Quote

#2 Old Quick hack - 2005-01-18, 10:02

Join Date: Mar 2004
Posts: 10
Location: Bangalore
Send a message via Yahoo to sandeep
sandeep
Offline
Registered User
From (http://www.python.org/doc/current/li...-examples.html)

==
import httplib, urllib

# replace with whatever you want POSTed...
gps_coords = urllib.urlencode({'param_1': 'value_1', 'param_2': 'value_2'})

# form contents
headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"}

conn = httplib.HTTPConnection("location-server.com:80")
conn.request("POST", "/cgi-bin/collect_loc", gps_coords, headers)
response = conn.getresponse()
data = response.read()
conn.close()
==

Both httplib and urllib are shipped with PyS60. Of course, you will have to create the CGI script separately.

Cheers,
Sandeep
http://sandeep.weblogs.us/
Last edited by sandeep : 2005-01-18 at 10:17.
Reply With Quote

#3 Old Thanks! - 2005-01-18, 11:29

Join Date: Mar 2003
Posts: 4
lda2000
Offline
Registered User
Hi Sandeep,

Thanks a lot! I'll post my resulting work.

Bye.

-Luca
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules

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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia