10
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

3Dプリンターの状況をRaspberry PiとSlackで確認したい

Posted at

余っているRaspberry PiとWebカメラで実装してみました!

初期セットアップ

以下は適当にセットしてある前提

  • Raspberry Piが部屋のWi-Fiにつながる
  • Slackを使っていてアクセストークンを発行している
  • Webカメラが余っている

Webカメラの画像をmotionで検知する

Raspberry Piと安めのウェブカメラで監視カメラを作る。何か動きがあったら画像保存もする | Divide et impera

↑を参考にmotionをセットアップ。

/tmp/motionに画像が保存されるようになるので、あとはここの画像をSlackにアップするだけです。

Slackへ画像アップロード

upload_3dprinter_photo.sh
# !/bin/bash
# cron --- */5 * * * * pi /home/pi/upload_3dprinter_photo.sh

upload_file=`ls /tmp/motion | sort -r | head -n1`

[ -z $upload_file ] && exit # 画像がなければなにもしない

curl -F file=@/tmp/motion/${upload_file} -F channels=C02UFJEFG -F token=xoxp-d9a78e... https://slack.com/api/files.upload

rm /tmp/motion/* # 必要なら最後に画像を削除

cronの設定もコメントしてあるので参考にしてください。

これで以下みたいな感じに画像が投稿されるようになりました!

3d-photo

超便利!!

10
11
0

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
10
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?