add datetime

This commit is contained in:
robert 2021-01-24 23:11:08 +01:00
parent 02e6c84a44
commit 0a2fffb0ed
1 changed files with 8 additions and 0 deletions

View File

@ -10,6 +10,12 @@ import Adafruit_DHT
import paho.mqtt.publish as publish
import paho.mqtt.client as paho
# DATETIME
now = datetime.now()
#print("now =", now)
#Output format: DD/MM/YYYY H:M:S
dt_string = now.strftime("%d/%m/%Y %H:%M:%S")
# MQTT credentials
#mqtt_username = 'homeassistant' # MQTT client username
#mqtt_password = '3355' # MQTT client password
@ -30,6 +36,7 @@ client = paho.Client(protocol=paho.MQTTv31) # * set a random string (max 23 cha
# Command topic
temperature_topic = 'weathersensors/' + client_id + '/temperature'
humidity_topic = 'weathersensors/' + client_id + '/humidity'
time_topic = 'weathersensors/' + client_id + 'time'
#client connection
#client.username_pw_set(mqtt_username, mqtt_password) # MQTT server credentials
@ -49,6 +56,7 @@ while True:
# Publish our data
client.publish(temperature_topic, temperature)
client.publish(humidity_topic, humidity)
client.publish(time_topic, dt_string)
time.sleep(30)