-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
26 lines (22 loc) · 993 Bytes
/
main.py
File metadata and controls
26 lines (22 loc) · 993 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 random
import os
import subprocess
import time
import mysql.connector
db_address = "ADDRESS"
db_port = "1234"
db_user = "USER"
db_password = "PASSWORD"
db_name = "marketpi_data"
db_table = "marketplace_table"
count = subprocess.Popen(["timeout", "--preserve-status", "5", "tcpdump", "-i", "bluetooth0"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
initial = count.stdout.read().decode("utf-8").split("\n")[4].split(" ")[0]
time.sleep(10)
count2 = subprocess.Popen(["timeout", "--preserve-status", "5", "tcpdump", "-i", "bluetooth0"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
final = count2.stdout.read().decode("utf-8").split("\n")[4].split(" ")[0]
print(int(final) - int(initial))
db = mysql.connector.connect(user=db_user, password=db_password, host=db_address, database=db_name, port=db_port)
cursor = db.cursor()
cursor.execute("INSERT INTO " + db_table + " (packets, timestamp) VALUES (" + str(int(final) - int(initial)) + ", NOW());")
db.commit()
cursor.close()