Пример #1
0
def read_config():
    global config, sensors
    print("read config")

    config = json.loads(open('config').read())
    if not 'debug' in config: config['debug'] = defconfig['debug']
    if not 'movingavg' in config: config['movingavg'] = defconfig['movingavg']
    if not 'sync' in config: config['sync'] = defconfig['sync']
    if not 'i2c_bus' in config: config['i2c_bus'] = defconfig['i2c_bus']

    # drop unconfigured sensors
    config['sensors'] = {
        k: v
        for k, v in config['sensors'].items() if k != v['name'] or v['enabled']
    }

    for k, v in config['sensors'].items():
        sensors.append(w1dev.w1d(k, v))

    sensors.sort(key=lambda s: s.id, reverse=True)
    del config['sensors']
Пример #2
0
def thread_discovery():
    while True:
        # monitor w1
        found = False
        for f in listdir(w1dev.w1path):
            if f == 'w1_bus_master1': continue
            if not path.isdir(w1dev.w1path + '/' + f): continue

            s = cfg.getSensor(f)
            if s is None:
                print("new sensor: " + f)
                found = True
                cfg.acquire()
                cfg.sensors.append(w1d(f))
                cfg.release()

        if found:
            cfg.store_config()
            cfg.event.set()

        threading.Event().wait(timeout=5)
    #Timer(5, thread_discovery, ()).start()
    return
Пример #3
0
def thread_discovery():
    global config, sensors
    brews = config['brewfiles']

    while True:
        # monitor data dir
        for f in listdir('data'):
            if not f.endswith('.csv'): continue
            f = f[:-4]
            if not f in brews: brews.append(f)

        # monitor w1
        found = False
        for f in listdir(w1dev.w1path):
            if f == 'w1_bus_master1': continue
            if not path.isdir(w1dev.w1path + '/' + f): continue

            lock.acquire()
            exists = False
            for s in sensors:
                if s.id == f:
                    exists = True
                    break

            if not exists:
                print("new sensor: " + f)
                found = True
                sensors.append(w1d(f))
            lock.release()

        if found:
            update_config()
            event.set()

        threading.Event().wait(timeout=5)
    return
Пример #4
0
    if not 'decimate' in config: config['decimate'] = defconfig['decimate']
    if not 'sync' in config: config['sync'] = defconfig['sync']
    if not 'i2c_bus' in config: config['i2c_bus'] = defconfig['i2c_bus']

    # migrate
    if len(config['sensors']) and type(next(iter(config['sensors'].values()))) is not dict:
         print('migrate list -> dict')
         s = {}
         for k,v in config['sensors'].items():
             s[k] = { 'name':v[0], 'curr':v[1], 'avg':v[2], 'enabled':v[3], 'min':-20, 'max':100 }
         config['sensors'] = s
    # drop unconfigured sensors
    config['sensors'] = { k : v for k,v in config['sensors'].items() if k != v['name'] }

    for k,v in config['sensors'].items():
        sensors.append(w1d(k, v))

    sensors.sort(key=lambda s: s.id, reverse=True)
    del config['sensors']

if path.isfile('.clean_shutdown'):
    config['running'] = False
    update_config()
    os.remove('.clean_shutdown')

config['brewfiles'] = []
debug = config['debug']

if 0: # rpi lcd
    import tm1637
    lcd = tm1637.TM1637(16,15, tm1637.BRIGHT_HIGHEST)