From 1428fa572251b30ee319b721553912d75c7b2dae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ebbe=20Ba=C3=9F?= Date: Sat, 9 Jul 2022 23:51:40 +0200 Subject: [PATCH] added next test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ebbe Baß --- main.py | 32 ++++++++++++++++++++++++++++++++ test.py | 24 +++++++++++------------- 2 files changed, 43 insertions(+), 13 deletions(-) diff --git a/main.py b/main.py index e69de29..5539baa 100644 --- a/main.py +++ b/main.py @@ -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(): + \ No newline at end of file diff --git a/test.py b/test.py index 9f64949..846eb13 100644 --- a/test.py +++ b/test.py @@ -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() \ No newline at end of file + bytes = sensor.read_i2c_block_data(address, 0, 3) + distance = ((bytes[0] << 16) + (bytes[1] << 8) + bytes[2]) / 10000 + + print(distance) \ No newline at end of file