LoginSignup
38
41

More than 5 years have passed since last update.

ラズベリーパイで監視カメラ

Last updated at Posted at 2016-01-25

Raspberry Pi

はじめに

最近世間でラズベリーパイというものが騒がれているので
それで監視カメラを作ることにした

準備

ラズベリーパイ-----1
どこかのカメラ-----1
マウス、キーボード----1
マイクロUSBなど
以上
詳しいOSのセットアップはここをみています
http://deviceplus.jp/hobby/raspberrypi_entry_016/
円山ナカノさんの記事ですが
とても分かりやすくOSのセットアップ方法がかかれています
でもosを入れるときNOOBSではなくRaspbianにはいってRaspbian Jessie
をえらんでください

機能概要

今回はslackを使ってします
当初はメールでする予定だったのですが
できないという見解になってしまいました(笑)
話が脱線しましたがslackに撮った画像を送ることにしたいです

使うソフト

motion---画像を撮るソフトです
slacker---ラズベリー版slackのようです
以上

motionのインストールand設定

まずmotionをインストールします

sudo apt-get install -y motion

インストールが終わったら次にslacker
をインストールします(もし失敗したらコマンドに是を打ってからインストールしてください)

1.sudo apt-get update 
2.sudo apt-get upgrade

次に設定

sudo nano /etc/motion/motion.conf 

でとりあえず

daemon off
target_dir /tmp/motion

そして
ctrl+xをしてyとうってからのenterで保存できます
そして次に

slackerのインストール

まずwindwosマシンでアカウント登録をします
https://slack.com/,%22%5BSlack%E3%81%AE%E3%82%A2%E3%82%AB%E3%82%A6%E3%83%B3%E3%83%88%E7%99%BB%E9%8C%B2%5D%22
どうにかがんばってください(分からない場合はきいてください
下に掲示板があります)

tokenを取る

このページを見てください
http://blog.bgbgbg.net/archives/3413

インストール

これらが終わったら
slackerをインストールします

sudo pip install slacker

もしなんか聞いてきたらyで

本番はここから

スクリプトを書きます

sudo nano /home/pi/slackbot.py

そしてその中に


# -*- coding: utf-8 -*- 


import sys 




from slacker import Slacker 





class Slack(object): 






    __slacker = None 






    def __init__(self, token): 


        self.__slacker = Slacker(token) 





    def get_channnel_list(self): 


        """ 


        Slackチーム内のチャンネルID、チャンネル名一覧を取得する。 


        """ 


        # bodyで取得することで、[{チャンネル1},{チャンネル2},...,]の形式で取得できる。 


        raw_data = self.__slacker.channels.list().body 






        channnels = [] 


        for data in raw_data["channels"]: 


            channnels.append(dict(channel_id=data["id"], channel_name=data["name"])) 


        return channnels 






    def post_to_file(self, file_path, channel): 


        result = self.__slacker.files.upload(file_path, channels=[channel]) 


        self.__slacker.pins.add(channel=channel, file_=result.body['file']['id']) 






if __name__ == "__main__": 






    param = sys.argv 


    file_path = param[1] 






    slack = Slack("xxxx-xxxxxxxxxxxx-xxxxxxxxxxxx-xxxxxxxxxxxx-xxxxxxxxxxxx") 


    channnels = slack.get_channnel_list() 


    slack.post_to_file(file_path, channnels[0]["channel_id"]) 

xxxx-xxxxxxxxxxxx-xxxxxxxxxxxx-xxxxxxxxxxxx-xxxxxxxxxxxxの所はそれを消して自分のtokenを入れてください

連携

sudo nano /etc/motion/motion.conf 

その中の

# Command to be executed when a picture (.ppm|.jpg) is saved (default: none)
# To give the filename as an argument to a command append it with %f
; on_picture_save value

; on_picture_save valueの下に

on_picture_save python /home/pi/slackbot.py

と打ってください

全部打ったらこんなかんじ

# Command to be executed when a picture (.ppm|.jpg) is saved (default: none)
# To give the filename as an argument to a command append it with %f
#; on_picture_save value
on_picture_save python /home/pi/slackbot/slack_bot.py %f

そして

ctrl+xをしてyとうってからのenterで保存できます

sudo motion

と打てば完了です
動体検知させてから
slackにsingしてみてください
画像がきているはずです

参考

などです

38
41
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
38
41