main.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import time
  2. import utils
  3. from config import getConfig
  4. from httpServer import startHttpServer,closeHttpServer
  5. # 硬重启
  6. #import machine;machine.reset()
  7. def taskCheck():
  8. """
  9. 定时检查连接
  10. :return:
  11. """
  12. while True:
  13. try:
  14. if utils.getStatus():
  15. print('WiFi 正常', utils.getWifiConnectInfo())
  16. if getConfig().mqttStatus:
  17. print('MQTT 正常', getConfig().mqtt.clientId, getConfig().mqtt.host, getConfig().mqtt.port,getConfig().mqtt.subTopic)
  18. utils.reportStatus()
  19. else:
  20. print('MQTT 未连接', getConfig().mqtt.clientId, getConfig().mqtt.host, getConfig().mqtt.port,getConfig().mqtt.subTopic)
  21. utils.connectMQTT()
  22. else:
  23. print('WiFi 未连接')
  24. if utils.autoConnectWifi():
  25. utils.connectMQTT()
  26. if not getConfig().mqttStatus:
  27. # 连接失败开启热点
  28. utils.openAp()
  29. startHttpServer()
  30. else:
  31. closeHttpServer()
  32. utils.closeAp()
  33. except Exception as e:
  34. print(e)
  35. time.sleep(10)
  36. taskCheck()