Skip to content

Commit b350fe2

Browse files
committed
Update sentinel.py
1 parent bff984d commit b350fe2

File tree

1 file changed

+36
-38
lines changed

1 file changed

+36
-38
lines changed

piclient/sentinel.py

+36-38
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
entry={'Group':'Town','Folder':'Address','Name':'Location'}
88
# settings
99
entry['Content||Settings||captureTime||@function']='select'
10-
entry['Content||Settings||captureTime||@value']=3600
10+
entry['Content||Settings||captureTime||@value']='3600'
1111
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'
1617

1718
entry['Content||Settings||mode||@function']='select'
1819
entry['Content||Settings||mode||@value']='alarm'
@@ -112,7 +113,7 @@ def initOutputs():
112113

113114
# process repsponse
114115
def writeOutputs(response):
115-
global leds,strOutputs,entry
116+
global leds,entry
116117
if type(response) is not bool:
117118
for key,value in response.items():
118119
key=key+'||@value'
@@ -128,6 +129,7 @@ def writeOutputs(response):
128129
print(value)
129130
if key in entry:
130131
entry[key]=value
132+
#print(key+': '+entry[key])
131133

132134
# ===================================== Sensors ===================================
133135
def initInputs():
@@ -138,7 +140,7 @@ def initInputs():
138140
initInputs()
139141

140142
def readInputs():
141-
global leds,entry,activity
143+
global entry
142144
entry['Date']=time.strftime('%Y-%m-%d %H:%M:%S',time.localtime())
143145
entry['Content||Status||timestamp||@value']=int(time.time())
144146
entry['Content||Status||activity||@value']=activity
@@ -149,51 +151,50 @@ def readInputs():
149151
entry[entryKey]=int(leds[key].is_active)
150152
if hasGpioZero:
151153
entry['Content||Status||cpuTemperature||@value']=CPUTemperature().temperature
154+
return dict(entry)
152155

153156
# ===================================== Behaviour =================================
154157
activity=0
155158

156159
def captureFileNames(filename):
157-
global dirs
158160
frame=0
159161
while frame<4:
160162
yield dirs['media']+'/'+filename+'_'+str(int(time.time()))+'_'+str(frame)+'.jpg'
161163
frame+=1
162164

163165
busyCapturing=False
164166
def capture(filename):
165-
global busyCapturing,entry
167+
global busyCapturing,leds
166168
busyCapturing=True
169+
if entry['Content||Settings||mode||@value']!='idle':
170+
leds['Content||Settings||light||@value'].on()
171+
captureEntry=readInputs()
167172
if hasPiCamera and entry['Content||Settings||mode||@value']!='idle':
168173
with picamera.PiCamera(framerate=2) as camera:
169174
camera.start_preview()
170175
time.sleep(1)
171176
camera.capture_sequence(captureFileNames(filename),use_video_port=False,resize=None)
172-
mediaItems2stack()
177+
mediaItems2stack(captureEntry)
173178
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()
174183

175184
def motionA():
176-
global busyCapturing,activity,entry
185+
global busyCapturing,activity,leds
177186
activity+=4
178187
if (busyCapturing==False):
179-
if entry['Content||Settings||mode||@value']!='idle':
180-
leds['Content||Settings||light||@value'].on()
181188
if entry['Content||Settings||mode||@value']=='alarm':
182189
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
185190
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()
190191
if (int(entry['Content||Settings||alarm||@value'])==1):
191192
leds['Content||Settings||alarm||@value'].on()
192193
else:
193194
leds['Content||Settings||alarm||@value'].off()
194195

195196
def motionB():
196-
global busyCapturing,activity
197+
global activity
197198
activity+=1
198199

199200
if 'pirA' in motionSensors:
@@ -202,7 +203,7 @@ def motionB():
202203
motionSensors['pirB'].when_motion=motionB
203204

204205
def updateActivity():
205-
global entry,activity
206+
global activity
206207
if (activity>0):
207208
activity-=1
208209
t=Timer(6,updateActivity)
@@ -211,28 +212,25 @@ def updateActivity():
211212

212213
# ==== add media item and/or status data to stack and process the stack ===========
213214

214-
def mediaItems2stack():
215-
global dirs,entry
215+
def mediaItems2stack(captureEntry):
216216
for file in os.listdir(dirs['media']):
217-
readInputs()
218-
entry['Tag']='media'
217+
captureEntry['Tag']='media'
219218
fileNameComps=file.split('_')
220219
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'
225224
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)
230229

231230
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)
236234
t=Timer(4.7,statusPolling)
237235
t.start()
238236
statusPolling()
@@ -258,7 +256,7 @@ def stackProcessingLoop():
258256
# ==== periodic capturing =========================================================
259257
ticks=0
260258
def periodicCapture():
261-
global ticks,entry,busyCapturing
259+
global ticks
262260
captureTime=int(entry['Content||Settings||captureTime||@value'])
263261
if (captureTime!=0):
264262
if (ticks % captureTime==0):

0 commit comments

Comments
 (0)