def pin_sw(p): try: lib.pin_s[p] except: lib.pin_s[p] = 0 if lib.pin_s[p] == 1: lib.pin(p, 0) else: lib.pin(p, 1)
def cb(topic, msg): global led_sw, interval, survial, tmp print("Mqtt REC<<<<", msg) #传感器操作 msg = eval(str(msg)[2:-1]) print("Mqtt接收<<<<", msg) #电灯操作 try: if msg['data']['btn-sw'] == 'tap': timer = 0 if lib.pin_s[12] == 0: lib.pin(12, 1) mq.publish({"btn-sw": {"tex": "ON"}}) else: lib.pin(12, 0) interval = 0 survial = 0 mq.publish({"btn-sw": {"tex": "OFF"}}) except: pass try: if msg['data']['btn-led-sw'] == 'tap': if led_sw == 0: led_sw = 1 mq.publish({"btn-led-sw": {"swi": "on", "col": "#00FF00"}}) else: led_sw = 0 mq.publish({"btn-led-sw": {"swi": "off"}}) except: pass try: if str(msg['data']).find("interval") > -1: interval = msg['data']['interval'] + survial tmp = 0 except: pass try: if str(msg['data']).find("survial") > -1: survial = msg['data']['survial'] except: pass if msg['fromDevice'] == 'MIOT': try: if (msg['data']['set']['pState'] == 'true'): print("on") lib.pin(12, 1) else: print("off") lib.pin(12, 0) interval = 0 survial = 0 except: pass mq.publish("%s" % lib.wifi("", "", "info")[0]) print("exec")
def pin_sw(p): if lib.pin_s[p] == 1: lib.pin(p, 0) else: lib.pin(p, 1)
print("exec") a = "0" mq = blinker.blinker("b14b891ec11b", cb, 'light') def pin_sw(p): if lib.pin_s[p] == 1: lib.pin(p, 0) else: lib.pin(p, 1) t = 1 lib.pin(2, 1) lib.update_time() lib.pin(12, 0) mq.ping() display(1) led_sw = 1 survial = 0 interval = 0 tmp = 0 while 1: time.sleep(1) try: display() except: print("oled err") if t % 10000 == 0:
def _time_diff(self, args): t = time.localtime() t = [t[3], t[4], t[5]] if t == self.time: lib.pin(12, 0)
from machine import Pin, UART, Timer from utime import sleep import utime as time import web配网, lib, time, ujson try: with open('wifi_conf.py', 'r+') as f: json_data = ujson.load(f) if not lib.wifi(json_data['ssd'], json_data['pwd']): print("连接失败!") raise "连接失败!" except Exception as e: web.wifi_web() lib.pin(2, 0) def send(s): uart = UART(1, 38400) # init with given baudrate uart.init(38400, bits=8, parity=None, stop=1) print("send:", s) uart.write(s) def publish(msg): mq.publish(msg) def time_add(t, add): #t=[10,11,12] #时间加秒