forked from mboyd/BTScan
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMysql_logger.py
More file actions
26 lines (19 loc) · 780 Bytes
/
Mysql_logger.py
File metadata and controls
26 lines (19 loc) · 780 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import MySQLdb
class MysqlLogger(object):
def __init__(self):
self.db = MySQLdb.connect("18.125.1.67","user","gpuuser","bluetooth1")
self.cursor =self.db.cursor()
def log(self, p):
x, y = p.position
SQL = "INSERT INTO BluetoothTB1 " + \
"(timestamp, receiver_mac, device_mac, rssi, x_pos, y_pos)" + \
" Values('%d','%s','%s','%d','%f','%f')" \
% (p.timestamp[0], p.receiver_mac, p.device_mac, p.rssi, x, y)
try:
self.cursor.execute(SQL)
self.db.commit()
except Exception, e:
self.db.rollback()
print "Failed to commit log to database, received %s" % str(e)
def stop(self):
self.db.close()