async def check_internet(): global int_err_count try: while True: await asyncio.sleep(60) print("Check Internet connect... ") if not internet_connected(): print("Internet connect fail...") int_err_count += 1 if int_err_count >= config.CONFIG['INT_CRIT_ERR']: client.disconnect() wifi.wlan.disconnect() machine.reset() if int_err_count >= config.CONFIG['INT_MAX_ERR']: print("Internet reconnect") client.disconnect() wifi.wlan.disconnect() wifi.activate() except Exception as error: print("Error in Internet connection: [Exception] %s: %s" % (type(error).__name__, error))
import gc import machine import utime as time import uasyncio as asyncio import usocket as socket import ustruct as struct from machine import Pin, SPI, WDT from nrf24l01 import NRF24L01 from mqtt import MQTTClient import wifi import config gc.enable() wifi.activate() int_err_count = 0 ping_mqtt = 0 ping_fail = 0 water = False wdt = WDT() # Init MQTT client = MQTTClient(config.CONFIG['MQTT_CLIENT'], config.CONFIG['MQTT_BROKER'], user=config.CONFIG['MQTT_USER'], password=config.CONFIG['MQTT_PASSWORD'], port=config.CONFIG['MQTT_PORT']) # Init NRF24L01 csn = Pin(config.NRFCFG["csn"], mode=Pin.OUT, value=1)