From ebfef71cd0b88100a71486cf258abfa4cc11d2ec Mon Sep 17 00:00:00 2001 From: Rodeta <44084093+Rood95@users.noreply.github.com> Date: Mon, 17 Jan 2022 07:41:15 +0100 Subject: [PATCH] upload files --- l2.py | 71 +++++++++++++++++++++++++++++++++++++++++++++++++ light.py | 22 +++++++++++++++ light_sensor.py | 54 +++++++++++++++++++++++++++++++++++++ requestTest.py | 17 ++++++++++++ thread_light.py | 56 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 220 insertions(+) create mode 100644 l2.py create mode 100644 light.py create mode 100644 light_sensor.py create mode 100644 requestTest.py create mode 100644 thread_light.py diff --git a/l2.py b/l2.py new file mode 100644 index 0000000..74ac1d2 --- /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 0000000..8de3c59 --- /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 0000000..176d88e --- /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 0000000..399982f --- /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 0000000..5ac866a --- /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()) + -- GitLab