動作環境
Raspberry Pi 2 Model B (以下RPi)
Raspbian Jessie
Python 2.7.9
プロジェクト開始: link
処理概要
「その日の帰宅時刻」にファイルを作りたい。
以下とした。
- 特定の時刻に/tmp/capture_motionファイルを削除
- 例: 12:30
- Motionを使って以下の処理トリガとする
- /tmp/capture_motionが
- なければ: 作る
- あれば: 何もしない
- /tmp/capture_motionが
上記の例では12:30以降にカメラの前を横断した時、「その日の帰宅時刻」のファイルが作成される。
その後のカメラ横断に関しては、ファイルに対して何もしない。
Motionのセットアップ
Raspberry Pi > 動体を検知したら、"Rear Center"という音声を流す
以下のように設定した。
/etc/motion/motion.conf(一部)
on_picture_save python /home/pi/MOTION/welcomeBack_171105.py
/home/pi/MOTION/welcomeBack_171105.py
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import os.path
import time
from datetime import datetime as dt
"""
v0.1 Nov. 05, 2017
- touch file
- read file datetime
"""
filepath = "/tmp/capture_motion"
if os.path.exists(filepath):
mddt = time.ctime(os.path.getmtime(filepath))
print(mddt)
else:
with open(filepath, 'a'):
os.utime(filepath, None)
上記の関連: https://qiita.com/7of9/items/9c537d1beb8e83bb20af
/etc/rc.local(一部)
## for PACEMAKER (05, Nov. 2017)
motion -c /etc/motion/motion.conf
Motionに関してはdaemon起動の設定や、output_pictures off設定など試したが、うまくいかなかったので、/etc/rc.local
での起動と、on_picture_saveイベントでの処理としている。
cronの設定
# PACEMAKER (Nov. 5, 2017)
30 12 * * * root rm /tmp/capture_motion
30 12 * * * root rm /tmp/motion/*.jpg
/etc/init.d/cron start
にてcron設定しておく。
TODO
-
/tmp/capture_motion
の時刻を見て疲れの判断基準とする- 早い帰宅
- 疲れてない
- 遅い帰宅
- 疲れている
- 早い帰宅
備考
当初、cronにてファイル削除でなく再起動の設定をしていた。
再起動の設定をしておくと、将来別のソフトを走らせて処理中に再起動でトラブりそうなので、ファイル削除に変更した。
動作確認
(追記 2017/11/07)
昨夜帰宅後、/tmp/capture_motion
を確認したところ、帰宅時刻のファイルとなっていた。
/tmp/motion/
以下にjpgファイルが大量にできる点は要改善点。