1234567891011121314151617181920212223242526272829303132333435363738394041 |
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- """
- demeter web
- name:admin.py
- author:rabin
- """
- import time
- from demeter.core import *
- from gevent import monkey; monkey.patch_socket()
- import gevent
- from pic import pic
- from demeter.mqtt import *
- # 处理定时命令、周期命令、条件控制、消息、设备状态等
- timeSleep = 10
- # 开关设备
- def switch(value):
- Demeter.service('device').switchMul(value)
-
- def timing():
- while 1:
- model = Demeter.model('device_set_timing')
- model.status = 0
- cur = Demeter.time()
- model.zdate.assgin(cur, '<=')
- data = model.select()
- if data:
- for value in data:
- switch(value)
- model.id = value['id']
- model.update(status=1)
- gevent.sleep(timeSleep)
- def handle():
- gevent.joinall([
- gevent.spawn(timing),
- ])
- handle()
|