LoginSignup
4
5

More than 5 years have passed since last update.

MESHハブからwebhook経由でshellを叩いてラズパイ版のソフトウェアタグを実現する

Last updated at Posted at 2018-03-18

はじめに

スマホのMESHアプリには、カメラタグ等のスマホの機能が使えるソフトウェアタグがありますが、Raspberry Pi版では、ソフトウェアタグはないので、Raspberry Pi版ソフトウェアタグを、MESHハブでも実現させる。

準備

MESHハブのセットアップ済みRaspberry Pi 3
iPhone or iPad

bottleのインストールと実行

node.jsでもよいのですが、手っ取り早く、bottleを使いました。

$ pip3 install bottle

今回は、http://localhost:8080/cameraを叩いたら、camera.shが起動するようにしてみました。

server.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from bottle import route, run, template
import requests
import subprocess


@route('/camera')
def camera():
    cmd = u'/home/pi/camera.sh'
    subprocess.call(cmd.split())
    return template('/camera requested')


run(host='localhost', port=8080)

サーバーを起動して、MESHレシピからのリクエストを待ちます。

$ python3 server.py

MESHカスタムタグの作成

次に、呼び出す、MESHの準備です。
カスタムタグを作成します。

var localhost = 'http://localhost:8080' + properties.path;
ajax({
  url: localhost,
  type: 'get',
  timeout: 5000,
  success: function(contents) {
    log(contents);

    callbackSuccess({
      resultType: 'continue',
    });
  },
  error: function(request, errorMessage) {
    log('ERROR: ' + errorMessage);
    callbackSuccess({
      resultType: 'continue',
    });
  }
});
return {
  resultType: 'pause'
};

MESHレシピの作成

parameterに、パスを指定するようにしてます。

2018-03-18 14.47.26.png

まとめ

MESHレシピからRaspberry Piのシェルを叩けるので、いろいろなことが可能となります。
MESHアプリをスマホで動かすよりもとにかく安定してますし、MESHタグのバッテリーが少なくなったら通知も来るし、ラズパイ版を使いだしたら、やめられませんね。
ぜひ、お試しください。

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