add datetime
This commit is contained in:
parent
02e6c84a44
commit
0a2fffb0ed
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user