LoginSignup
4
5

More than 5 years have passed since last update.

Raspberry Pi ツール part 1 (遠隔操作)

Last updated at Posted at 2015-08-04

Telegramでの遠隔操作

どんな環境

  • 今回の環境構築は Raspberry pi B 以上をおすすめ
  • 使用しているOSはRaspbian 3.18
  • 使用レポジトリー https://github.com/vysheng/tg

背景

380011_10151105753244475_58885166_n.jpg
家に犬がいるとします。
自分がいない時に何をしているか気になりますよね?
そんな時は Raspberry pi で確認しましょう!

インストール

Telegram

librariesをインストール

sudo apt-get install libreadline-dev libconfig-dev libssl-dev lua5.2 liblua5.2-dev libevent-dev make

vyshengさんのTelegramのコンソール用クライアントを使用

git clone --recursive https://github.com/vysheng/tg.git && cd tg 

configureファイルを使用

./configure && make

使い方


Telegramを携帯にインストール
https://telegram.org/
サインアップする際に電話番号とエリアコードを登録
+81 *** **** ****
SMSにメッセージが届くので登録を確認


Telegramクライアントを起動

bin/telegram-cli -k tg-server.pub -W

コンソールでアカウント作成時に登録した番号を入力(エリアコードを含む)
+81***********

メッセージ送信でのテスト

メッセージ送信はコンソールに...

msg 名前_名字 hogehoge

luaを使用してのTelegrambot

Telegramのアクションスクリプトを作成

sudo nano /home/pi/tg/action.lua

単純な Ping - Pong テスト用のサンプルコード

function on_msg_receive (msg)
    if msg.out then
        return
    end
    if (msg.text=='ping') then
       send_msg (msg.from.print_name, 'pong', ok_cb, false)
    end
end

function on_our_id (id)
end

function on_secret_chat_created (peer)
end

function on_user_update (user)
end

function on_chat_update (user)
end

function on_get_difference_end ()
end

function on_binlog_replay_end ()
end

先ほど作った action.luaを使用して再度telegramを起動

bin/telegram-cli -k tg-server.pub -W -s action.lua

最後にカメラをtelegramにつなげましょう

写真の保存のためにdirectoryを作成

sudo mkdir /home/pi/camera

カメラ起動のためのアーカイブ・shellファイルを用意

sudo nano /home/pi/camera/camera.sh

ファイルの内容は以下のようにしてください

#!/bin/bash  

raspistill -w 800 -h 600 -o /home/pi/camera/photo.jpg 

ファイルにパーミッションをわたします

sudo chmod -R 0655 /home/pi/camera/camera.sh

もう一度作成したaction.luaを開き以下のコードでcamera.shを実行

if (msg.text=='photo') then
   os.execute('/home/pi/camera/camera.sh')
   send_photo (msg.from.print_name, '/home/pi/camera/photo.jpg', ok_cb, false)
end

結果、telegramに 'photo'と書く事でカメラが起動!

細かい内容

4
5
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
4
5