12
6

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.

Node-REDAdvent Calendar 2019

Day 3

Node-REDでラズパイのシャットダウンとリブートを快適にしよう!

Last updated at Posted at 2019-12-02

#概要
 ラズパイを持ち歩いていると、撤収や動きがおかしいときにシャットダウンやリブートをしますよね。私の場合、ラズパイにLCDを組み付けてサイネージ化したデモを持ち歩いています。
 そんな時、困るのがシャットダウン。シャットダウンするにはこんな面倒があると思います。

  • ssh接続いてコマンド打つのは面倒
  • 物理的なボタンは断線やスペースの問題でメンテナンスが面倒

 これらの面倒をNode-REDで解決してみました!

#実現した事
 「Node-REDで作成したWebページにコマンド実行ボタンを用意し、ボタンを押すと対応したコマンドが実行される

 WebページにはNode-REDのDashBoardを使用し、次のようなフローを作成しました。
image.png

 ダッシュボードのWebページを開くと次のようにボタンが2つ並んでおり、ボタンを押すと対応したコマンドが実行されます。
image.png

#実際の様子

#フローのソースコード

[{"id":"8c097990.a47498","type":"tab","label":"フロー 1","disabled":false,"info":""},{"id":"ce69ad84.b4785","type":"ui_button","z":"8c097990.a47498","name":"","group":"ef8cfd1d.26343","order":0,"width":"2","height":"1","passthru":false,"label":"シャットダウン","tooltip":"","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"","x":160,"y":80,"wires":[["e8e257d0.a9e248"]]},{"id":"e8e257d0.a9e248","type":"exec","z":"8c097990.a47498","command":"sudo shutdown -h now","addpay":true,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"","x":420,"y":80,"wires":[[],[],[]]},{"id":"5e5ec1e1.c0b4c","type":"ui_button","z":"8c097990.a47498","name":"","group":"ef8cfd1d.26343","order":0,"width":"2","height":"1","passthru":false,"label":"リブート","tooltip":"","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"","x":140,"y":140,"wires":[["3b29b4c0.041d8c"]]},{"id":"3b29b4c0.041d8c","type":"exec","z":"8c097990.a47498","command":"sudo reboot","addpay":true,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"","x":390,"y":140,"wires":[[],[],[]]},{"id":"ef8cfd1d.26343","type":"ui_group","z":"","name":"コマンド","tab":"b5051da0.fade4","disp":true,"width":"6","collapse":false},{"id":"b5051da0.fade4","type":"ui_tab","z":"","name":"Command","icon":"dashboard","disabled":false,"hidden":false}]

#おわりに
 Webページを開ければ誰でもコマンド実行できていまうので、セキュリティ面に問題があります。趣味レベルのものでデモ展示など頻繁に電源ON/OFFする場面ではかなり便利だと思います。

12
6
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
12
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?