From 7573a32573c7e9455ed69323ab426a1426ff7067 Mon Sep 17 00:00:00 2001 From: Steffen Volkmann Date: Mon, 3 Jun 2019 12:27:36 +0200 Subject: [PATCH] replace piface with gpiozero lib --- .gitignore | 3 ++ .pydevproject | 16 +++--- Doc/wpa_supplicant.conf.txt | 3 +- README.md | 48 ++++++++++++++---- SimpleWebControl/simple_server.py | 27 +++++++--- mc_control.sh | 10 ++-- mc_control/mc_statemachine.py | 21 ++++---- pyface_simulation/__init__.py | 0 .../__pycache__/__init__.cpython-32.pyc | Bin 155 -> 0 bytes .../pifacedigitalio.cpython-32.pyc | Bin 1533 -> 0 bytes pyface_simulation/pifacedigitalio.py | 32 ------------ utils/fgpio.py | 19 +++++++ www/mc.html | 8 +-- 13 files changed, 109 insertions(+), 78 deletions(-) create mode 100644 .gitignore delete mode 100644 pyface_simulation/__init__.py delete mode 100644 pyface_simulation/__pycache__/__init__.cpython-32.pyc delete mode 100644 pyface_simulation/__pycache__/pifacedigitalio.cpython-32.pyc delete mode 100644 pyface_simulation/pifacedigitalio.py create mode 100644 utils/fgpio.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b68812e --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +archiv +*.pyc + diff --git a/.pydevproject b/.pydevproject index 7cc0692..d7e7c54 100644 --- a/.pydevproject +++ b/.pydevproject @@ -1,8 +1,8 @@ - - -python -python 3.0 - -/RP_RemoteControl - - + + +python +python interpreter + +/RP_RemoteControl + + diff --git a/Doc/wpa_supplicant.conf.txt b/Doc/wpa_supplicant.conf.txt index 7a2c894..0f7847b 100644 --- a/Doc/wpa_supplicant.conf.txt +++ b/Doc/wpa_supplicant.conf.txt @@ -1,4 +1,4 @@ -# sudo cat ./etc/wpa_supplicant/wpa_supplicant.conf +# sudo cat ./etc/wpa_supplicant/wpa_supplicant.conf ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 @@ -10,4 +10,3 @@ network={ pairwise=CCMP auth_alg=OPEN } - diff --git a/README.md b/README.md index 5a67d8c..7d0d9f7 100644 --- a/README.md +++ b/README.md @@ -1,21 +1,51 @@ -Raspberry PI Allgemein +# RP_Jalousiecontrol +allows web based remote control of Jalousie + +## requirements + +### hardware +Rasperry PI + +### software +- python 3.x +- raspberrian + +## installation: + +### debian packages +sudo apt install git python3-pifacedigitalio python-pifacedigitalio + +### checkout sources +cd /var/lib +sudo mkdir Jalousiecontrol +sudo chown pi:pi Jalousiecontrol +git clone https://gitea.devpool.net/stevo/RP_Jalousiecontrol.git + +### copy startup scripts and enable autostart +sudo cp ./mc_control.sh /etc/init.d/mc_control.sh +sudo /etc/init.d/mc_control.sh start +sudo /etc/init.d/mc_control.sh stop +sudo update-rc.d mc_control.sh defaults + +sudo raspi-config -> 5 - interface options -> P4 SPI -> enable kernel modules + + + +# bookmarks + +## Raspberry PI Allgemein - http://www.mikrocontroller.net/articles/Raspberry_Pi -Ajax, Java Script, CCS: +## Ajax, Java Script, CCS: - http://flask.pocoo.org/docs/patterns/jquery/ - http://xyzzyxyzzy.net/2012/07/01/ajax-fun-with-jquery-python/ - http://getbootstrap.com/components/#panels - http://openbook.galileocomputing.de/javascript/ - http://www.w3schools.com/js/js_htmldom_document.asp -Python webserver mit SSL +## Python webserver mit SSL - http://www.piware.de/2011/01/creating-an-https-server-in-python/ - http://code.activestate.com/recipes/442473-simple-http-server-supporting-ssl-secure-communica/ -webserver atomatisch starten +## webserver atomatisch starten - http://raspberrywebserver.com/serveradmin/run-a-script-on-start-up.html - -sudo cp ./mc_control.sh /etc/init.d/mc_control.sh -sudo /etc/init.d/mc_control.sh start -sudo /etc/init.d/mc_control.sh stop -sudo update-rc.d mc_control.sh defaults \ No newline at end of file diff --git a/SimpleWebControl/simple_server.py b/SimpleWebControl/simple_server.py index 386845d..9d80f91 100644 --- a/SimpleWebControl/simple_server.py +++ b/SimpleWebControl/simple_server.py @@ -15,6 +15,9 @@ import time from urllib.parse import urlparse from utils.web import handle_file_request, get_my_ip from mc_control.mc_statemachine import mc_state_machine, mc_event +from gpiozero import LED +from gpiozero.pins.pigpio import PiGPIOFactory + HOST_NAME = '' #'localhost' PORT_NUMBER = 8000 @@ -117,13 +120,23 @@ class myhandler(BaseHTTPRequestHandler): class ThreadedHTTPServer(ThreadingMixIn, HTTPServer): ''' ''' -def StartStateMachines(): +def StartStateMachines(factory): global sm sm = list() - sm.append( mc_state_machine(0, 1)) - sm.append( mc_state_machine(2, 3)) - sm.append( mc_state_machine(4, 5)) - sm.append( mc_state_machine(6, 7)) + + up_1 = LED(16, pin_factory=factory) + down_1 = LED(12, pin_factory=factory) + up_2 = LED(6, pin_factory=factory) + down_2 = LED(20, pin_factory=factory) + up_3 = LED(13, pin_factory=factory) + down_3 = LED(21, pin_factory=factory) + up_4 = LED(19, pin_factory=factory) + down_4 = LED(26, pin_factory=factory) + + sm.append( mc_state_machine(up_1, down_1)) + sm.append( mc_state_machine(up_2, down_2)) + sm.append( mc_state_machine(up_3, down_3)) + sm.append( mc_state_machine(up_4, down_4)) def CloseStateMachines(): global sm @@ -136,7 +149,9 @@ def CloseStateMachines(): if __name__ == '__main__': global sm - StartStateMachines() + + factory = PiGPIOFactory(host='jalousiecontrol') + StartStateMachines(factory) httpd = ThreadedHTTPServer((HOST_NAME,PORT_NUMBER),myhandler) diff --git a/mc_control.sh b/mc_control.sh index 68278af..392ea5a 100755 --- a/mc_control.sh +++ b/mc_control.sh @@ -1,8 +1,8 @@ #! /bin/sh ### BEGIN INIT INFO # Provides: start and stop of the mc_control webservice -# Required-Start: -# Required-Stop: +# Required-Start: +# Required-Stop: # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: start and stop of the mc_control webservice @@ -12,15 +12,15 @@ # Aktionen case "$1" in start) - /usr/bin/python3 /home/pi/10_RP_MotorControl/SimpleWebControl/simple_server.py & + /usr/bin/python3 /var/lib/RP_Jalousiecontrol/SimpleWebControl/simple_server.py & ;; stop) killall python3 ;; restart) killall python3 - /usr/bin/python3 /home/pi/10_RP_MotorControl/SimpleWebControl/simple_server.py & + /usr/bin/python3 /var/lib/RP_Jalousiecontrol/SimpleWebControl/simple_server.py & ;; esac -exit 0 \ No newline at end of file +exit 0 diff --git a/mc_control/mc_statemachine.py b/mc_control/mc_statemachine.py index e5bb2cc..e9db48a 100644 --- a/mc_control/mc_statemachine.py +++ b/mc_control/mc_statemachine.py @@ -18,13 +18,9 @@ DOWN - in down position from queue import Queue import threading from mc_control.mc_timer import mc_timer +#from pyface_simulation import pifacedigitalio -try: - import pifacedigitalio #@UnresolvedImport -except: - from pyface_simulation import pifacedigitalio - class Position(): def __init__(self, min_value=0, max_value=100, step=1): @@ -74,7 +70,8 @@ class mc_state_machine(threading.Thread): self.__running = True self.Port_Up = Port_Up self.Port_Down = Port_Down - self.pfd = pifacedigitalio.PiFaceDigital() # creates a PiFace Digtal object + #self.pfd = pifacedigitalio.PiFaceDigital() # creates a PiFace Digtal object + self.timeout_value = timeout_value # sec. self.PositionUpdateTimerPeriode = timeout_value/10 # sec. self.MotorTimeout = mc_timer() @@ -122,22 +119,22 @@ class mc_state_machine(threading.Thread): print('MotorUp') print('Switch Port={} on'.format(self.Port_Up)) print('Switch Port={} off'.format(self.Port_Down)) - self.pfd.leds[self.Port_Up].value = 1 - self.pfd.leds[self.Port_Down].value = 0 + self.Port_Up.on() + self.Port_Down.off() def MotorDown(self): print('MotorDown') print('Switch Port={} off'.format(self.Port_Up)) print('Switch Port={} on'.format(self.Port_Down)) - self.pfd.leds[self.Port_Up].value = 0 - self.pfd.leds[self.Port_Down].value = 1 + self.Port_Up.off() + self.Port_Down.on() def MotorStop(self): print('MotorStop') print('Switch Port={} off'.format(self.Port_Up)) print('Switch Port={} off'.format(self.Port_Down)) - self.pfd.leds[self.Port_Up].value = 0 - self.pfd.leds[self.Port_Down].value = 0 + self.Port_Up.off() + self.Port_Down.off() def run(self): diff --git a/pyface_simulation/__init__.py b/pyface_simulation/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/pyface_simulation/__pycache__/__init__.cpython-32.pyc b/pyface_simulation/__pycache__/__init__.cpython-32.pyc deleted file mode 100644 index 756a421e4d0165a42de5d38a7c47654b29a1f48f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 155 zcmd1d;pIB^eSL5;0}@~avK@f9m<33rFfasbfJFQ>fCK{?QR)B`bGC{}Ni0c>DJaU% zO3f~bF*Jw|3W)d3FUc=*&d)0;%Fl@@s7y;tPK__l%q`7HEXmBzi;0iV%*!l^kJl@x WEads5MEXzSLeAZTs~i9&)aXSd5HtZU-$payergEB{&8l!o_8#-MjwLAT|< z4*3acuVor5ZrV!r+Ag}v5t;vna2Yr9h%L~)S9d^JDl87|B{UyKAxNVDnv3K{-?KAxjTl&pSOFyJ&V*4iH&f++ydkxzN qoJ(6S-=9_UuczeB{#7>O>|S3Xy1

- Gruppe 1 + Alex 1

@@ -99,7 +99,7 @@ @@ -129,7 +129,7 @@ @@ -160,7 +160,7 @@