コード例 #1
0
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:
        
        INTERNAL_BLUE_LED.on() # blue led on
        # message initialisation with pass nr and datetime
        msg = 'Passe: ' + str(passe) + '\n'
#         now = my_rtc.rtc_now()  # get date and time
        datetime_formated = my_rtc.format_datetime(my_rtc.rtc_now())
        txt = "now date and time :" + datetime_formated + '\n'
コード例 #2
0
    return mqtt_client

if __name__ == '__main__':
    
    
    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 + '"')
    print('-----------------------------------------------------------')

    my_rtc = rtc_esp32.RtcEsp32()  # initialize the class
    my_rtc.rtc_init()  # initialize the rtc with local date and time
    
    my_ds18x20 = ds18x20_esp32.Ds18x20Esp32(DS18B20_PIN)
    my_dhtxx = dhtxx_esp32.DhtxxEsp32()
    my_seesaw = stemma_soil_sensor.StemmaSoilSensor(i2c)
    my_HW390_soil = voltage_esp32.VoltageEsp32(HW390_PIN)
    my_voltage = voltage_esp32.VoltageEsp32(ANALOG_PIN, R1, R2)
    
    passe = 1
    while True:
        
        msg = 'Passe: ' + str(passe) + '\n'
        INTERNAL_LED.on()
        now = my_rtc.rtc_now()  # get date and time
        datetime_formated = my_rtc.format_datetime(now)
        txt = "now date and time :" + datetime_formated + '\n'
        msg += txt