5
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

IoTとブロックチェーン

Posted at

概要

Raspberry PI Zero Wを使ってBluetooth対応体温計のデータを取得してブロックチェーンにデータを保存します。

ブロックチェーンに体温データを刻むことで対改竄性が担保されます。また、アカウントを参照することで誰でもデータを閲覧することもできます(もちろん個人情報的にはアレなので暗号化等と組み合わせる必要はあると思います)

作るもの

以下のような構成で実装します。

Untitled (3).png

記録先アドレス

サンプル動画

MP4動画はQiitaに上げられなかったのでGIF動画にしました。(わかりにくい、、、)

体温計サンプル1.gif

体温計サンプル2.gif

体温計サンプル3.gif

開発環境

Raspberry Pi Zero W

Raspberry Pi Zero W - ヘッダー ハンダ付け済み - ラズベリー・パイ ゼロ W ワイヤレス

A&D Bluetooth内蔵 体温計 UT-201BLE

今回はA&D Bluetooth内蔵 体温計 UT-201BLEを使いました。

環境

$ cat /etc/os-release 
PRETTY_NAME="Raspbian GNU/Linux 11 (bullseye)"
NAME="Raspbian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"

SSH接続

初期設定にてWi-Fiに接続出来る状態であればSSHコマンドにてラズパイZeroWにSSH接続可能。

ssh pi@raspberry.local
raspberry.local's password:
Linux opening 5.15.84+ #1613 Thu Jan 5 11:58:09 GMT 2023 armv6l

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

キーボード入力の修正

(リブートが必要かも)

echo "set nocompatible" >> /etc/skel/.vimrc
echo "set backspace=indent,eol,start" >> /etc/skel/.vimrc
sudo echo "set nocompatible" >> /root/.vimrc
sudo echo "set backspace=indent,eol,start" >> /root/.vimrc
echo "set nocompatible" >> /home/pi/.vimrc
echo "set backspace=indent,eol,start" >> /home/pi/.vimrc

1.ペアリングデバイスの検索

piユーザー(初期)をbluetoothグループに追加

$ sudo usermod -a -G bluetooth pi
$ sudo reboot

2.繋ぎたいデバイスのBluetoothアドレスを特定

リブート後、bluetoothctlコマンドを実行

$ bluetoothctl
[bluetooth]# scan on

※scan onは自分で入力

以下のようにデバイスが列挙される。

[bluetooth]# scan on
Discovery started
[CHG] Controller B8:27:EB:13:4A:0D Discovering: yes
[NEW] Device 6C:17:F8:88:CE:C5 6C-17-F8-88-CE-C5

Untitled (4).png

沢山出て来たら、目当ての品を探す。

xx:xx:xx:xx:xx:xxという書かれ方をしている文字列が、各Bluetooth機器のMACアドレス

3.ペアリングする

Untitled (5).png

pair MACアドレスで接続する

pair 64:33:DB:D8:AF:D2

Enterを押下して、Pairing successfulと表示されたらあとはconnect MACアドレスと打てば成功。

Untitled (6).png

Untitled (7).png

最後にtrust MACアドレスにて信頼できるデバイスとして追加しておけば次回以降この手間が省けるので便利。

あとはPythonを使ってごにょごにょすれば完成!(実はソースコード保管してなかったので紛失してる。。。余裕があればまた作成します)

この実験は2023/01頃に実施したものになります。
検証時期から時間が経っているのでうまく動作しない可能性があります。

以上です。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?