Add starting point for futher details

This commit is contained in:
Praxis.bot 2024-06-27 11:14:28 +02:00
parent f0d0cd707d
commit a78baa3a78
8 changed files with 121 additions and 1 deletions

22
Pi-py-Code/cooling.py Normal file
View file

@ -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()

17
Pi-py-Code/gasventile.py Normal file
View file

@ -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)

22
Pi-py-Code/lüfter.py Normal file
View file

@ -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")

41
Pi-py-Code/protocoll.py Normal file
View file

@ -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)

15
Pi-py-Code/tmp_0x09.py Normal file
View file

@ -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))

View file

@ -1,3 +1,6 @@
# bh3a-Icetruck-Challenge-1-3 # bh3a-Icetruck-Challenge-1-3
Itech Icetruck Challenges Sommer 2024 Itech Icetruck Challenges Sommer 2024
Contact:
bhh-Icetruck@i3le.net

Binary file not shown.