Browse Source

replace piface with gpiozero lib

Steffen Volkmann 4 years ago
parent
commit
7573a32573

+ 3 - 0
.gitignore View File

@@ -0,0 +1,3 @@
1
+archiv
2
+*.pyc
3
+

+ 8 - 8
.pydevproject View File

@@ -1,8 +1,8 @@
1
-<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
-<?eclipse-pydev version="1.0"?><pydev_project>
3
-<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">python</pydev_property>
4
-<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 3.0</pydev_property>
5
-<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
6
-<path>/RP_RemoteControl</path>
7
-</pydev_pathproperty>
8
-</pydev_project>
1
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
+<?eclipse-pydev version="1.0"?><pydev_project>
3
+<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">python</pydev_property>
4
+<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python interpreter</pydev_property>
5
+<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
6
+<path>/RP_RemoteControl</path>
7
+</pydev_pathproperty>
8
+</pydev_project>

+ 1 - 2
Doc/wpa_supplicant.conf.txt View File

@@ -1,4 +1,4 @@
1
-# sudo cat  ./etc/wpa_supplicant/wpa_supplicant.conf 
1
+# sudo cat  ./etc/wpa_supplicant/wpa_supplicant.conf
2 2
 ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
3 3
 update_config=1
4 4
 
@@ -10,4 +10,3 @@ network={
10 10
 	pairwise=CCMP
11 11
 	auth_alg=OPEN
12 12
 }
13
-

+ 39 - 9
README.md View File

@@ -1,21 +1,51 @@
1
-Raspberry PI Allgemein
1
+# RP_Jalousiecontrol
2
+allows web based remote control of Jalousie
3
+
4
+## requirements
5
+
6
+### hardware
7
+Rasperry PI
8
+
9
+### software
10
+- python 3.x
11
+- raspberrian
12
+
13
+## installation:
14
+
15
+### debian packages
16
+sudo apt install git python3-pifacedigitalio python-pifacedigitalio
17
+
18
+### checkout sources
19
+cd /var/lib
20
+sudo mkdir Jalousiecontrol
21
+sudo chown pi:pi Jalousiecontrol
22
+git clone https://gitea.devpool.net/stevo/RP_Jalousiecontrol.git
23
+
24
+### copy startup scripts and enable autostart
25
+sudo cp ./mc_control.sh /etc/init.d/mc_control.sh
26
+sudo /etc/init.d/mc_control.sh start
27
+sudo /etc/init.d/mc_control.sh stop
28
+sudo update-rc.d mc_control.sh defaults
29
+
30
+sudo raspi-config -> 5 - interface options -> P4 SPI -> enable kernel modules
31
+
32
+
33
+
34
+# bookmarks
35
+
36
+## Raspberry PI Allgemein
2 37
 - http://www.mikrocontroller.net/articles/Raspberry_Pi
3 38
 
4
-Ajax, Java Script, CCS:
39
+## Ajax, Java Script, CCS:
5 40
 - http://flask.pocoo.org/docs/patterns/jquery/
6 41
 - http://xyzzyxyzzy.net/2012/07/01/ajax-fun-with-jquery-python/
7 42
 - http://getbootstrap.com/components/#panels
8 43
 - http://openbook.galileocomputing.de/javascript/
9 44
 - http://www.w3schools.com/js/js_htmldom_document.asp
10 45
 
11
-Python webserver mit SSL
46
+## Python webserver mit SSL
12 47
 - http://www.piware.de/2011/01/creating-an-https-server-in-python/
13 48
 - http://code.activestate.com/recipes/442473-simple-http-server-supporting-ssl-secure-communica/
14 49
 
15
-webserver atomatisch starten
50
+## webserver atomatisch starten
16 51
 - http://raspberrywebserver.com/serveradmin/run-a-script-on-start-up.html
17
-
18
-sudo cp ./mc_control.sh /etc/init.d/mc_control.sh
19
-sudo /etc/init.d/mc_control.sh start
20
-sudo /etc/init.d/mc_control.sh stop
21
-sudo update-rc.d mc_control.sh defaults

+ 21 - 6
SimpleWebControl/simple_server.py View File

@@ -15,6 +15,9 @@ import time
15 15
 from urllib.parse import urlparse
16 16
 from utils.web import handle_file_request, get_my_ip
17 17
 from mc_control.mc_statemachine import mc_state_machine, mc_event
18
+from gpiozero import LED
19
+from gpiozero.pins.pigpio import PiGPIOFactory
20
+
18 21
 
19 22
 HOST_NAME   = '' #'localhost'
20 23
 PORT_NUMBER = 8000
@@ -117,13 +120,23 @@ class myhandler(BaseHTTPRequestHandler):
117 120
 class ThreadedHTTPServer(ThreadingMixIn, HTTPServer):
118 121
     ''' '''
119 122
     
120
-def StartStateMachines():
123
+def StartStateMachines(factory):
121 124
         global sm 
122 125
         sm = list()
123
-        sm.append( mc_state_machine(0, 1))
124
-        sm.append( mc_state_machine(2, 3))
125
-        sm.append( mc_state_machine(4, 5))
126
-        sm.append( mc_state_machine(6, 7))
126
+        
127
+        up_1   = LED(16, pin_factory=factory)  
128
+        down_1 = LED(12, pin_factory=factory)  
129
+        up_2   = LED(6, pin_factory=factory)  
130
+        down_2 = LED(20, pin_factory=factory)  
131
+        up_3   = LED(13,  pin_factory=factory)  
132
+        down_3 = LED(21, pin_factory=factory)  
133
+        up_4   = LED(19, pin_factory=factory)  
134
+        down_4 = LED(26, pin_factory=factory)  
135
+        
136
+        sm.append( mc_state_machine(up_1, down_1))
137
+        sm.append( mc_state_machine(up_2, down_2))
138
+        sm.append( mc_state_machine(up_3, down_3))
139
+        sm.append( mc_state_machine(up_4, down_4))
127 140
             
128 141
 def CloseStateMachines():
129 142
         global sm 
@@ -136,7 +149,9 @@ def CloseStateMachines():
136 149
 if __name__ == '__main__':
137 150
         
138 151
         global sm
139
-        StartStateMachines()
152
+
153
+        factory = PiGPIOFactory(host='jalousiecontrol')
154
+        StartStateMachines(factory)
140 155
         
141 156
         httpd = ThreadedHTTPServer((HOST_NAME,PORT_NUMBER),myhandler)
142 157
         

+ 5 - 5
mc_control.sh View File

@@ -1,8 +1,8 @@
1 1
 #! /bin/sh
2 2
 ### BEGIN INIT INFO
3 3
 # Provides:          start and stop of the mc_control webservice
4
-# Required-Start:    
5
-# Required-Stop:     
4
+# Required-Start:
5
+# Required-Stop:
6 6
 # Default-Start:     2 3 4 5
7 7
 # Default-Stop:      0 1 6
8 8
 # Short-Description: start and stop of the mc_control webservice
@@ -12,15 +12,15 @@
12 12
 # Aktionen
13 13
 case "$1" in
14 14
 	start)
15
-        /usr/bin/python3 /home/pi/10_RP_MotorControl/SimpleWebControl/simple_server.py &
15
+        /usr/bin/python3 /var/lib/RP_Jalousiecontrol/SimpleWebControl/simple_server.py &
16 16
         ;;
17 17
 	stop)
18 18
         killall python3
19 19
         ;;
20 20
 	restart)
21 21
         killall python3
22
-        /usr/bin/python3 /home/pi/10_RP_MotorControl/SimpleWebControl/simple_server.py &
22
+        /usr/bin/python3 /var/lib/RP_Jalousiecontrol/SimpleWebControl/simple_server.py &
23 23
         ;;
24 24
 esac
25 25
 
26
-exit 0
26
+exit 0

+ 9 - 12
mc_control/mc_statemachine.py View File

@@ -18,13 +18,9 @@ DOWN      - in down position
18 18
 from queue import Queue
19 19
 import threading
20 20
 from mc_control.mc_timer import mc_timer
21
+#from pyface_simulation import pifacedigitalio
21 22
 
22 23
 
23
-try:
24
-    import pifacedigitalio #@UnresolvedImport
25
-except:
26
-    from pyface_simulation import pifacedigitalio
27
-    
28 24
 
29 25
 class Position():
30 26
     def __init__(self, min_value=0, max_value=100, step=1):
@@ -74,7 +70,8 @@ class mc_state_machine(threading.Thread):
74 70
         self.__running = True 
75 71
         self.Port_Up = Port_Up
76 72
         self.Port_Down = Port_Down
77
-        self.pfd = pifacedigitalio.PiFaceDigital() # creates a PiFace Digtal object
73
+        #self.pfd = pifacedigitalio.PiFaceDigital() # creates a PiFace Digtal object
74
+        
78 75
         self.timeout_value = timeout_value # sec.
79 76
         self.PositionUpdateTimerPeriode = timeout_value/10 # sec.
80 77
         self.MotorTimeout = mc_timer()
@@ -122,22 +119,22 @@ class mc_state_machine(threading.Thread):
122 119
         print('MotorUp')
123 120
         print('Switch Port={} on'.format(self.Port_Up))
124 121
         print('Switch Port={} off'.format(self.Port_Down))
125
-        self.pfd.leds[self.Port_Up].value = 1
126
-        self.pfd.leds[self.Port_Down].value = 0
122
+        self.Port_Up.on()
123
+        self.Port_Down.off()
127 124
                 
128 125
     def MotorDown(self):
129 126
         print('MotorDown')
130 127
         print('Switch Port={} off'.format(self.Port_Up))
131 128
         print('Switch Port={} on'.format(self.Port_Down))
132
-        self.pfd.leds[self.Port_Up].value = 0
133
-        self.pfd.leds[self.Port_Down].value = 1
129
+        self.Port_Up.off()
130
+        self.Port_Down.on()
134 131
         
135 132
     def MotorStop(self): 
136 133
         print('MotorStop')
137 134
         print('Switch Port={} off'.format(self.Port_Up))
138 135
         print('Switch Port={} off'.format(self.Port_Down))
139
-        self.pfd.leds[self.Port_Up].value = 0
140
-        self.pfd.leds[self.Port_Down].value = 0
136
+        self.Port_Up.off()
137
+        self.Port_Down.off()
141 138
         
142 139
                         
143 140
     def run(self):

+ 0 - 0
pyface_simulation/__init__.py View File


BIN
pyface_simulation/__pycache__/__init__.cpython-32.pyc View File


BIN
pyface_simulation/__pycache__/pifacedigitalio.cpython-32.pyc View File


+ 0 - 32
pyface_simulation/pifacedigitalio.py View File

@@ -1,32 +0,0 @@
1
-'''
2
-Created on 29.06.2014
3
-
4
-@author: stevo
5
-'''
6
-
7
-
8
-
9
-class RelayClass():
10
-    value = 0
11
-
12
-class LedClass():
13
-    value = 0
14
-
15
-class PiFaceDigital():
16
-    
17
-    def __init__(self):
18
-        self.relays = []
19
-        self.relays.append( RelayClass())
20
-        self.relays.append( RelayClass())
21
-        
22
-        self.leds = []
23
-        self.leds.append( LedClass())
24
-        self.leds.append( LedClass())
25
-        self.leds.append( LedClass())
26
-        self.leds.append( LedClass())
27
-        self.leds.append( LedClass())
28
-        self.leds.append( LedClass())
29
-        self.leds.append( LedClass())
30
-        self.leds.append( LedClass())
31
-        
32
-        return None 

+ 19 - 0
utils/fgpio.py View File

@@ -0,0 +1,19 @@
1
+'''
2
+Created on Jun 3, 2019
3
+
4
+@author: stevo
5
+'''
6
+
7
+from gpiozero import LED
8
+from gpiozero.pins.pigpio import PiGPIOFactory
9
+from time import sleep
10
+
11
+remote_factory = PiGPIOFactory(host='192.168.1.97')
12
+led = LED(21, pin_factory=remote_factory)
13
+
14
+while True:
15
+    led.on()
16
+    sleep(5)
17
+    led.off()
18
+    sleep(5)
19
+    

+ 4 - 4
www/mc.html View File

@@ -72,7 +72,7 @@
72 72
 			    <div class="panel-heading">
73 73
 			      <h4 class="panel-title">
74 74
 			        <a data-toggle="collapse" data-parent="#accordion" href="#collapseOne">
75
-			          Gruppe 1
75
+			          Alex 1
76 76
 			        </a>
77 77
 			      </h4>
78 78
 			    </div>
@@ -99,7 +99,7 @@
99 99
 			    <div class="panel-heading">
100 100
 			      <h4 class="panel-title">
101 101
 			        <a data-toggle="collapse" data-parent="#accordion" href="#collapseTwo">
102
-			          Gruppe 2
102
+			          Alex 2
103 103
 			        </a>
104 104
 			      </h4>
105 105
 			    </div>
@@ -129,7 +129,7 @@
129 129
 			    <div class="panel-heading">
130 130
 			      <h4 class="panel-title">
131 131
 			        <a data-toggle="collapse" data-parent="#accordion" href="#collapseThree">
132
-			          Gruppe 3
132
+			          Linus 3
133 133
 			        </a>
134 134
 			      </h4>
135 135
 			    </div>
@@ -160,7 +160,7 @@
160 160
 			    <div class="panel-heading">
161 161
 			      <h4 class="panel-title">
162 162
 			        <a data-toggle="collapse" data-parent="#accordion" href="#collapseFour">
163
-			          Gruppe 4
163
+			          Linus 4
164 164
 			        </a>
165 165
 			      </h4>
166 166
 			    </div>