Exemplo n.º 1
0
Arquivo: app.py Projeto: lz677/ipheno
def fan():
    try:
        hardware_info.all_states[HardwareStates.fan] = int(
            request.args.get('duty'))
        logger.debug('---- 风扇开度设置为:%d' %
                     hardware_info.all_states[HardwareStates.fan])
    except TypeError:
        hardware_info.all_states[HardwareStates.fan] = 10
        logger.warning('未设置风扇开度(duty) 将其默认开启最低值10')
    TaskManager.tasks['fan'].start()
    time.sleep(0.1)
    return jsonify({'state': "ok"}) if TaskManager.tasks['fan'].get_states().states == 'complete' \
        else jsonify({'state': "failed"})
Exemplo n.º 2
0
Arquivo: app.py Projeto: lz677/ipheno
def system(cmd: str):
    if utility.save_info_to_json(hardware_info,
                                 './doc/conf/main_control.json'):
        logger.info("--- 主控配置储存成功 ---")
    else:
        logger.error('--- 主控配置未能成功储存 ---')
    if cmd == 'info':
        logger.debug('--- 查询总控信息')
        return jsonify(hardware_info.get_system_info())
    elif cmd == 'restart':
        time.sleep(1)
        # 重启服务器代码
        logger.warning("--- 重启服务器 ---")
        os.execv(sys.executable, ['python -m flask run'] + sys.argv)
    elif cmd == 'reboot':
        time.sleep(1)
        logger.warning("--- 重启总控 ---")
        os.system('sudo reboot')
Exemplo n.º 3
0
Arquivo: app.py Projeto: lz677/ipheno
def task(task_name: str):
    logger.info('收到任务<%s>执行请求' % task_name)
    if 'fan' in task_name:
        try:
            hardware_info.all_states[HardwareStates.fan] = int(
                request.args.get('duty'))
            logger.debug('---- 风扇开度设置为:%d' %
                         hardware_info.all_states[HardwareStates.fan])
        except TypeError:
            hardware_info.all_states[HardwareStates.fan] = 10
            logger.warning('未设置风扇开度(duty) 将其默认开启最低值10')
    if 'set-ip' in task_name:
        try:
            hardware_info.system_info['temIP']['ip'] = request.args.get("ip")
            hardware_info.system_info['temIP']['port'] = request.args.get(
                "port")
        except KeyError:
            logger.warning('未设置ip和端口,将其默认为初始值')
            hardware_info.system_info['temIP']['ip'] = '192.168.1.7'
            hardware_info.system_info['temIP']['port'] = '5000'
    # time.sleep(1)
    return TaskManager.tasks[task_name].start().get_json()
Exemplo n.º 4
0
Arquivo: app.py Projeto: lz677/ipheno
def task_cancel(task_name: str):
    logger.warning('收到取消任务<%s>请求' % task_name)
    return TaskManager.tasks[task_name].cancel().get_json()
Exemplo n.º 5
0
Arquivo: app.py Projeto: lz677/ipheno
def update_project():
    logger.warning('--- 更新本地版本')
    utility.update_project('/home/pi/Documents/hh')