Beispiel #1
0
    def testAddGPS(self):
        # Open connection with the database
        db = MySQLdb.connect("localhost", "root", "reverse", "mydata")
        cursor = db.cursor()

        # Add a information to the database
        dr = GPS("1234.567865", "098765.4321", 7.20, "123.456.789")
        addToDatabase(dr)

        # Get information from the database
        cursor.execute("SELECT * FROM GPS")
        result = cursor.fetchone()
        dbId = result[0]
        dbLong = result[1]
        dbLat = result[2]
        dbSpe = result[3]
        dbTimestamp = result[4]

        # Close the connection and wipe the database
        db.close()
        cleardb()

        self.assertTrue(dbId == 1 and dbLong == "1234.567865"
                        and dbLat == "098765.4321" and dbSpe == 7.20
                        and dbTimestamp == "123.456.789")
def retreiveData():
	while True: 
		message = nextMessage(receiveQueue)
		if(isinstance(message, SensorData) and message.getSensorId() == "1"): latestvalues['throttle'] 	= message.getData()
		elif(isinstance(message, SensorData) and message.getSensorId() == "2"): latestvalues['rpm'] 	= message.getData()
		elif(isinstance(message, SensorData) and message.getSensorId() == "3"): latestvalues['current'] 	= message.getData()
		elif(isinstance(message, SensorData) and message.getSensorId() == "4"): latestvalues['voltage'] 	= message.getData()
		elif(isinstance(message, GPS)): latestvalues['GPS'] = (message.getLongtitude(), message.getLattitude(), 0, message.getTimestamp())
		else: pass
		addToDatabase(message)
Beispiel #3
0
    def testAddPower1(self):
        # Open connection with the database
        db = MySQLdb.connect("localhost", "root", "reverse", "mydata")
        cursor = db.cursor()

        # Add a information to the database
        dr = SensorData("1", "throttle", 7, "123.456.789")
        addToDatabase(dr)

        # Get information from the database
        cursor.execute("SELECT * FROM Throttle")
        result = cursor.fetchone()
        dbId = result[0]
        dbType = result[1]
        dbData = result[2]
        dbTimestamp = result[3]

        # Close the connection and wipe the database
        db.close()
        cleardb()

        self.assertTrue(dbId == 1 and dbType == "throttle" and dbData == "7"
                        and dbTimestamp == "123.456.789")
import MySQLdb
from writeDBToFile import writeDBToFile
from readFromGBDatabase import readFromGBDatabase

print "Starting runFromGB.py"

# Connect to the queue server
conn = boto.sqs.connect_to_region(
    "eu-west-2",
    aws_access_key_id="AKIAJAR3NWUEFXUP2DUA",
    aws_secret_access_key="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")
receiveQueue = conn.get_queue('Eco2GB')

# Clear the database before running
db = MySQLdb.connect("localhost", "root", "reverse", "mydata")
cursor = db.cursor()
#cleardb()

print "Starting runFromGB.py main loop."
while (True):
    try:
        message = nextMessage(receiveQueue)
        addToDatabase(message)
        print readFromGBDatabase()
        time.sleep(.005)

    except KeyboardInterrupt:
        print "Wrong."
        writeDBToFile()
        sys.exit()