この記事は Node-RED Advent Calendar 2018 20日目の記事です。
はじめに
Node-REDを使って動くものってたくさんありますね。
単体ケースで持ち歩き、外で動作させたとき
このラズパイのIPがわからない!
ということがありませんか?(僕だけ?)
TJBotを外で紹介しよう!といろいろやってみたら、このほうが便利なのでは?
ということがいくつか出てきたので、紹介しようと思います。
TJBotに限らずRaspberry piをテザリング環境などお外で使うときに
参考になればと思います。
TJBotというダンボールロボット製作キット
いきなりTJBotのことを紹介しましたが、ご存じない方も多いと思うので・・・。
IBMが公開するダンボールによるロボット製作キットで、Raspberry PI + Node-REDで動きます。
2018/12解禁となったTJBot zeroは海外で公開されているフルサイズダンボールキットをさらに小さく・スマートに作れるようになりました。
Hello., World#TJBot #TJBotzero #BMXUG #IBMChampion pic.twitter.com/a5k0Z2PDkh
— Shoichiro Sakaigawa (@l_s_s_l) 2018年11月28日
[日本版 TJBot - プログラム可能なロボット (TJBot zero)]
(https://www.ibm.com/developerworks/jp/code/open/projects/tjbot/)
自作AIロボットTJBot Zeroで遊んでみる
IoT縛りの勉強会/SIer主催 SIerIoTLT vol8@サイボウズ
— Shoichiro Sakaigawa (@l_s_s_l) 2018年5月22日
でTJBotのことを話ました。#BMXUG #noderedjp のみなさんに感謝です!#iotlt
Today, I speak about "TJBot" raspberry pi and Node-RED robot in JPN SIerIoTLT Vol8https://t.co/I91dBQGdmk
TJBotもっと作り込みしたい課題いっぱいだけど、
— Shoichiro Sakaigawa (@l_s_s_l) 2018年5月22日
ダンボールの愛嬌と、手を振る動作で
大変人気でした!
さらに進化させたいです!
今日の紹介動画はこちらhttps://t.co/EHjMfrINQs
#iotlt #tjbot #IBMChampion #BMXUG #noderedjp
イベントに持ち込んで思うこと
- 携帯や家、職場などIPが変わる環境に持ち込んでもすぐdash-boardにつなぎたい!
- シャットダウンするためだけにSSHするのがちょっと不便
やってみた
第1弾: HW的にIPを表示させる
最初は2行のLCDディスプレイにIPアドレスを表示させることからはじめました
どちらかというとLCDへ文字列を入れる方が手間でした。
IPアドレスの取得自体はnode-red-contrib-hostipを使ったのでノードへ入れるだけ。
WiFiでも、LAN経由でもIPアドレスを配列で格納してくれるので、これをLCDへ出力します。
[{"id":"9637b1de.96eef","type":"i2clcd","z":"8dbb53ad.e1e3e","name":"1602 LCD","addr":"0x3f","x":739,"y":637,"wires":[["e7b70e64.2b84f"]]},{"id":"43e8d56a.1d1b9c","type":"inject","z":"8dbb53ad.e1e3e","name":"","topic":"init","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"x":179,"y":517,"wires":[["27837274.2ead6e"]]},{"id":"4c4fa36d.ccad7c","type":"hostip","z":"8dbb53ad.e1e3e","name":"Host IP","x":159,"y":637,"wires":[["3bbaf8b0.6cadd8"]]},{"id":"d26318d4.310478","type":"change","z":"8dbb53ad.e1e3e","name":"insertIPv4Address","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.0.address","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":549,"y":637,"wires":[["9637b1de.96eef"]]},{"id":"3bbaf8b0.6cadd8","type":"template","z":"8dbb53ad.e1e3e","name":"MyIP-topic","field":"topic","fieldType":"msg","format":"text","syntax":"plain","template":"line1","output":"str","x":349,"y":637,"wires":[["d26318d4.310478"]]},{"id":"e7b70e64.2b84f","type":"delay","z":"8dbb53ad.e1e3e","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":899,"y":637,"wires":[["ff9a0654.d6a1d8"]]},{"id":"27837274.2ead6e","type":"template","z":"8dbb53ad.e1e3e","name":"LCD-Clear","field":"topic","fieldType":"msg","format":"handlebars","syntax":"plain","template":"init","output":"str","x":169,"y":577,"wires":[["651f94fa.30160c"]]},{"id":"1eaeea15.b74766","type":"template","z":"8dbb53ad.e1e3e","name":"Hello-topic","field":"topic","fieldType":"msg","format":"handlebars","syntax":"plain","template":"line1","output":"str","x":169,"y":757,"wires":[["555a9471.436e4c"]]},{"id":"555a9471.436e4c","type":"template","z":"8dbb53ad.e1e3e","name":"Hello-body","field":"payload","fieldType":"msg","format":"text","syntax":"plain","template":"Hello! TJBot","output":"str","x":349,"y":757,"wires":[["9131db36.af7a98"]]},{"id":"ab8b013c.657c3","type":"template","z":"8dbb53ad.e1e3e","name":"Hello-body2","field":"payload","fieldType":"msg","format":"text","syntax":"plain","template":"from BMXUG","output":"str","x":349,"y":817,"wires":[["2beceaea.26aea6"]]},{"id":"2f33592a.270656","type":"template","z":"8dbb53ad.e1e3e","name":"Hello-topic2","field":"topic","fieldType":"msg","format":"handlebars","syntax":"plain","template":"line2","output":"str","x":169,"y":817,"wires":[["ab8b013c.657c3"]]},{"id":"9131db36.af7a98","type":"i2clcd","z":"8dbb53ad.e1e3e","name":"1602 LCD","addr":"0x3f","x":519,"y":757,"wires":[["ca99b866.5931a8"]]},{"id":"2beceaea.26aea6","type":"i2clcd","z":"8dbb53ad.e1e3e","name":"1602 LCD","addr":"0x3f","x":519,"y":817,"wires":[["48205721.a0f428"]]},{"id":"ca99b866.5931a8","type":"delay","z":"8dbb53ad.e1e3e","name":"","pauseType":"delay","timeout":"2","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":679,"y":757,"wires":[["2f33592a.270656"]]},{"id":"651f94fa.30160c","type":"i2clcd","z":"8dbb53ad.e1e3e","name":"1602 LCD","addr":"0x3f","x":339,"y":577,"wires":[["520f6062.91903"]]},{"id":"48205721.a0f428","type":"delay","z":"8dbb53ad.e1e3e","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":679,"y":817,"wires":[["27837274.2ead6e"]]},{"id":"520f6062.91903","type":"delay","z":"8dbb53ad.e1e3e","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":499,"y":577,"wires":[["4c4fa36d.ccad7c"]]},{"id":"ff9a0654.d6a1d8","type":"template","z":"8dbb53ad.e1e3e","name":"LCD-Clear","field":"topic","fieldType":"msg","format":"handlebars","syntax":"plain","template":"init","output":"str","x":169,"y":697,"wires":[["154ac4c3.3d4e9b"]]},{"id":"154ac4c3.3d4e9b","type":"i2clcd","z":"8dbb53ad.e1e3e","name":"1602 LCD","addr":"0x3f","x":339,"y":697,"wires":[["57b82a2f.f109e4"]]},{"id":"57b82a2f.f109e4","type":"delay","z":"8dbb53ad.e1e3e","name":"","pauseType":"delay","timeout":"2","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":519,"y":697,"wires":[["1eaeea15.b74766"]]},{"id":"1317081b.5ae5c8","type":"comment","z":"8dbb53ad.e1e3e","name":"LCDぱねる ぐるぐる","info":"","x":139,"y":457,"wires":[]}]
第2弾: シャットダウン・再起動をノードから実行させる
止めるためだけにSSHするのはちょっと面倒だな(どうせデモでNode-REDのダッシュボード開いているし)」
ということで、停止ボタンを作りました
なんてことはないです。ただのexecノードで
sudo reboot
sudo poweroff
を実行するinjectを用意するだけです。
[{"id":"c6837e27.f35bf","type":"comment","z":"8dbb53ad.e1e3e","name":"とめる","info":"","x":70,"y":720,"wires":[]},{"id":"24608ec9.643b42","type":"inject","z":"8dbb53ad.e1e3e","name":"shutdown!","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":140,"y":760,"wires":[["7b44cde8.a71d24"]]},{"id":"7b44cde8.a71d24","type":"exec","z":"8dbb53ad.e1e3e","command":"sudo poweroff #","addpay":false,"append":"","useSpawn":"","timer":"","oldrc":false,"name":"turn off Pi","x":314,"y":759,"wires":[[],[],[]]},{"id":"99ab5cb8.eb6cf","type":"exec","z":"8dbb53ad.e1e3e","command":"sudo reboot #","addpay":false,"append":"","useSpawn":"","timer":"","oldrc":false,"name":"reboot Pi","x":314,"y":859,"wires":[[],[],[]]},{"id":"11132c53.f8ed24","type":"inject","z":"8dbb53ad.e1e3e","name":"reboot!","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":130,"y":860,"wires":[["99ab5cb8.eb6cf"]]},{"id":"576e0835.f0c5e8","type":"comment","z":"8dbb53ad.e1e3e","name":"さいきどう","info":"","x":80,"y":820,"wires":[]}]
ふりかえり
IPアドレスの認知方法をもっと面白くする
- LCD無くてもできるようにできる
- 音声でしゃべる
- スマホとかなにかに通知する(MQTTでなにかする/slack/メール)
というのもいろいろ考えられそうですね
まだまだ不便に思うこと、こんなことしたらいいかな、
という小ネタをまとめて行きたいと思います。