Merge branch 'main' of https://git.jerick.xyz/jerick/homeassistantPi
This commit is contained in:
@@ -16,14 +16,8 @@ password = 'falrenforbreakfast'
|
|||||||
|
|
||||||
client_id = f'python-mqtt-office-{random.randint(0, 1000)}'
|
client_id = f'python-mqtt-office-{random.randint(0, 1000)}'
|
||||||
|
|
||||||
#We first check if a libgpiod process is running. If yes, we kill it!
|
|
||||||
for proc in psutil.process_iter():
|
|
||||||
if proc.name() == 'libgpiod_pulsein' or proc.name() == 'libgpiod_pulsei':
|
|
||||||
proc.kill()
|
|
||||||
|
|
||||||
#D20 is the pin number, DHT11 is the sensor type
|
|
||||||
sensor = adafruit_dht.DHT11(board.D20)
|
|
||||||
|
|
||||||
|
#Function Definitions
|
||||||
def connect_mqtt():
|
def connect_mqtt():
|
||||||
def on_connect(client, userdata, flags, rc):
|
def on_connect(client, userdata, flags, rc):
|
||||||
if rc == 0:
|
if rc == 0:
|
||||||
@@ -85,11 +79,19 @@ def publish(client, temp, humidity):
|
|||||||
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
client = connect_mqtt()
|
#We first check if a libgpiod process is running. If yes, we kill it!
|
||||||
client.loop_start()
|
for proc in psutil.process_iter():
|
||||||
|
if proc.name() == 'libgpiod_pulsein' or proc.name() == 'libgpiod_pulsei':
|
||||||
|
proc.kill()
|
||||||
|
|
||||||
|
#D20 is the pin number, DHT11 is the sensor type
|
||||||
|
sensor = adafruit_dht.DHT11(board.D20)
|
||||||
|
#Run functions
|
||||||
|
client = connect_mqtt() # Connect to Broker
|
||||||
|
client.loop_start() #Start loop
|
||||||
temp, humidity = getValues(sensor)
|
temp, humidity = getValues(sensor)
|
||||||
getValues(sensor)
|
getValues(sensor)
|
||||||
publish(client, temp, humidity)
|
publish(client, temp, humidity)
|
||||||
time.sleep (300.0)
|
time.sleep (300.0)
|
||||||
client.loop_stop() #Stop loop
|
client.loop_stop() #Stop loop
|
||||||
client.disconnect() # disconnect
|
client.disconnect() # Disconnect
|
||||||
|
|||||||
Reference in New Issue
Block a user