2
1

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 1 year has passed since last update.

Node-RED MCUのセンサーデバイスで取得したデータをクラウド上のNode-REDで永続化・可視化してみた。

Last updated at Posted at 2023-02-05

はじめに

以前、Node-RED MCUのセンサーデバイスで取得したデータをクラウド上のNode-REDのDashboardで表示するサンプルを作ったが、Dashboardで表示したデータは消失(揮発)してしまうため、今回はデータを永続化し、可視化する機能を追加してみました。

構成

ローカルネットワーク(おうちIoT)のラズパイ、または、クラウド上でNode-REDを動かし、Node-RED MCUから受け取ったデータをinfluxdbへ永続化し、chronografで可視化します。

スクリーンショット 2023-01-24 18.41.48.png

前提条件

  • デバイス
    • M5Atom lite
    • Unit ENVⅢ
  • ラズパイ
    • Raspberry Pi4
  • クラウド
    • OCI(Oracle Cloud Infrastructure)

手順

Node-RED MCU

node-red-mcu.jpg

クラウド

Node-REDをdockerで起動する

Node-REDとMQTT Broker(Aedes MQTT Broker)を動かします。
Node-REDはポート:1880で起動するため、ホスト側でポート:80でアクセスできるようにします。

$ sudo docker run -d -p 80:1880 -p 1883:1883 -v /home/ubuntu/.node-red:/data nodered/node-red:latest

iptablesを変更する

dockerコンテナ環境(Node-RED)からホスト上のinfluxdbへアクセスするため、iptablesで通信を許可します。

$ sudo iptables -I INPUT -i docker0 -j ACCEPT

influxdbをインストールする

$ sudo apt install -y influxdb influxdb-client

正常に起動していることを確認します。

$ sudo systemctl status influxdb

influxdbのテーブルを作成する

influxコマンドでCLIへログインし、sensorという名前でデータベースを作成します。

$ influx
Connected to http://localhost:8086 version 1.6.4
InfluxDB shell version: 1.6.4
> create database sensor

データ格納されているか確認します。
Node-REDからM5Atomという名前でテーブル(measurements)が作成されています。

> use sensor
Using database sensor
> show measurements
name: measurements
name
----
M5Atom
> select * from M5Atom
name: M5Atom
time                humidity           temperature
----                --------           -----------
1674536180151641473 28.639658197909515 26.970702677958343
1674536185137529500 28.95399404898146  26.95735103379873
1674536190139970097 29.187457084000915 26.95735103379873
1674536195146578443 28.91279468986038  26.970702677958343
1674536200137016984 28.78919661249714  26.943999389639117
1674536205137830977 28.91279468986038  26.95735103379873
...

chronografをインストールする

$ wget https://dl.influxdata.com/chronograf/releases/chronograf_1.10.0_amd64.deb
$ sudo dpkg -i chronograf_1.10.0_amd64.deb

正常に起動していることを確認します。

$ systemctl status chronograf.service

外部からグラフを確認する場合、ポート:8888を開放するか、ngrokでトンネル経由でアクセスします。

$ ngrok http 8888

Node-REDフロー

右上のメニューから「パレットの管理」→「ノードの追加」で
node-red-contrib-influxdb
を追加します。

oracle_node-red.jpg

influxdb.jpg

chronografのグラフ表示

スクリーンショット 2023-02-05 23.48.32.png

2
1
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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?