回答編集履歴

1

コードの追加

2021/12/31 01:50

投稿

morita05041984
morita05041984

スコア3

test CHANGED
@@ -15,3 +15,277 @@
15
15
 
16
16
 
17
17
  いま現状、30分設定しても26分で停止してしまってます…。
18
+
19
+
20
+
21
+
22
+
23
+ ```index.html
24
+
25
+ <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
26
+
27
+ <html>
28
+
29
+ <head>
30
+
31
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
32
+
33
+ <title>WebIOPi | Light Control</title>
34
+
35
+ <script type="text/javascript" src="/webiopi.js"></script>
36
+
37
+ <script type="text/javascript">
38
+
39
+ webiopi().ready(function() {
40
+
41
+ // Following function will process data received from set/getLightHours macro.
42
+
43
+ var updateLightHours = function(macro, args, response) {
44
+
45
+ var hours = response.split(";");
46
+
47
+ // Following lines use jQuery functions
48
+
49
+ $("#inputOn").val(hours[0]);
50
+
51
+ $("#inputOff").val(hours[1]);
52
+
53
+ }
54
+
55
+
56
+
57
+ // Immediately call getLightHours macro to update the UI with current values
58
+
59
+ // "getLightHours" refers to macro name
60
+
61
+ // [] is an empty array, because getLightHours macro does not take any argument
62
+
63
+ // updateLightHours is the callback function, defined above
64
+
65
+ webiopi().callMacro("getLightHours", [], updateLightHours);
66
+
67
+
68
+
69
+ // Create a button to call setLightHours macro
70
+
71
+ var sendButton = webiopi().createButton("sendButton", "Send", function() {
72
+
73
+ // Arguments sent to the macro
74
+
75
+ var hours = [$("#inputOn").val(), $("#inputOff").val()];
76
+
77
+ // Call the macro
78
+
79
+ webiopi().callMacro("setLightHours", hours, updateLightHours);
80
+
81
+ });
82
+
83
+
84
+
85
+ // Append the button to the controls box using a jQuery function
86
+
87
+ $("#controls").append(sendButton);
88
+
89
+
90
+
91
+ // Create a "Light" labeled button for GPIO 17
92
+
93
+ var button = webiopi().createGPIOButton(17, "Light");
94
+
95
+
96
+
97
+ // Append the button to the controls box
98
+
99
+ $("#controls").append(button);
100
+
101
+
102
+
103
+ // Refresh GPIO buttons
104
+
105
+ // pass true to refresh repeatedly of false to refresh once
106
+
107
+ webiopi().refreshGPIO(true);
108
+
109
+
110
+
111
+ });
112
+
113
+ </script>
114
+
115
+
116
+
117
+ <style type="text/css">
118
+
119
+ button {
120
+
121
+ display: block;
122
+
123
+ margin: 5px 5px 5px 5px;
124
+
125
+ width: 160px;
126
+
127
+ height: 45px;
128
+
129
+ font-size: 24pt;
130
+
131
+ font-weight: bold;
132
+
133
+ color: white;
134
+
135
+ }
136
+
137
+
138
+
139
+ #gpio17.LOW {
140
+
141
+ background-color: Black;
142
+
143
+ }
144
+
145
+
146
+
147
+ #gpio17.HIGH {
148
+
149
+ background-color: Blue;
150
+
151
+ }
152
+
153
+ </style>
154
+
155
+
156
+
157
+ </head>
158
+
159
+ <body>
160
+
161
+
162
+
163
+ <div align="center">
164
+
165
+ 稼働時間を入力してください<input type="text" id="inputOn" />
166
+
167
+
168
+
169
+
170
+
171
+ <div id="controls"></div>
172
+
173
+
174
+
175
+ </div>
176
+
177
+
178
+
179
+ </body>
180
+
181
+ </html>
182
+
183
+ ```
184
+
185
+
186
+
187
+ ```script.py
188
+
189
+ import webiopi
190
+
191
+ import RPi.GPIO as GPIO
192
+
193
+ import time
194
+
195
+
196
+
197
+
198
+
199
+
200
+
201
+
202
+
203
+
204
+
205
+ GPIO = webiopi.GPIO
206
+
207
+
208
+
209
+ LIGHT = 17 # GPIO pin using BCM numbering
210
+
211
+
212
+
213
+ HOUR_ON = 0 # Turn Light ON at 08:00
214
+
215
+ HOUR_OFF = 0 # Turn Light OFF at 18:00
216
+
217
+
218
+
219
+ # setup function is automatically called at WebIOPi startup
220
+
221
+ def setup():
222
+
223
+ # set the GPIO used by the light to output
224
+
225
+ GPIO.setFunction(LIGHT, GPIO.OUT)
226
+
227
+
228
+
229
+
230
+
231
+
232
+
233
+ # loop function is repeatedly called by WebIOPi
234
+
235
+ def loop():
236
+
237
+ # retrieve current datetime
238
+
239
+ for i in range(1):
240
+
241
+ GPIO.output(LIGHT, GPIO.HIGH) # LED on
242
+
243
+ time.sleep(0)
244
+
245
+ GPIO.output(LIGHT, GPIO.LOW) # LED off
246
+
247
+ time.sleep(HOUR_ON + 10)
248
+
249
+
250
+
251
+
252
+
253
+
254
+
255
+
256
+
257
+ # destroy function is called at WebIOPi shutdown
258
+
259
+ def destroy():
260
+
261
+ GPIO.digitalWrite(LIGHT, GPIO.LOW)
262
+
263
+
264
+
265
+ @webiopi.macro
266
+
267
+ def getLightHours():
268
+
269
+ return "%d;%d" % (HOUR_ON, HOUR_OFF)
270
+
271
+
272
+
273
+ @webiopi.macro
274
+
275
+ def setLightHours(on, off):
276
+
277
+ global HOUR_ON, HOUR_OFF
278
+
279
+ HOUR_ON = int(on)
280
+
281
+ HOUR_OFF = int(off)
282
+
283
+ return getLightHours()
284
+
285
+ ```
286
+
287
+
288
+
289
+ こちらがコードです。
290
+
291
+ 初めてだらけで何が何だかわかりませんが、一応sheepの引数には変数を置いておき、変数にユーザが任意の分数をテキストボックスにいれて時間を設定するプログラムを書いたつもりですが、おかしいところありますか??