編集履歴一覧に戻る
myaonのアイコン画像

myaon が 2021年04月27日16時56分34秒 に編集

コメント無し

本文の変更

# デモ動画 # 使い方 ■手順 1. アプリを起動して待機。

-

1. 来訪者にobnizのスイッチを押してもらい自分にLINE通知。 1. 通知が来たらアプリのブラウザ画面を開き、「今行きます!」「会議中なので出られません」といった返信をobnizに返

+

1. 来訪者にobnizのスイッチを押してもらいGAS経由で自分にLINE通知。 1. 通知が来たらアプリのブラウザ画面を開き、「今行きます!」「会議中なので出られません」といった返信をobnizに返せる

# 部品および接続・設置図 作成に使用したパーツは下記となります。 | 品目 | 価格 | |:---:|:---| | [obniz Board 1Y](https://akizukidenshi.com/catalog/g/gM-14930/) | 6930 | | モバイルバッテリー | - | | Type-C ケーブル | - |

-

![](https://camo.elchika.com/2309c2de838c63548a140b1e22b7341cd9b0cfe7/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f64656631306632662d356164392d343539322d613131332d6332353130373234613762322f39316163373935322d353732632d343532302d383035352d656164396161616164646564/)

+

![キャプションを入力できます](https://camo.elchika.com/b113ebeab5e5573b47ab4e7d0037a11e4a3e8cde/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f64656631306632662d356164392d343539322d613131332d6332353130373234613762322f34356434313061662d376565632d343738622d386432322d316431323561616632656539/)

# ソースコード

+

LINE通知の仕方は迷いましたが、GASで作ることにしました。 Googleドライブから新規>GoogleAppsScriptsを作成し、以下のプログラムを記入、デプロイします。 トークンは[こちら](http://sgnotify-bot.line.me/my/)から作成できます。

```js:only-line-push.json function line_notify(message) { url = "https://notify-api.line.me/api/notify";

-

token = "GsLqmRj6MmZE8wu2WyNBDHexmxA218aK84I5bVgx4tP";

+

token = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";

data = { "message": message }; options = { "method": "post", "contentType": "application/x-www-form-urlencoded", "headers": { "Authorization": "Bearer " + token }, "payload": data }; UrlFetchApp.fetch(url, options); } function doGet() {

-

message = "お届け物です!返信してね!\nhttps://obniz.com/webapp/2710/run?obniz_id=0154-4243";

+

message = "お届け物です!返信してね!\nhttps://obniz.com/webapp/XXXXXXXXXXXXXXXXXX";

line_notify(message); } ```

+

![デプロイ設定](https://camo.elchika.com/25fd0d6fa3a9c2d16c9d2bb22627db08e718fac5/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f64656631306632662d356164392d343539322d613131332d6332353130373234613762322f66323464663330342d333537302d346134302d616561662d383136343032353731356365/)

+

デプロイが完了すると実行urlがコピーできるようになるので、それを以下のサンプルベースのプログラム内のWebRequestのところにペーストすればOKです。 ![元のサンプル](https://camo.elchika.com/ee0e538ada4df0f6ed0e7c0f25f8c4af79967d45/687474703a2f2f73746f726167652e676f6f676c65617069732e636f6d2f656c6368696b612f76312f757365722f64656631306632662d356164392d343539322d613131332d6332353130373234613762322f62636362633935362d353465312d346264652d623732382d366431363864636666376361/)

```html:obline.html <html> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" /> <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script> <script src="https://unpkg.com/obniz@3.x/obniz.js" crossorigin="anonymous" ></script> </head> <body> <div id="obniz-debug"></div> <div class="container"> <div class="text-center"> <h3>Print Text on obniz</h3> <input type="text" id="text" value="今行きます!" /> <button class="btn btn-primary" id="showtime">Print on obniz</button> </div> </div> <script> //put your obniz ID var obniz = new Obniz("OBNIZ_ID_HERE"); //during obniz connection obniz.onconnect = async function() { //init switch state on obniz $("#print").text(await obniz.switch.getWait()); obniz.display.clear(); obniz.display.print("チャイムを鳴らす"); obniz.display.print("前にこっちを"); obniz.display.print("押してください!"); //if the "Print on obniz" clicked $("#showtime").on("click", function() { //show input text on obniz display obniz.display.clear(); obniz.display.print($("#text").val()); }); //if the switch state changes obniz.switch.onchange = function(state) { //ボタンを押したとき if(state == "push"){ //show the state on obniz display obniz.display.clear(); obniz.display.print("返信を"); obniz.display.print("お待ちください"); //このアプリのURLをGAS経由でLineに送る

-

fetch('https://script.google.com/macros/s/AKfycbzhl0OoEOLV34T9PJqoy0XQ81bJvsIAvLbFXclOSEQabAEt5j5FeAh0KCMdXxBCSjmUcw/exec', {method:"GET", mode: "cors", cache:"no-cache"}).catch(e=>{ /* nothing */ });

+

fetch('XXXXXXXXXXXXXXXXXXXXXX', {method:"GET", mode: "cors", cache:"no-cache"}).catch(e=>{ /* nothing */ });

} //表示のリセット if(state == "right"){ obniz.display.clear(); obniz.display.print("チャイムを鳴らす"); obniz.display.print("前にこっちを"); obniz.display.print("押してください!"); } }; }; </script> </body> </html> ```

+

# 参考文献 https://stabucky.com/wp/archives/12654