# uploadBMdata.py # Written by Susan Mlodzianoski for CS78 final project - Mobile Data Gathering in Sensor Networks import socket import appuifw import string import httplib import urllib import e32 db0 = "http://gstocco.com/Mote.php?mode=1&id=" db1 = "&temp=" def uploadBMdata(): tempfile = "c:\\temp.xml" sock = socket.socket(socket.AF_BT,socket.SOCK_STREAM) address,services = socket.bt_discover() target = (address, services.values()[0]) sock.connect(target) ch = "" cht = "" id = "" temp = "" while(ch != '/'): if(ch != '+'): id+=ch ch = sock.recv(1) while(cht != '-'): temp+=cht cht = sock.recv(1) t = int(temp) temp = ((((t/4096.0) * 1.5 ) - .986) / .00355) temp = str(temp) print id print temp try: db = db0 + id + db1 + temp urllib.urlretrieve(db, tempfile) f = open(tempfile, 'r') result = f.read() f.close() print result except IOError: appuifw.note(u"Connection error to server", 'error') except: appuifw.note(u"Could not fetch information", 'error') appuifw.note(u"id = " + id + "\ntemp = " + temp, "info") sock.close() def quit(): appuifw.app.set_exit() appuifw.app.exit_key_handler=quit while(1): uploadBMdata()