added next test

Signed-off-by: Ebbe Baß <ebbe@ping-mee.de>
master
Ebbe Baß 2022-07-09 23:51:40 +02:00
parent 6c32af997d
commit 1428fa5722
2 changed files with 43 additions and 13 deletions

32
main.py
View File

@ -0,0 +1,32 @@
import time
import os
from datetime import datetime
try:
import paho.mqtt.client as mqtt
import gpiozero
except ImportError:
print('Some modules are missing. Try to install them with "pip3 install -r requirements.txt"')
exit()
def debug_print(message: str):
now = datetime.now()
current_time = now.strftime("%H:%M:%S")
print('[DEBUG]['+current_time+'] '+message)
def error_print(message: str):
now = datetime.now()
current_time = now.strftime("%H:%M:%S")
print('[ERROR]['+current_time+'] '+message)
def relay_controller(pin: int, status: str):
if status == "ON":
relay = gpiozero.OutputDevice(pin, active_high=False, initial_value=False)
relay.on()
elif status == "OFF":
relay = gpiozero.OutputDevice(pin, active_high=False, initial_value=False)
relay.off()
else:
error_print("Unknown status for relay ("+status+")")
def get_water_lvl():

24
test.py
View File

@ -1,17 +1,15 @@
import smbus
import time
import os
import gpiozero
pins = [14,15]
address = 0x57
sensor = smbus.SMBus(1)
# for pin in pins:
# print(pin)
# relay = gpiozero.OutputDevice(pin, active_high=False, initial_value=False)
# relay.on()
# time.sleep(1)
# relay.off()
while True:
sensor.write_byte(address, 0x01)
time.sleep(0.2)
relay = gpiozero.OutputDevice(14, active_high=False, initial_value=False)
relay.on()
time.sleep(30)
relay.off()
bytes = sensor.read_i2c_block_data(address, 0, 3)
distance = ((bytes[0] << 16) + (bytes[1] << 8) + bytes[2]) / 10000
print(distance)