49 lines
1.3 KiB
Python
49 lines
1.3 KiB
Python
import time
|
|
|
|
import mysql.connector
|
|
|
|
dataBase = mysql.connector.connect(
|
|
host="192.168.1.25",
|
|
port="3306",
|
|
user="grafana_user",
|
|
passwd="Little1!",
|
|
database="grafana"
|
|
)
|
|
|
|
# preparing a cursor object
|
|
cursorObject = dataBase.cursor()
|
|
|
|
# creating table
|
|
studentRecord = """CREATE TABLE CARRIER_UPSTAIRS_STATUS (
|
|
timestamp TIMESTAMP,
|
|
status_timestamp TIMESTAMP,
|
|
outdoor_temp int,
|
|
idu_cfm int,
|
|
idu_opstat VARCHAR(20),
|
|
odu_opmode VARCHAR(20),
|
|
odu_opstat VARCHAR(20),
|
|
room_temp int,
|
|
room_humidity int,
|
|
cool_setpoint int,
|
|
heat_setpoint int,
|
|
current_activity VARCHAR(20),
|
|
zone_conditioning VARCHAR(20),
|
|
mode VARCHAR(20)
|
|
)"""
|
|
|
|
# table created
|
|
cursorObject.execute(studentRecord)
|
|
|
|
# # insert into table
|
|
# for i in range(10):
|
|
# sql = "INSERT INTO CARRIER_STATUS (timestamp, value)\
|
|
# VALUES (CURRENT_TIMESTAMP, %s)"
|
|
# val = [str(i)]
|
|
# cursorObject.execute(sql, val)
|
|
# dataBase.commit()
|
|
# time.sleep(1)
|
|
|
|
# disconnecting from server
|
|
dataBase.close()
|
|
|