def restart_and_reconnect(self, err_msg): my_rtc = rtc_esp32.RtcEsp32() # initialize the class msg = my_rtc.format_datetime(my_rtc.rtc_now()) + ' -> ' + err_msg print(msg) with open('error.txt' , 'a') as f: f.write(msg+'\n') utime.sleep(10) machine.reset()
def connect_and_subscribe(self): # try: print('-----------------------------------------------------------') my_wifi = wifi_esp32.WifiEsp32(WIFI_SSID, WIFI_PW) my_wifi.connect_wifi() mqtt_client = rhodo.mqtt_connect(MQTT_CLIENT_ID, MQTT_BROKER) print('MQTT mqtt_client connected on ' + MQTT_BROKER + ' with the topic "' + MQTT_TOPIC_PUB + '"') # Real time clock (RTC) initialisation my_rtc = rtc_esp32.RtcEsp32() # initialize the class my_rtc.rtc_init() # initialize the rtc with local date and time txt = "now date and time :" + my_rtc.format_datetime(my_rtc.rtc_now()) + '\n' print('-----------------------------------------------------------') return mqtt_client
led.on() utime.sleep(ton) led.off() utime.sleep(toff) time.sleep(tpause) if __name__ == '__main__': # WIFI, mosquitto MQTT connection and RTC sync print('-----------------------------------------------------------') my_wifi = wifi_esp32.WifiEsp32(WIFI_SSID, WIFI_PW) my_wifi.connect_wifi() mqtt_client = mqtt_connect(MQTT_CLIENT_ID, MQTT_BROKER) print('MQTT mqtt_client connected on ' + MQTT_BROKER + ' with the topic "' + MQTT_TOPIC_PUB + '"') # Real time clock (RTC) initialisation my_rtc = rtc_esp32.RtcEsp32() # initialize the class my_rtc.rtc_init() # initialize the rtc with local date and time txt = "now date and time :" + my_rtc.format_datetime(now) + '\n' print('-----------------------------------------------------------') # imported classes initialisation my_ds18x20 = ds18x20_esp32.Ds18x20Esp32(DS18B20_PIN) # DS18B20 temperature sensors my_dhtxx = dhtxx_esp32.DhtxxEsp32() # DHT11 and DHT22 air temperature and humidity sensors my_seesaw = stemma_soil_sensor.StemmaSoilSensor(i2c) # seesaw soil humidity and temperature sensor my_HW390_soil_1 = voltage_esp32.VoltageEsp32(HW390_PIN_1) # HW390 soil humidity sensor 1 my_HW390_soil_2 = voltage_esp32.VoltageEsp32(HW390_PIN_2) # HW390 soil humidity sensor 2 my_divider_voltage = voltage_esp32.VoltageEsp32(ANALOG_PIN, R1, R2) # for battery voltage passe = 1 while True: