This is crappy python which receives a UDP packet from the i296 running the java code located here. This packet is lightly parsed, then placed in a MySQL table.

There are TONS of errors in this code, and none of them are handled well. Malformed incoming packets crash the program, etc. etc.

If you want to take it and make it better, please do so. — Brad Luyster 2010/10/07 17:46

balloonserver.py
from socket import *
import MySQLdb
 
host =''
port = 1111
buf = 1024
addr = (host,port)
UDPSock = socket(AF_INET, SOCK_DGRAM)
UDPSock.bind(addr)
 
conn = MySQLdb.connect (host = "localhost",
                        user = "user",
                        passwd = "pass",
                        db = "db")
cursor = conn.cursor()
 
trun = input('Truncate Old Data? 1=yes, 0=no ')
 
if int(trun) == 1:
        cursor.execute("TRUNCATE `testDrive1`")
 
while 1:
        data,addr = UDPSock.recvfrom(buf)
        if not data:
                print "Client has Exited!"
                break
        else:
                print data
                splitData = data.split("~~")
                nmeaData = splitData[1].split("\n")
                locData = nmeaData[0].split(",")
                latS = locData[2].split(":")
                lonS = locData[4].split(":")
                lat = float(latS[0]) + float(latS[1]) / 60
                #Dangerous Assumption:  All data is coming from the Western hemisphere
                lon = float(lonS[0]) - float(lonS[1]) / 60
                telemData = splitData[2].split(";")
                oTemp = float(telemData[0])
                iTemp = float(telemData[5])
                if locData[11] == '':
                        alt = 0;
                else:
                        alt = float(locData[11])
                print "Sample Number: " +str(splitData[0][1:]) + " Lattitude: " +str(lat) + " Longitude: " + str(lon) + " Satellites in View: " + str(locData[7]+" Altitude: " + str(alt) + " Internal Temp: "+str(iTemp/10)+" External Temp: "+str(oTemp) )
                sql = "INSERT INTO `testDrive1` VALUES ('"
                sql += str(splitData[0][1:])
                sql += "','"
                sql += str(lat)
                sql += "','"
                sql += str(lon)
                sql += "','"
                sql += str(locData[7])
                sql += "','"
                sql += str(alt)
                sql += "','"
                sql += str(iTemp/10)
                sql += "','"
                sql += str(oTemp)
                sql += "','"
                sql += data
                sql += "');"
                cursor.execute(sql)
 
cursor.close()
conn.close()
UDPSock.close()
launches/highball/pyserver.txt · Last modified: 2010/10/07 21:48 by bradluyster
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki