Пример #1
0
def setConfigInfo(data):
    result = {'result': 'ERROR: setConfigInfo()'}
    bc = beerChipPersistant(
        beerChip(beermonConfig['i2cBus'], beermonConfig['i2cAddr']))

    if ('controlProbe' in data):
        prbInfo = data['controlProbe']
        if (('dataSetId' in prbInfo) and ('probeId' in prbInfo)):
            try:
                dbConn = beerDB()
                dbConn.connect(beermonConfig['dbLocation'])

                sql = "SELECT id, probe_chan, control_probe FROM Probes "
                sql += "WHERE proj_id = ? AND id = ?"

                row = dbConn.fetchOne(
                    sql, (int(prbInfo['dataSetId']), int(prbInfo['probeId'])))

                if (row):
                    if (row[2] == 1):  # If configured for control
                        if (bc.setControlProbeChan(int(row[1]))):
                            result['result'] = 'OK'
                        else:
                            result[
                                'result'] = 'ERROR: Error writing chan %d to control chip' % (
                                    int(row[1]))
                    else:
                        result[
                            'result'] = 'ERROR: Probe not configured for control'
                else:
                    result['result'] = 'ERROR: Dataset/Probe not found.'

            except:
                result = {'result': 'ERROR: trying setConfigInfo()'}

            finally:
                if (dbConn != None):
                    dbConn.close()

    if ('activate' in data):
        if (data['activate']):
            bc.switchIn()
        else:
            bc.switchOut()
        result = {'result': 'OK'}

    if ('setpoint' in data):
        try:
            if (('id' in data['setpoint'])
                    and ('setting' in data['setpoint'])):
                if (int(data['setpoint']['id']) == 0):
                    temp = float(data['setpoint']['setting'])
                    bc.setSetpoint(temp)
        except:
            print('ERROR: Setting setpoint')

    return result
Пример #2
0
def getTempStat(data):
    # import pdb; pdb.set_trace()
    dbConn = None
    result = {}

    try:
        dbConn = beerDB()
        dbConn.connect(beermonConfig['dbLocation'])

        bc = beerChip(beermonConfig['i2cBus'], beermonConfig['i2cAddr'])
        result['uptime'] = bc.getUptime()

        result['state'] = {}
        result['state']['controlState'] = bc.getState()
        result['state']['setpoint'] = bc.getSetpoint()

        cntlChan = bc.getControlProbeChan()
        result['datasetId'] = data['datasetId']
        result['probes'] = []

        sql = "SELECT id, probe_name, probe_chan, type, min_range, max_range, control_probe FROM Probes "
        sql += "WHERE proj_id = ?"

        for row in dbConn.querySafe(sql, (int(data['datasetId']), )):
            probeData = {
                'id': row[0],
                'name': row[1],
                'min_range': row[4],
                'max_range': row[5],
                'cntl_able': row[6]
            }
            if (row[2] == cntlChan):
                probeData['cntl'] = True
            else:
                probeData['cntl'] = False

            probeWhere = []
            tupleWhere = (data['datasetId'], )
            probeWhere.append("probe_id = %d" % row[0])

            startts = datetime.now()
            if ('startTime' in data):
                # startts = datetime.fromisoformat( data['startTime'] )
                startts = datetime.strptime(data['startTime'],
                                            "%Y-%m-%dT%H:%M:%S.%fZ")
                probeWhere.append("temp_time <= '%s'" % (startts.isoformat()))

            if ('endTime' in data):
                # ts = datetime.fromisoformat( data['startTime'] )
                ts = datetime.strptime(data['endTime'],
                                       "%Y-%m-%dT%H:%M:%S.%fZ")
                probeWhere.append("temp_time > '%s'" % (ts.isoformat()))

            if ('statInterval' in data):
                ts = startts - timedelta(seconds=int(data['statInterval']))
                probeWhere.append("temp_time > '%s'" % (ts.isoformat()))
            """
            probeSql  = "SELECT "
            probeSql +=     "COUNT(*) as cnt, "
            probeSql +=     "AVG(temp) as avg, "
            probeSql +=     "SUM(temp * temp) as Ex2, "
            probeSql +=     "MIN(temp) as min, "
            probeSql +=     "MAX(temp) as max "
            probeSql += "FROM Temperature "
            probeSql += "WHERE (proj_id = ?) "
            if( len(probeWhere) > 0 ):
                probeSql += 'AND (' + ') AND ('.join(probeWhere) + ')'

            for prbRow in dbConn.querySafe( probeSql, tupleWhere ):
                if( prbRow[0] > 1 ):
                    probeData['avgTemp'] = prbRow[1]
                    probeData['sdevTemp'] = math.sqrt((prbRow[2] / prbRow[0]) - (probeData['avgTemp'] * probeData['avgTemp']))
                    # probeData['sdevTemp'] = result['uptime'] % 20
                    probeData['minTemp'] = prbRow[3]
                    probeData['maxTemp'] = prbRow[4]

                probeData['currentTemp'] = bc.getTemperature( row[2], row[3] )

                result['probes'].append( probeData )
            """
            probeData['currentTemp'] = bc.getTemperature(row[2], row[3])
            result['probes'].append(probeData)

        result['result'] = 'OK'
    except:
        result['result'] = 'ERROR: GetTempStat()'

    return result
Пример #3
0
import getpass

from beerChipI2C import beerChipI2C as beerChip
from beerChipDB import beerChipSQLiteDB as beerDB
from beerChipPersistant import beerChipPersistant


def usage():
    print('')
    print('Usage:')
    print('    python setActiveProject.py "DatasetName" ')
    print('')


if __name__ == '__main__':
    bc = beerChip(1, 0x2e)
    dbConn = beerDB()
    dbConn.connect('/opt/beermon/data/beermonSQLite3DB.db')

    bcPersist = beerChipPersistant(bc)

    if (len(sys.argv) != 2):
        print('ERROR: Usage')
        usage()
        sql = "SELECT proj_name FROM Project"
        print('Datasets:')
        for proj in dbConn.query(sql):
            print('\t%s' % proj[0])

        dbConn.close()
        sys.exit(1)
Пример #4
0
    print("    Where: checkPeriod -> ")
    print("                  Number of seconds between reconciliation")
    print("                  between database and beerChip")
    print("    checkPeriod = 0 means reconcile once, then return ")
    print("    checkPeriod = 300 -> 5min")
    print("    checkPeriod = 1800 -> 1/2hr")
    print("    checkPeriod = 3600 -> 1hr")
    print("    checkPeriod = 7200 -> 2hr")
    print("    checkPeriod = 18000 -> 5hr")
    print("    checkPeriod = 36000 -> 10hr")
    print("    checkPeriod = 86400 -> 24hr")
    print("")


if __name__ == '__main__':
    bc = beerChipPersistant(
        beerChip(beermonConfig['i2cBus'], beermonConfig['i2cAddr']))

    if (len(sys.argv) != 2):
        usage()
        sys.exit(1)

    bc.verifyConfig()
    sleepTime = int(sys.argv[1])
    if (sleepTime != 0):
        while (True):
            time.sleep(sleepTime)
            bc.verifyConfig()

    sys.exit(0)
Пример #5
0
#!/usr/bin/python

import sys

from beerChipI2C import beerChipI2C as beerChip
from beerChipPersistant import beerChipPersistant


def usage():
    print('')
    print('Usage:')
    print('    python setTemp.py <temperature in F> ')
    print('')


if __name__ == '__main__':
    bc = beerChipPersistant(beerChip(1, 0x2e))

    if (len(sys.argv) != 2):
        print('ERROR: Usage')
        usage()
        sys.exit(1)

    try:
        temp = float(sys.argv[1])
        bc.setSetpoint(temp)
    except:
        print('ERROR: Writing setpoint')
Пример #6
0
def getConfigInfo(data):
    activityMap = ['stale', 'collecting']
    dbConn = None
    result = {}

    try:
        dbConn = beerDB()
        dbConn.connect(beermonConfig['dbLocation'])

        result['version'] = '%d.%d.%d' % (beermonConfig['majVersion'],
                                          beermonConfig['minVersion'],
                                          beermonConfig['buildVersion'])

        bc = beerChipPersistant(
            beerChip(beermonConfig['i2cBus'], beermonConfig['i2cAddr']))
        cntlChan = bc.getControlProbeChan()
        result['uptime'] = bc.getUptime()
        result['state'] = {}
        result['state']['controlState'] = bc.getState()

        dataset = []
        sql = "SELECT id, proj_name, activity FROM Project "
        sql += "ORDER BY activity desc"
        for row in dbConn.query(sql):
            if (row[2] and (row[2] < len(activityMap))):
                act = activityMap[row[2]]
            else:
                act = 'err'
            dat = {'id': row[0], 'name': row[1], 'activity': act, 'probes': []}

            setpoints = []
            hasSp = False

            probeSql = "SELECT id, probe_name, probe_chan, type, min_range, max_range, control_probe FROM Probes "
            probeSql += "WHERE proj_id = %d" % (row[0])
            for prb in dbConn.query(probeSql):
                probe = {
                    'id': prb[0],
                    'name': prb[1],
                    'chan': prb[2],
                    'type': prb[3],
                    'min_range': prb[4],
                    'max_range': prb[5],
                    'cntl_able': prb[6]
                }
                if (probe['chan'] == cntlChan):
                    probe['cntl'] = True
                else:
                    probe['cntl'] = False

                if (probe['cntl_able'] == 1):
                    hasSp = True

                dat['probes'].append(probe)

            if (hasSp):
                setpoints.append({
                    'chan': 0,
                    'value': bc.getSetpoint(0),
                    'min_range': 20.0,
                    'max_range': 90.0
                })
            dat['setpoints'] = setpoints
            dataset.append(dat)

        result['dataset'] = dataset
        result['result'] = 'OK'
    except:
        result['result'] = 'Error'

    if (dbConn != None):
        dbConn.close()

    return result