import sys sys.path.insert(0, '../database/database') from sql_declarative import databaseCreation from sql_insert import insertNewRow from sql_query import queryRowSpecific, queryColumn, queryRow, queryTable, queryValue, queryValueSpecific print databaseCreation() table = 'Devices' rowOne = {'name':'Hello!','ini':'ControllerOne.ini','ip':'192.168.92.69','mac':'macAddressOne'} rowTwo = {'name':'ControllerTwo','ini':'ControllerTwo.ini','ip':'192.168.92.70','mac':'macAddressTwo'} rowThree = {'name':'ControllerThree','ini':'ControllerThree.ini','ip':'192.168.92.71','mac':'macAddressThree'} rowFour = {'name':'ControllerFour','ini':'ControllerFour.ini','ip':'192.168.92.72','mac':'macAddressFour'} insertNewRow(table, rowOne) insertNewRow(table, rowTwo) insertNewRow(table, rowThree) insertNewRow(table, rowFour) tablename = 'Setpoints' setpointrow = {'tempSA':10000,'tempMA':72,'tempPA':73,'tempSA':75,'humidityRA':20,'airFlowOA':25,'coRA':30} insertNewRow(tablename, setpointrow) value =queryTable('Devices','name') print value valuetwo = queryTable('Setpoints','id') print valuetwo
# Reading all ports on device for item in range(1,numberOfConnectedPorts): portObj = here.getPortItem(item) readDic[int(portObj.getPortNum())] = read(here, portObj) end1 = time.time() ################################ print "After Reading all ports: " + str(readDic) #commit it to the database array = ['tempOA','tempRA','tempMA','tempPA','tempSA','humidityOA'] valDic = {} for i in range(0,len(readDic)): valDic[array[i]] = readDic[i+1] print valDic table = here.getObjectName() tablename = table.lower() print tablename insertNewRow(tablename, valDic) #manipulate data for item in range(1,numberOfConnectedPorts): portObj = here.getPortItem(item) if portObj.getControlled(): manipulatedDic[portObj.getConnectedTo()] = portObj.Ploop(setpoint, readDic[portObj.getPortNum()]) #manipulatedDic should conatin the value from the Ploop with the key being the port of the actuator that the sensor is paired with print "after Ploop : " + str(manipulatedDic) start2 = time.time() ################################ #print "Started write ..." for item in manipulatedDic: portObj = here.getPortItem(item) write(here, portObj, manipulatedDic[item]) end2 = time.time() ################################
portObj = device.getPortItem(item) readDic[item] = read(i, device, portObj) print "After Reading all ports: " + str(readDic) #---------------------------------------- #Hard Coded write statements for database print "Writing values to database..." #These are just possible column key names. Ideally these would be read from a configuration database and would reflect #the actual key for the port. dummyColList = ['tempOA', 'tempRA' ,'tempMA', 'tempSA', 'tempRA', 'tempMA', 'tempSA', 'damperPositionRA'] temp = {} for j in range(0, len(readDic)): temp[dummyColList[j]] = readDic[j + 1] print str(temp) if i == 0: insertNewRow('controllerone', temp, 'sqlite:///../database/database/rh.db') if i == 1: insertNewRow('controllertwo', temp, 'sqlite:///../database/database/rh.db') #---------------------------------------- # P-Loop -- Proportional Control Loop for item in range(1,numberOfConnectedPorts): portObj = device.getPortItem(item) if portObj.getControlled(): # manipulatedDic should contain the value from the Ploop with the key being the port of the actuator that the sensor is paired with print readDic[portObj.getPortNum()] manipulatedDic[portObj.getConnectedTo()] = portObj.Ploop(setpoint, readDic[portObj.getPortNum()]) print "P-Loop result: " + str(manipulatedDic) except ValueError:
import sys sys.path.insert(0, '../database/database') from sql_insert import insertNewRow from sql_declarative import databaseCreation from sql_query import queryTable print databaseCreation() table = 'devices' rowOne = {'name':'ControllerOne','ini':'ControllerOne.ini','ip':'192.168.92.69','mac':'macAddressOne'} rowTwo = {'name':'ControllerTwo','ini':'ControllerTwo.ini','ip':'192.178.92.79','mac':'macAddressTwo'} insertNewRow(table, rowOne, 'sqlite:///../database/database/rh.db') insertNewRow(table, rowTwo, 'sqlite:///../database/database/rh.db') tablename = 'setpoints' setpointrow = {'tempSA':70,'tempMA':72,'tempPA':73,'tempSA':75,'humidityRA':20,'airFlowOA':25,'coRA':30} insertNewRow(tablename, setpointrow)
#Hard Coded write statements for database #---------------------------------------- print "Writing values to database..." #These are just possible column key names. Ideally these would be read from a configuration database and would reflect #the actual key for the port. dummyColList = [ 'tempOA', 'humidityOA', 'coOA', 'coRA', 'tempRA', 'tempMA', 'tempSA', 'damperPositionRA' ] temp = {} for j in range(0, len(readDic)): temp[dummyColList[j]] = readDic[j + 1] print str(temp) if i == 0: insertNewRow('controllerone', temp, 'sqlite:///../database/database/rh.db') if i == 1: insertNewRow('controllertwo', temp, 'sqlite:///../database/database/rh.db') #---------------------------------------- #Determining the correct output from the controller. ManipulatedDic should contain the value from the P-loop with the key being the port of the actuator that the sensor is paired with for item in range(1, numberOfConnectedPorts): portObj = device.getPortItem(item) if portObj.getControlled(): print readDic[portObj.getPortNum()] manipulatedDic[portObj.getConnectedTo()] = portObj.Ploop( setpoint, readDic[portObj.getPortNum()]) print "P-Loop result: " + str(manipulatedDic) #Write the new output values to the controller.
print databaseCreation() table = 'devices' rowOne = { 'name': 'ControllerOne', 'ini': 'ControllerOne.ini', 'ip': '192.168.92.69', 'mac': 'macAddressOne' } rowTwo = { 'name': 'ControllerTwo', 'ini': 'ControllerTwo.ini', 'ip': '192.178.92.79', 'mac': 'macAddressTwo' } insertNewRow(table, rowOne, 'sqlite:///../database/database/rh.db') insertNewRow(table, rowTwo, 'sqlite:///../database/database/rh.db') tablename = 'setpoints' setpointrow = { 'tempSA': 70, 'tempMA': 72, 'tempPA': 73, 'tempSA': 75, 'humidityRA': 20, 'airFlowOA': 25, 'coRA': 30 } insertNewRow(tablename, setpointrow)