diff --git a/l2.py b/l2.py new file mode 100644 index 0000000000000000000000000000000000000000..74ac1d23372bb4b6e74a9b52a1dfc624eec9e714 --- /dev/null +++ b/l2.py @@ -0,0 +1,71 @@ + +import RPi.GPIO as GPIO +import os, time +from multiprocessing import Process + +RECEIVER_PIN = 23 +RECEIVER_PIN2 = 25 +def callback_func(channel): + if GPIO.input(channel): + print("Lichtschranke 1 wurde unterbrochen {}") + + # alternativ kann ein Script / Shell Befehl gestartet werden + # os.system("ls") +def callback_func2(channel): + if GPIO.input(channel): + print("Lichtschranke 2 wurde unterbrochen {}") + + # alternativ kann ein Script / Shell Befehl gestartet werden + # os.system("ls") +def light_barrier1_check(): + try: + while True: + time.sleep(1) + if(GPIO.input(23)== GPIO.HIGH): + print("Schranke 1 verbunden") + except: + # Event wieder entfernen mittels: + GPIO.remove_event_detect(RECEIVER_PIN) + +def light_barrier2_check(): + try: + while True: + time.sleep(1) + if(GPIO.input(25) == GPIO.HIGH): + print("Schranke 2 verbunden") + except: + # Event wieder entfernen mittels: + GPIO.remove_event_detect(RECEIVER_PIN2) +def light_barrier3_check(i): + + while(GPIO.input(25) == GPIO.HIGH): + if(i==1): + i = 0 + print(i) + #print("Schranke verbunden") + time.sleep(3) + print("Schranke unterbrochen") + i = 1 + + + +if __name__ == '__main__': + GPIO.setmode(GPIO.BCM) + GPIO.setwarnings(False) + + #GPIO.setup(RECEIVER_PIN, GPIO.IN) + GPIO.setup(RECEIVER_PIN2, GPIO.IN) + #GPIO.add_event_detect(RECEIVER_PIN, GPIO.RISING, callback=callback_func, bouncetime=200) + #GPIO.add_event_detect(RECEIVER_PIN2, GPIO.RISING, callback=callback_func2, bouncetime=200) + #light_barrier1_check() + i = 0 + while True: + light_barrier3_check(i) + #light_barrier2_check() + #p1 = Process(target=light_barrier1_check) + #p1.start() + #p2 = Process(target=light_barrier2_check) + #p2.start() + #p1.join() + #p2.join() + diff --git a/light.py b/light.py new file mode 100644 index 0000000000000000000000000000000000000000..8de3c59ce9acc3ec043e7952f9abafdfb367701b --- /dev/null +++ b/light.py @@ -0,0 +1,22 @@ +import RPi.GPIO as GPIO +import time + +GPIO.setmode(GPIO.BCM) + +GPIO.setup(23, GPIO.OUT) +GPIO.setup(24, GPIO.IN) + +for i in range(5): + GPIO.output(23, GPIO.HIGH) + time.sleep(0.5) + GPIO.output(23, GPIO.LOW) + time.sleep(0.5) + +# Endlosschleife +while True: + if GPIO.input(24) == 0: + # Ausschalten + GPIO.output(23, GPIO.LOW) + else: + # Einschalten + GPIO.output(23, GPIO.HIGH) \ No newline at end of file diff --git a/light_sensor.py b/light_sensor.py new file mode 100644 index 0000000000000000000000000000000000000000..176d88e906e5d329f041ecb3d4e686acf4e5b321 --- /dev/null +++ b/light_sensor.py @@ -0,0 +1,54 @@ + +import RPi.GPIO as GPIO +import os, time +from multiprocessing import Process + +RECEIVER_PIN = 23 +RECEIVER_PIN2 = 25 +def callback_func(channel): + if GPIO.input(channel): + print("Lichtschranke 1 wurde unterbrochen {}") + + # alternativ kann ein Script / Shell Befehl gestartet werden + # os.system("ls") +def callback_func2(channel): + if GPIO.input(channel): + print("Lichtschranke 2 wurde unterbrochen {}") + + # alternativ kann ein Script / Shell Befehl gestartet werden + # os.system("ls") +def light_barrier1_check(): + try: + while True: + time.sleep(1) + if(GPIO.input(23)== GPIO.HIGH): + print("Schranke 1 verbunden") + except: + # Event wieder entfernen mittels: + GPIO.remove_event_detect(RECEIVER_PIN) + +def light_barrier2_check(): + try: + while True: + time.sleep(1) + if(GPIO.input(25) == GPIO.HIGH): + print("Schranke 2 verbunden") + except: + # Event wieder entfernen mittels: + GPIO.remove_event_detect(RECEIVER_PIN2) + +if __name__ == '__main__': + GPIO.setmode(GPIO.BCM) + GPIO.setwarnings(False) + + GPIO.setup(RECEIVER_PIN, GPIO.IN) + #GPIO.setup(RECEIVER_PIN2, GPIO.IN) + GPIO.add_event_detect(RECEIVER_PIN, GPIO.RISING, callback=callback_func, bouncetime=200) + #GPIO.add_event_detect(RECEIVER_PIN2, GPIO.RISING, callback=callback_func2, bouncetime=200) + light_barrier1_check() + #p1 = Process(target=light_barrier1_check) + #p1.start() + #p2 = Process(target=light_barrier2_check) + #p2.start() + #p1.join() + #p2.join() diff --git a/requestTest.py b/requestTest.py new file mode 100644 index 0000000000000000000000000000000000000000..399982f2ddab77554acc1209c9edcad45e16bf9d --- /dev/null +++ b/requestTest.py @@ -0,0 +1,17 @@ +import requests +from requests.structures import CaseInsensitiveDict +#headers = CaseInsensitiveDict() +#headers["Accept"] = "application/json" +#headers["Content-Type"] = "application/json" +base_path = 'https://192.168.0.94:44378/api/parkingrow' +response = requests.get(base_path, verify=False) +print(response.status_code) +print(response.text) +update_path = 'https://192.168.0.94:44378/api/parkingrow/1' +headers = {"Content-Type": "application/json", "Accept":"application/json"} +data = {"increase":True} +patch_request = requests.patch(update_path, json=data, verify=False) +print(patch_request.status_code) +print(patch_request.text) +#patch_request = requests.patch(base_path + '/1',headers=headers, data={'increasing':True}, verify=False) +#print(patch_request.status_code) \ No newline at end of file diff --git a/thread_light.py b/thread_light.py new file mode 100644 index 0000000000000000000000000000000000000000..5ac866a931a9759e827b814d3c0e75917af9a5e4 --- /dev/null +++ b/thread_light.py @@ -0,0 +1,56 @@ + +import RPi.GPIO as GPIO +import os, time, asyncio + + +RECEIVER_PIN = 23 +RECEIVER_PIN2 = 25 +def callback_func(channel): + if GPIO.input(channel): + print("Lichtschranke 1 wurde unterbrochen {}") + + # alternativ kann ein Script / Shell Befehl gestartet werden + # os.system("ls") +def callback_func2(channel): + if GPIO.input(channel): + print("Lichtschranke 2 wurde unterbrochen {}") + + # alternativ kann ein Script / Shell Befehl gestartet werden + # os.system("ls") +async def light_barrier1_check(): + try: + while True: + await asyncio.sleep(1) + if(GPIO.input(23)== GPIO.HIGH): + print("Schranke 1 verbunden") + except: + # Event wieder entfernen mittels: + GPIO.remove_event_detect(RECEIVER_PIN) + +async def light_barrier2_check(): + try: + while True: + await asyncio.sleep(1) + if(GPIO.input(25) == GPIO.HIGH): + print("Schranke 2 verbunden") + except: + # Event wieder entfernen mittels: + GPIO.remove_event_detect(RECEIVER_PIN2) + +async def run_task(): + task1 = asyncio.create_task(light_barrier1_check()) + task2 = asyncio.create_task(light_barrier2_check()) + await task1 + await task2 + +if __name__ == '__main__': + GPIO.setmode(GPIO.BCM) + GPIO.setwarnings(False) + + GPIO.setup(RECEIVER_PIN, GPIO.IN) + GPIO.setup(RECEIVER_PIN2, GPIO.IN) + GPIO.add_event_detect(RECEIVER_PIN, GPIO.RISING, callback=callback_func, bouncetime=200) + GPIO.add_event_detect(RECEIVER_PIN2, GPIO.RISING, callback=callback_func2, bouncetime=200) + + asyncio.run(run_task()) +