diff --git a/Pi-py-Code/cooling.py b/Pi-py-Code/cooling.py new file mode 100644 index 0000000..2ab904b --- /dev/null +++ b/Pi-py-Code/cooling.py @@ -0,0 +1,22 @@ +from tmp_0x09 import get_temp +from lüfter import luefter +from gasventile import gasventile +from protocoll import insert_data + +def apply_cooling(): + try: + temp_sensor= ((get_temp(0x09)+get_temp(0x0a)+get_temp(0x0b))/3) + except ZeroDivisionError: + temp_sensor=0 + #insert_data(temp_sensor, 1) + if (temp_sensor < -5): + luefter(0) + elif (temp_sensor < 10): + luefter(1) + else: + luefter(1) + gasventile(5) + print (temp_sensor) + +if __name__ == '__main__': + apply_cooling() diff --git a/Pi-py-Code/gasventile.py b/Pi-py-Code/gasventile.py new file mode 100644 index 0000000..1375a37 --- /dev/null +++ b/Pi-py-Code/gasventile.py @@ -0,0 +1,17 @@ +import time +from smbus import SMBus + +addr = 0x8 # bus address +bus = SMBus(1) # indicates /dev/ic2-1 + +def gasventile(zeit): + bus.write_byte(addr, 86) # send V + time.sleep(zeit) + bus.write_byte(addr, 118) # send v + time.sleep(0.1) + +if __name__ == "__main__": + gasventile(15); + print("Gas Ventile opend 1s") + # Tur Fan on + time.sleep(1) diff --git a/Pi-py-Code/lüfter.py b/Pi-py-Code/lüfter.py new file mode 100644 index 0000000..a6416c2 --- /dev/null +++ b/Pi-py-Code/lüfter.py @@ -0,0 +1,22 @@ +import time +from smbus import SMBus + +addr = 0x8 # bus address +bus = SMBus(1) # indicates /dev/ic2-1 + + +def luefter(state): + if (state==1): + bus.write_byte(addr, 70 ) # send F # send L / 76 + elif(state==0): + bus.write_byte(addr, 102 ) #send f # send l / 108 + time.sleep(0.1) + +if __name__ == "__main__": + # Tur Fan on + luefter(1) + print("turn on Luefter") + time.sleep(10) + #Turn Luefter off + luefter(0) + print("turn luefter off") diff --git a/Pi-py-Code/protocoll.py b/Pi-py-Code/protocoll.py new file mode 100644 index 0000000..ba6fdad --- /dev/null +++ b/Pi-py-Code/protocoll.py @@ -0,0 +1,41 @@ +import mysql.connector +from mysql.connector import errorcode +from tmp_0x09 import get_temp + + +# MySQL database connection setup +config = { + 'user': 'root', # dein MySQL-Benutzername + 'password': '', # dein MySQL-Passwort (standardmäßig leer bei XAMPP) + 'host': '127.0.0.1', + 'database': 'arduino', + 'raise_on_warnings': True +} + +def insert_data(temp, sensor_id): + try: + cnx = mysql.connector.connect(**config) + cursor = cnx.cursor() + add_data = ("INSERT INTO Sensordaten " + "(temperatur, sensor_id) " + "VALUES (%s, %s)") + data = (temp, sensor_id) + cursor.execute(add_data, data) + cnx.commit() + cursor.close() + cnx.close() + except mysql.connector.Error as err: + if err.errno == errorcode.ER_ACCESS_DENIED_ERROR: + print("Etwas ist mit deinem Benutzernamen oder Passwort falsch.") + elif err.errno == errorcode.ER_BAD_DB_ERROR: + print("Die Datenbank existiert nicht.") + else: + print(err) + else: + print("Daten erfolgreich eingefügt.") + +if __name__ == '__main__': + while True: + insert_data(get_temp(0x09), 1) + insert_data(get_temp(0x0a), 2) + #insert_data(get_temp(0x0b), 3) diff --git a/sql_create_and_inserts b/Pi-py-Code/sql_create_and_inserts similarity index 100% rename from sql_create_and_inserts rename to Pi-py-Code/sql_create_and_inserts diff --git a/Pi-py-Code/tmp_0x09.py b/Pi-py-Code/tmp_0x09.py new file mode 100644 index 0000000..b4c2f33 --- /dev/null +++ b/Pi-py-Code/tmp_0x09.py @@ -0,0 +1,15 @@ +import smbus +import time + +bus = smbus.SMBus(1) +address = 0x09 # Arduino I2C Address + +def get_temp(addr): + # request data + temp = (bus.read_byte(addr) - 75) + time.sleep(1) + return temp + + +if __name__ == '__main__': + print("temp of 0x09:",get_temp(address)) diff --git a/README.md b/README.md index 28a09cf..1e4f0d6 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ # bh3a-Icetruck-Challenge-1-3 -Itech Icetruck Challenges Sommer 2024 \ No newline at end of file +Itech Icetruck Challenges Sommer 2024 + +Contact: +bhh-Icetruck@i3le.net diff --git a/__pycache__/protocoll.cpython-39.pyc b/__pycache__/protocoll.cpython-39.pyc new file mode 100644 index 0000000..b2331b9 Binary files /dev/null and b/__pycache__/protocoll.cpython-39.pyc differ