You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.6 KiB
41 lines
1.6 KiB
import time
|
|
import serial
|
|
import json
|
|
import mysql.connector
|
|
#dilosi ths trexousas metrisis
|
|
test_name="test4"
|
|
# dilosi twn parametrwn gia thn anagnosi apo thn seiriakh porta
|
|
# rfcomm0 h kati allo einai h dilosi ths porta me thn opoia sindeete to rasbery me to arduino
|
|
ser = serial.Serial(
|
|
port='/dev/rfcomm0',
|
|
baudrate = 9600,
|
|
parity=serial.PARITY_NONE,
|
|
stopbits=serial.STOPBITS_ONE,
|
|
bytesize=serial.EIGHTBITS,
|
|
timeout=1
|
|
)
|
|
# loop sto opoio diabazoume apo thn seiriaki porta
|
|
while 1:
|
|
if(ser.isOpen):
|
|
#diabasma apo thn seiriaki kai apothikeusi se metabliti line
|
|
line = ser.readline()
|
|
# me thn bohtheia ths str metasximatizoume ta dedomena ths line pou einai byte se string typou utf-8
|
|
data = str(line, 'utf-8')
|
|
# ektyposi twn data
|
|
print(data)
|
|
# sindesi me thn bash dedomenwn tou rasbery kai apostoli twn dedomenwn
|
|
connection = mysql.connector.connect(user='root', password='password',host='127.0.0.1',database='tracking_2d')
|
|
cursor = connection.cursor()
|
|
mysql_insert = """INSERT INTO records (data, test_name) VALUES (%s, %s)"""
|
|
recordTuple = (data, test_name)
|
|
cursor.execute(mysql_insert,recordTuple)
|
|
connection.commit()
|
|
# kleisimo ths sindesis
|
|
if(connection.is_connected()):
|
|
cursor.close()
|
|
connection.close()
|
|
# se periptosi pou theloume na apothikeusoume ta data se arxeio
|
|
#b = open("/home/pi/Desktop/results.txt", "a")
|
|
#b.write(str(line,'utf-8'))
|
|
#b.close()
|
|
|