Bonjour à tous !
Je me tourne vers vous car j'ai quelques soucis pour piloter les GPIO de mon raspberry via une page html qui execute un script en php..
J'ai fait une une page html qui contient quelques checkbox (12) dont 8 pour piloter 2 relais 5V..
Je ne comprend pas ou est l'erreur..
A savoir que je n'ai pas vraiment de notion de programmation et que j'ai fait cela en 4-5 jours alors si vous avez de remarques ou simplification.. je suis preneur..
et je me suis beaucoup inspirer de ce tuto sur le web https://td72pro.com/tutoriel-control...dune-page-web/
Merci à l'avance à ceux qui prendrons un peu de temps pour m'aider![]()
Code html : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213 <!doctype html> <html lang="fr"> <head> <meta charset="utf-8"> <title>Test commande GPIO</title> <link rel="stylesheet" type="text/css" href="/var/www/html/stylesheet.css"> </head> <body> <img src="/var/www/html/img/Schéma.jpg" border="0" align="Right" width=1000 height=100%/> <img src="/var/www/html/img/Titre.png" border="0" align="Center" width=390 height=100%/> <form action="/var/www/html/FonctionManuRelais.php" method="post"> <div class ="scenrel"> <div class="onoffblock"> <div class="onoffscenar"> <!-- 1ère gamme --> <div class="EnteteToggle"> <p>Scénario n°1 </p> </div> <input type="checkbox" name="onoffscenar1" class="onoffscenar-checkbox" id="myonoffscenar1" Notchecked> <label class="onoffscenar-label" for="myonoffscenar1"> <span class="onoffscenar-inner"></span> <span class="onoffscenar-switch"></span> </label> </div> <div class="onoffrelaisall"> <div class="EnteteToggle"> <a href="/var/www/html/ProgHoraireR1.html"><img src="/var/www/html/img/param1.png" border=0 align="right" width=65 height=100%/></a> <p>relais n°1</p> </div> <div class="onoffrelais1"> <input type="checkbox" name="relais1" class="onoffrelais-checkbox1" id="relais1" Notchecked> <label class="onoffrelais-label1" for="relais1"> <span class="onoffrelais-inner1"></span> <span class="onoffrelais-switch1"></span> </label> </div> <div class="EnteteToggle"> <a href="/var/www/html/ProgHoraireR2.html"><img src="/var/www/html/img/param1.png" border=0 align="right" width=65 height=100%/></a> <p>relais n°2</p> </div> <div class="onoffrelais1"> <input type="checkbox" name="relais2" class="onoffrelais-checkbox1" id="relais2" Notchecked> <label class="onoffrelais-label1" for="relais2"> <span class="onoffrelais-inner1"></span> <span class="onoffrelais-switch1"></span> </label> </div> </div> </div> <div class="onoffblock"> <!-- 2ème gammes --> <div class ="scenrel"> <div class="onoffblock"> <div class="onoffscenar"> <div class="EnteteToggle"> <p>Scénario n°2 </p> </div> <input type="checkbox" name="onoffscenar2" class="onoffscenar-checkbox" id="myonoffscenar2" Notchecked> <label class="onoffscenar-label" for="myonoffscenar2"> <span class="onoffscenar-inner"></span> <span class="onoffscenar-switch"></span> </label> </div> <div class="onoffrelaisall"> <div class="EnteteToggle"> <a href="/var/www/html/ProgHoraireR3.html"><img src="/var/www/html/img/param1.png" border=0 align="right" width=65 height=100%/></a> <p>relais n°3</p> </div> <div class="onoffrelais2"> <input type="checkbox" name="relais3" class="onoffrelais-checkbox2" id="relais3" NotChecked> <label class="onoffrelais-label2" for="relais3"> <span class="onoffrelais-inner2"></span> <span class="onoffrelais-switch2"></span> </label> </div> <div class="EnteteToggle"> <a href="/var/www/html/ProgHoraireR4.html"><img src="/var/www/html/img/param1.png" border=0 align="right" width=65 height=100%/></a> <p>relais n°4</p> </div> <div class="onoffrelais2"> <input type="checkbox" name="relais4" class="onoffrelais-checkbox2" id="relais4" NotChecked> <label class="onoffrelais-label2" for="relais4"> <span class="onoffrelais-inner2"></span> <span class="onoffrelais-switch2"></span> </label> </div> <div class="EnteteToggle"> <a href="/var/www/html/ProgHoraireR5.html"><img src="/var/www/html/img/param1.png" border=0 align="right" width=65 height=100%/></a> <p>relais n°5</p> </div> <div class="onoffrelais2 <input type="checkbox" name="relais5" class="onoffrelais-checkbox2" id="relais5" NotChecked> <label class="onoffrelais-label2" for="relais5"> <span class="onoffrelais-inner2"></span> <span class="onoffrelais-switch2"></span> </label> </div> </div> </div> <div class="onoffblock"> <!-- 3ème gammes --> <div class ="scenrel"> <div class="onoffblock"> <div class="onoffscenar"> <div class="EnteteToggle"> <p>Scénario n°3 </p> </div> <input type="checkbox" name="onoffscenar3" class="onoffscenar-checkbox" id="myonoffscenar3" Notchecked> <label class="onoffscenar-label" for="myonoffscenar3"> <span class="onoffscenar-inner"></span> <span class="onoffscenar-switch"></span> </label> </div> <div class="onoffrelaisall"> <div class="EnteteToggle"> <a href="/var/www/html/ProgHoraireR6.html"><img src="/var/www/html/img/param1.png" border=0 align="right" width=65 height=100%/></a> <p>relais n°6</p> </div> <div class="onoffrelais3"> <input type="checkbox" name="relais6" class="onoffrelais-checkbox3" id="relais6" NotChecked> <label class="onoffrelais-label3" for="relais6"> <span class="onoffrelais-inner3"></span> <span class="onoffrelais-switch3"></span> </label> </div> <div class="EnteteToggle"> <a href="/var/www/html/ProgHoraireR7.html"><img src="/var/www/html/img/param1.png" border=0 align="right" width=65 height=100%/></a> <p>relais n°7</p> </div> <div class="onoffrelais3"> <input type="checkbox" name="relais7" class="onoffrelais-checkbox3" id="relais7" NotChecked> <label class="onoffrelais-label3" for="relais7"> <span class="onoffrelais-inner3"></span> <span class="onoffrelais-switch3"></span> </label> </div> </div> </div> <div class="onoffblock"> <!-- 4ème gammes --> <div class ="scenrel"> <div class="onoffblock"> <div class="onoffscenar"> <div class="EnteteToggle"> <p>Scénario n°4 </p> </div> <input type="checkbox" name="onoffscenar4" class="onoffscenar-checkbox" id="myonoffscenar4" Notchecked> <label class="onoffscenar-label" for="myonoffscenar4"> <span class="onoffscenar-inner"></span> <span class="onoffscenar-switch"></span> </label> </div> <div class="onoffrelaisall"> <div class="EnteteToggle"> <a href="/var/www/html/ProgHoraireR8.html"><img src="/var/www/html/img/param1.png" border=0 align="right" width=65 height=100%/></a> <p>relais n°8</p> </div> <div class="onoffrelais4"> <input type="checkbox" name="relais8" class="onoffrelais-checkbox4" id="relais8" NotChecked> <label class="onoffrelais-label4" for="relais8"> <span class="onoffrelais-inner4"></span> <span class="onoffrelais-switch4"></span> </label> </div> <!-- fin gammes --> </div> </div> </form> </body> </html>
Pour essayer de piloter les GPIO ce script :
Code php : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115 <?php //relais n°1 system("gpio -g mode 4 out"); if($_POST['relais1'] == 'Checked') { system("gpio -g write 4 1"); } else { system("gpio -g write 4 0"); } header('Location: /var/www/html/index.html'); //relais n°2 system("gpio -g mode 17 out"); if($_POST['relais2'] == 'Checked') { system("gpio -g write 17 1"); } else { system("gpio -g write 17 0"); } header('Location: /var/www/html/index.html'); //relais n°3 system("gpio -g mode 27 out"); if($_POST['relais3'] == 'Checked') { system("gpio -g write 27 1"); } else { system("gpio -g write 27 0"); } header('Location: /var/www/html/index.php'); //relais n°4 system("gpio -g mode 22 out"); if($_POST['relais4'] == 'Checked') { system("gpio -g write 22 1"); } else { system("gpio -g write 22 0"); } header('Location: /var/www/html/index.php'); //relais n°5 system("gpio -g mode 14 out"); if($_POST['relais5'] == 'Checked') { system("gpio -g write 14 1"); } else { system("gpio -g write 14 0"); } header('Location: /var/www/html/index.php'); //relais n°6 system("gpio -g mode 15 out"); if($_POST['relais6'] == 'Checked') { system("gpio -g write 15 1"); } else { system("gpio -g write 15 0"); } header('Location: /var/www/html/index.php'); //relais n°7 system("gpio -g mode 18 out"); if($_POST['relais7'] == 'Checked') { system("gpio -g write 18 1"); } else { system("gpio -g write 18 0"); } header('Location: /var/www/html/index.php'); //relais n°8 system("gpio -g mode 23 out"); if($_POST['relais8'] == 'Checked') { system("gpio -g write 23 1"); } else { system("gpio -g write 23 0"); } header('Location: /var/www/html/index.php'); ?>
et pour la mise en page
Code css : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164 html { zoom: 0.8; } body{ background-color: black; /* Le fond de la page sera noir */ color: white; /* Le texte de la page sera blanc */ } .scenrel{ display:flex; flex-direction: column; } .onoffblock{ display:flex; padding:5px } .onoffblock > .onoffscenar{ border:5px black solid; border :1px black solid; margin-right:15px } .EnteteToggle { position: relative; width: 200px } .EnteteToggle > p{ margin-left:10px; } .onoffrelaisall{ border:5px black dotted; } .onoffscenar { position: relative; width: 174px; user-select: none; float:left } .onoffrelais1,.onoffrelais2, .onoffrelais3,.onoffrelais4 { position: relative; width: 90px; user-select: none; } .onoffscenar-checkbox, .onoffrelais-checkbox1, .onoffrelais-checkbox2,.onoffrelais-checkbox3, .onoffrelais-checkbox4 { display: none; } .onoffscenar-label { display: block; overflow: hidden; cursor: pointer; border: 2px solid #999999; border-radius: 6px; } .onoffrelais-label1,.onoffrelais-label2, .onoffrelais-label3,.onoffrelais-label4 { display: block; overflow: hidden; cursor: pointer; border: 2px solid #999999; border-radius: 20px; } .onoffscenar-inner, .onoffrelais-inner1, .onoffrelais-inner2,.onoffrelais-inner3, .onoffrelais-inner4{ display: block; width: 200%; margin-left: -100%; transition: margin 0.3s ease-in 0s; } .onoffscenar-inner:before, .onoffscenar-inner:after, .onoffrelais-inner1:before, .onoffrelais-inner1:after, .onoffrelais-inner2:before, .onoffrelais-inner2:after, .onoffrelais-inner3:before, .onoffrelais-inner3:after, .onoffrelais-inner4:before, .onoffrelais-inner4:after { display: block; float: left; width: 50%; height: 30px; padding: 0; line-height: 30px; font-size: 14px; color: white; font-family: Trebuchet, Arial, sans-serif; font-weight: bold; box-sizing: border-box; } .onoffscenar-inner:before { content: "MANUEL"; padding-left: 10px; background-color: #FF0000; color: #FFFFFF; } .onoffscenar-inner:after { content: "AUTOMATIQUE"; padding-right: 10px; background-color: #FF8800; color: #FFFFFF; text-align: right; } .onoffrelais-inner1:before { content: "ON"; padding-left: 10px; background-color: #3314FF; color: #FFFFFF; } .onoffrelais-inner2:before { content: "ON"; padding-left: 10px; background-color: #9CBCD6; color: #FFFFFF; } .onoffrelais-inner3:before { content: "ON"; padding-left: 10px; background-color: #F5E500; color: #FFFFFF; } .onoffrelais-inner4:before { content: "ON"; padding-left: 10px; background-color: #AB1ED6; color: #FFFFFF; } .onoffrelais-inner1:after,.onoffrelais-inner2:after, .onoffrelais-inner3:after,.onoffrelais-inner4:after{ content: "OFF"; padding-right: 10px; background-color: #EEEEEE; color: #999999; text-align: right; } .onoffscenar-switch { display: block; width: 35px; margin: -2.5px; background: #FFFFFF; position: absolute; bottom: 0; top:49px; height:37px; right: 140px; border: 2px solid #999999; border-radius: 6px; transition: all 0.3s ease-in 0s; } .onoffrelais-switch1,.onoffrelais-switch2, .onoffrelais-switch3,.onoffrelais-switch4 { display: block; width: 36px; margin: -3px; background: #FFFFFF; position: absolute; top: 0; bottom: 0; right: 56px; border: 2px solid #999999; border-radius: 20px; transition: all 0.3s ease-in 0s; } .onoffscenar-checkbox:checked + .onoffscenar-label .onoffscenar-inner, .onoffrelais-checkbox1:checked + .onoffrelais-label1 .onoffrelais-inner1, .onoffrelais-checkbox2:checked + .onoffrelais-label2 .onoffrelais-inner2, .onoffrelais-checkbox3:checked + .onoffrelais-label3 .onoffrelais-inner3, .onoffrelais-checkbox4:checked + .onoffrelais-label4 .onoffrelais-inner4{ margin-left: 0; } .onoffscenar-checkbox:checked + .onoffscenar-label .onoffscenar-switch, .onoffrelais-checkbox1:checked + .onoffrelais-label1 .onoffrelais-switch1, .onoffrelais-checkbox2:checked + .onoffrelais-label2 .onoffrelais-switch2, .onoffrelais-checkbox3:checked + .onoffrelais-label3 .onoffrelais-switch3, .onoffrelais-checkbox4:checked + .onoffrelais-label4 .onoffrelais-switch4{ right: 0px; }
Partager