v-kun 1 місяць тому
коміт
4261ba168e
5 змінених файлів з 68 додано та 0 видалено
  1. 21 0
      01001/v.1.1/device.py
  2. 1 0
      01001/v.1.1/fileList.json
  3. 1 0
      system/v1.1/fileList.json
  4. 41 0
      system/v1.1/main.py
  5. 4 0
      version.json

+ 21 - 0
01001/v.1.1/device.py

@@ -0,0 +1,21 @@
+from machine import Pin
+
+# 设备类型
+model = '01001'
+led = Pin(4, Pin.OUT)
+def command(com):
+    """
+    执行命令
+    """
+    if com == 'on':
+        led.on()
+    elif com == 'off':
+        led.off()
+
+def status():
+    """
+    上报状态
+    """
+    return {
+        'status': led.value() == 1
+    }

+ 1 - 0
01001/v.1.1/fileList.json

@@ -0,0 +1 @@
+["device.py"]

+ 1 - 0
system/v1.1/fileList.json

@@ -0,0 +1 @@
+["main.py"]

+ 41 - 0
system/v1.1/main.py

@@ -0,0 +1,41 @@
+import time
+
+import utils
+from config import getConfig
+from httpServer import startHttpServer,closeHttpServer
+# 硬重启
+#import machine;machine.reset()
+
+def taskCheck():
+    """
+    定时检查连接
+    :return:
+    """
+    while True:
+        try:
+            if utils.getStatus():
+                print('WiFi 正常', utils.getWifiConnectInfo())
+                if getConfig().mqttStatus:
+                    print('MQTT 正常', getConfig().mqtt.clientId, getConfig().mqtt.host, getConfig().mqtt.port,getConfig().mqtt.subTopic)
+                    utils.reportStatus()
+                else:
+                    print('MQTT 未连接', getConfig().mqtt.clientId, getConfig().mqtt.host, getConfig().mqtt.port,getConfig().mqtt.subTopic)
+                    utils.connectMQTT()
+            else:
+                print('WiFi 未连接')
+                if utils.autoConnectWifi():
+                    utils.connectMQTT()
+
+            if not getConfig().mqttStatus:
+                # 连接失败开启热点
+                utils.openAp()
+                startHttpServer()
+            else:
+                closeHttpServer()
+                utils.closeAp()
+
+        except Exception as e:
+            print(e)
+
+        time.sleep(10)
+taskCheck()

+ 4 - 0
version.json

@@ -0,0 +1,4 @@
+{
+  "bin": 1.1,
+  "01001": 1.1
+}