7
7
entry = {'Group' :'Town' ,'Folder' :'Address' ,'Name' :'Location' }
8
8
# settings
9
9
entry ['Content||Settings||captureTime||@function' ]= 'select'
10
- entry ['Content||Settings||captureTime||@value' ]= 3600
10
+ entry ['Content||Settings||captureTime||@value' ]= ' 3600'
11
11
entry ['Content||Settings||captureTime||@excontainer' ]= True
12
- entry ['Content||Settings||captureTime||@options||10' ]= 10
13
- entry ['Content||Settings||captureTime||@options||60' ]= 60
14
- entry ['Content||Settings||captureTime||@options||600' ]= 600
15
- entry ['Content||Settings||captureTime||@options||3600' ]= 3600
12
+ entry ['Content||Settings||captureTime||@options||10' ]= '10sec'
13
+ entry ['Content||Settings||captureTime||@options||60' ]= '1min'
14
+ entry ['Content||Settings||captureTime||@options||600' ]= '10min'
15
+ entry ['Content||Settings||captureTime||@options||3600' ]= '1h'
16
+ entry ['Content||Settings||captureTime||@options||36000' ]= '10h'
16
17
17
18
entry ['Content||Settings||mode||@function' ]= 'select'
18
19
entry ['Content||Settings||mode||@value' ]= 'alarm'
@@ -112,7 +113,7 @@ def initOutputs():
112
113
113
114
# process repsponse
114
115
def writeOutputs (response ):
115
- global leds ,strOutputs , entry
116
+ global leds ,entry
116
117
if type (response ) is not bool :
117
118
for key ,value in response .items ():
118
119
key = key + '||@value'
@@ -128,6 +129,7 @@ def writeOutputs(response):
128
129
print (value )
129
130
if key in entry :
130
131
entry [key ]= value
132
+ #print(key+': '+entry[key])
131
133
132
134
# ===================================== Sensors ===================================
133
135
def initInputs ():
@@ -138,7 +140,7 @@ def initInputs():
138
140
initInputs ()
139
141
140
142
def readInputs ():
141
- global leds , entry , activity
143
+ global entry
142
144
entry ['Date' ]= time .strftime ('%Y-%m-%d %H:%M:%S' ,time .localtime ())
143
145
entry ['Content||Status||timestamp||@value' ]= int (time .time ())
144
146
entry ['Content||Status||activity||@value' ]= activity
@@ -149,51 +151,50 @@ def readInputs():
149
151
entry [entryKey ]= int (leds [key ].is_active )
150
152
if hasGpioZero :
151
153
entry ['Content||Status||cpuTemperature||@value' ]= CPUTemperature ().temperature
154
+ return dict (entry )
152
155
153
156
# ===================================== Behaviour =================================
154
157
activity = 0
155
158
156
159
def captureFileNames (filename ):
157
- global dirs
158
160
frame = 0
159
161
while frame < 4 :
160
162
yield dirs ['media' ]+ '/' + filename + '_' + str (int (time .time ()))+ '_' + str (frame )+ '.jpg'
161
163
frame += 1
162
164
163
165
busyCapturing = False
164
166
def capture (filename ):
165
- global busyCapturing ,entry
167
+ global busyCapturing ,leds
166
168
busyCapturing = True
169
+ if entry ['Content||Settings||mode||@value' ]!= 'idle' :
170
+ leds ['Content||Settings||light||@value' ].on ()
171
+ captureEntry = readInputs ()
167
172
if hasPiCamera and entry ['Content||Settings||mode||@value' ]!= 'idle' :
168
173
with picamera .PiCamera (framerate = 2 ) as camera :
169
174
camera .start_preview ()
170
175
time .sleep (1 )
171
176
camera .capture_sequence (captureFileNames (filename ),use_video_port = False ,resize = None )
172
- mediaItems2stack ()
177
+ mediaItems2stack (captureEntry )
173
178
busyCapturing = False
179
+ if (int (entry ['Content||Settings||light||@value' ])== 1 ):
180
+ leds ['Content||Settings||light||@value' ].on ()
181
+ else :
182
+ leds ['Content||Settings||light||@value' ].off ()
174
183
175
184
def motionA ():
176
- global busyCapturing ,activity ,entry
185
+ global busyCapturing ,activity ,leds
177
186
activity += 4
178
187
if (busyCapturing == False ):
179
- if entry ['Content||Settings||mode||@value' ]!= 'idle' :
180
- leds ['Content||Settings||light||@value' ].on ()
181
188
if entry ['Content||Settings||mode||@value' ]== 'alarm' :
182
189
leds ['Content||Settings||alarm||@value' ].on ()
183
- entry ['Content||Status||light||@value' ]= leds ['Content||Settings||light||@value' ].is_active
184
- entry ['Content||Status||alarm||@value' ]= leds ['Content||Settings||alarm||@value' ].is_active
185
190
capture ('motionA' )
186
- if (int (entry ['Content||Settings||light||@value' ])== 1 ):
187
- leds ['Content||Settings||light||@value' ].on ()
188
- else :
189
- leds ['Content||Settings||light||@value' ].off ()
190
191
if (int (entry ['Content||Settings||alarm||@value' ])== 1 ):
191
192
leds ['Content||Settings||alarm||@value' ].on ()
192
193
else :
193
194
leds ['Content||Settings||alarm||@value' ].off ()
194
195
195
196
def motionB ():
196
- global busyCapturing , activity
197
+ global activity
197
198
activity += 1
198
199
199
200
if 'pirA' in motionSensors :
@@ -202,7 +203,7 @@ def motionB():
202
203
motionSensors ['pirB' ].when_motion = motionB
203
204
204
205
def updateActivity ():
205
- global entry , activity
206
+ global activity
206
207
if (activity > 0 ):
207
208
activity -= 1
208
209
t = Timer (6 ,updateActivity )
@@ -211,28 +212,25 @@ def updateActivity():
211
212
212
213
# ==== add media item and/or status data to stack and process the stack ===========
213
214
214
- def mediaItems2stack ():
215
- global dirs ,entry
215
+ def mediaItems2stack (captureEntry ):
216
216
for file in os .listdir (dirs ['media' ]):
217
- readInputs ()
218
- entry ['Tag' ]= 'media'
217
+ captureEntry ['Tag' ]= 'media'
219
218
fileNameComps = file .split ('_' )
220
219
if (len (fileNameComps )== 3 ):
221
- entry ['Content||Status||timestamp||@value' ]= fileNameComps [1 ]
222
- entry ['Params||File||Name' ]= file
223
- entry ['Params||File||Extension' ]= 'jpeg'
224
- entry ['Params||File||MIME-Type' ]= 'image/jpeg'
220
+ captureEntry ['Content||Status||timestamp||@value' ]= fileNameComps [1 ]
221
+ captureEntry ['Params||File||Name' ]= file
222
+ captureEntry ['Params||File||Extension' ]= 'jpeg'
223
+ captureEntry ['Params||File||MIME-Type' ]= 'image/jpeg'
225
224
else :
226
- entry ['Params||File||Name' ]= ''
227
- entry ['Params||File||Extension' ]= ''
228
- entry ['Params||File||MIME-Type' ]= ''
229
- datapoolclient .add2stack (entry ,dirs ['media' ]+ '/' + file )
225
+ captureEntry ['Params||File||Name' ]= ''
226
+ captureEntry ['Params||File||Extension' ]= ''
227
+ captureEntry ['Params||File||MIME-Type' ]= ''
228
+ datapoolclient .add2stack (captureEntry ,dirs ['media' ]+ '/' + file )
230
229
231
230
def statusPolling ():
232
- global entry
233
- readInputs ()
234
- entry ['Tag' ]= 'status'
235
- datapoolclient .add2stack (entry )
231
+ captureEntry = readInputs ()
232
+ captureEntry ['Tag' ]= 'status'
233
+ datapoolclient .add2stack (captureEntry )
236
234
t = Timer (4.7 ,statusPolling )
237
235
t .start ()
238
236
statusPolling ()
@@ -258,7 +256,7 @@ def stackProcessingLoop():
258
256
# ==== periodic capturing =========================================================
259
257
ticks = 0
260
258
def periodicCapture ():
261
- global ticks , entry , busyCapturing
259
+ global ticks
262
260
captureTime = int (entry ['Content||Settings||captureTime||@value' ])
263
261
if (captureTime != 0 ):
264
262
if (ticks % captureTime == 0 ):
0 commit comments