Browse Source

replace piface with gpiozero lib

Steffen Volkmann 5 years ago
parent
commit
7573a32573

+ 3 - 0
.gitignore View File

1
+archiv
2
+*.pyc
3
+

+ 8 - 8
.pydevproject View File

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
-# sudo cat  ./etc/wpa_supplicant/wpa_supplicant.conf 
1
+# sudo cat  ./etc/wpa_supplicant/wpa_supplicant.conf
2
 ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
2
 ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
3
 update_config=1
3
 update_config=1
4
 
4
 
10
 	pairwise=CCMP
10
 	pairwise=CCMP
11
 	auth_alg=OPEN
11
 	auth_alg=OPEN
12
 }
12
 }
13
-

+ 39 - 9
README.md View File

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
 - http://www.mikrocontroller.net/articles/Raspberry_Pi
37
 - http://www.mikrocontroller.net/articles/Raspberry_Pi
3
 
38
 
4
-Ajax, Java Script, CCS:
39
+## Ajax, Java Script, CCS:
5
 - http://flask.pocoo.org/docs/patterns/jquery/
40
 - http://flask.pocoo.org/docs/patterns/jquery/
6
 - http://xyzzyxyzzy.net/2012/07/01/ajax-fun-with-jquery-python/
41
 - http://xyzzyxyzzy.net/2012/07/01/ajax-fun-with-jquery-python/
7
 - http://getbootstrap.com/components/#panels
42
 - http://getbootstrap.com/components/#panels
8
 - http://openbook.galileocomputing.de/javascript/
43
 - http://openbook.galileocomputing.de/javascript/
9
 - http://www.w3schools.com/js/js_htmldom_document.asp
44
 - http://www.w3schools.com/js/js_htmldom_document.asp
10
 
45
 
11
-Python webserver mit SSL
46
+## Python webserver mit SSL
12
 - http://www.piware.de/2011/01/creating-an-https-server-in-python/
47
 - http://www.piware.de/2011/01/creating-an-https-server-in-python/
13
 - http://code.activestate.com/recipes/442473-simple-http-server-supporting-ssl-secure-communica/
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
 - http://raspberrywebserver.com/serveradmin/run-a-script-on-start-up.html
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
 from urllib.parse import urlparse
15
 from urllib.parse import urlparse
16
 from utils.web import handle_file_request, get_my_ip
16
 from utils.web import handle_file_request, get_my_ip
17
 from mc_control.mc_statemachine import mc_state_machine, mc_event
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
 HOST_NAME   = '' #'localhost'
22
 HOST_NAME   = '' #'localhost'
20
 PORT_NUMBER = 8000
23
 PORT_NUMBER = 8000
117
 class ThreadedHTTPServer(ThreadingMixIn, HTTPServer):
120
 class ThreadedHTTPServer(ThreadingMixIn, HTTPServer):
118
     ''' '''
121
     ''' '''
119
     
122
     
120
-def StartStateMachines():
123
+def StartStateMachines(factory):
121
         global sm 
124
         global sm 
122
         sm = list()
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
 def CloseStateMachines():
141
 def CloseStateMachines():
129
         global sm 
142
         global sm 
136
 if __name__ == '__main__':
149
 if __name__ == '__main__':
137
         
150
         
138
         global sm
151
         global sm
139
-        StartStateMachines()
152
+
153
+        factory = PiGPIOFactory(host='jalousiecontrol')
154
+        StartStateMachines(factory)
140
         
155
         
141
         httpd = ThreadedHTTPServer((HOST_NAME,PORT_NUMBER),myhandler)
156
         httpd = ThreadedHTTPServer((HOST_NAME,PORT_NUMBER),myhandler)
142
         
157
         

+ 5 - 5
mc_control.sh View File

1
 #! /bin/sh
1
 #! /bin/sh
2
 ### BEGIN INIT INFO
2
 ### BEGIN INIT INFO
3
 # Provides:          start and stop of the mc_control webservice
3
 # Provides:          start and stop of the mc_control webservice
4
-# Required-Start:    
5
-# Required-Stop:     
4
+# Required-Start:
5
+# Required-Stop:
6
 # Default-Start:     2 3 4 5
6
 # Default-Start:     2 3 4 5
7
 # Default-Stop:      0 1 6
7
 # Default-Stop:      0 1 6
8
 # Short-Description: start and stop of the mc_control webservice
8
 # Short-Description: start and stop of the mc_control webservice
12
 # Aktionen
12
 # Aktionen
13
 case "$1" in
13
 case "$1" in
14
 	start)
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
 	stop)
17
 	stop)
18
         killall python3
18
         killall python3
19
         ;;
19
         ;;
20
 	restart)
20
 	restart)
21
         killall python3
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
 esac
24
 esac
25
 
25
 
26
-exit 0
26
+exit 0

+ 9 - 12
mc_control/mc_statemachine.py View File

18
 from queue import Queue
18
 from queue import Queue
19
 import threading
19
 import threading
20
 from mc_control.mc_timer import mc_timer
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
 class Position():
25
 class Position():
30
     def __init__(self, min_value=0, max_value=100, step=1):
26
     def __init__(self, min_value=0, max_value=100, step=1):
74
         self.__running = True 
70
         self.__running = True 
75
         self.Port_Up = Port_Up
71
         self.Port_Up = Port_Up
76
         self.Port_Down = Port_Down
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
         self.timeout_value = timeout_value # sec.
75
         self.timeout_value = timeout_value # sec.
79
         self.PositionUpdateTimerPeriode = timeout_value/10 # sec.
76
         self.PositionUpdateTimerPeriode = timeout_value/10 # sec.
80
         self.MotorTimeout = mc_timer()
77
         self.MotorTimeout = mc_timer()
122
         print('MotorUp')
119
         print('MotorUp')
123
         print('Switch Port={} on'.format(self.Port_Up))
120
         print('Switch Port={} on'.format(self.Port_Up))
124
         print('Switch Port={} off'.format(self.Port_Down))
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
     def MotorDown(self):
125
     def MotorDown(self):
129
         print('MotorDown')
126
         print('MotorDown')
130
         print('Switch Port={} off'.format(self.Port_Up))
127
         print('Switch Port={} off'.format(self.Port_Up))
131
         print('Switch Port={} on'.format(self.Port_Down))
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
     def MotorStop(self): 
132
     def MotorStop(self): 
136
         print('MotorStop')
133
         print('MotorStop')
137
         print('Switch Port={} off'.format(self.Port_Up))
134
         print('Switch Port={} off'.format(self.Port_Up))
138
         print('Switch Port={} off'.format(self.Port_Down))
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
     def run(self):
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
-'''
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

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