0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

災危通報を受信する

Last updated at Posted at 2024-07-14

前回まででセットアップとGPS関連の情報を受信できたので、今回は災危通報を取得して解析してみます。

受信機

GR-M10-RP

製品情報

製品ドキュメント

データの読み取り

ラズパイでのデータの読み取り
$ sudo screen /dev/ttyS0 38400

災危通報の解析

まずは、ドキュメント通りに進めていきます。

PySerialのインストール

PySerialをインストールします。

ドキュメントの記載通りpipコマンドでインストールしようとしたらエラーが発生しました。

pipでのPySerialのインストール(失敗)
$ pip install pyserial
error: externally-managed-environment

× This environment is externally managed
└> To install Python packages system-wide, try apt install
    python3-xyz, where xyz is the package you are trying to
    install.

    If you wish to install a non-Debian-packaged Python package,
    create a virtual environment using python3 -m venv path/to/venv.
    Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make
    sure you have python3-full installed.

    For more information visit http://rptl.io/venv

note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
hint: See PEP 668 for the detailed specification.

システム全体にPythonパッケージをインストールするには、apt installを使えと言っているようです。
個人で使う場合は仮想環境(venv)を使うようにも言ってますね。
今回は、自分しか使わないのでaptコマンドでインストールしてみます。

aptでのPySerialのインストール
$ sudo apt install python3-serial
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
python3-serial is already the newest version (3.5-1.1).
0 upgraded, 0 newly installed, 0 to remove and 27 not upgraded.

あれ、すでにインストールされていたようです。

サンプルコードの実行

失敗…
$ python read.py /dev/ttyS0 38400
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/serial/serialposix.py", line 322, in open
    self.fd = os.open(self.portstr, os.O_RDWR | os.O_NOCTTY | os.O_NONBLOCK)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
OSError: [Errno 16] Device or resource busy: '/dev/ttyS0'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/nomura/read.py", line 52, in <module>
    with serial.Serial(args.port, args.baudrate) as ser:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/serial/serialutil.py", line 244, in __init__
    self.open()
  File "/usr/lib/python3/dist-packages/serial/serialposix.py", line 325, in open
    raise SerialException(msg.errno, "could not open port {}: {}".format(self._port, msg))
serial.serialutil.SerialException: [Errno 16] could not open port /dev/ttyS0: [Errno 16] Device or resource busy: '/dev/ttyS0'

サンプルでエラーが出てしまいました。
/dev/ttyS0がbusyになっていたので確認してみました。

/dev/ttyS0の確認
$ ps aux | grep ttyS0
root      1566  3.9  0.5   8208  2528 ?        Ss   11:05   1:27 SCREEN /dev/ttyS0 38400
nomura    2538 25.0  0.4   7508  1980 pts/0    S+   11:41   0:00 grep --color=auto ttyS0

最初に受信確認したscreenが/dev/ttyS0を使っているようだったので、強制終了しました。

screenコマンドの強制終了
$ sudo kill -9 1566

再度実行したら動き出しました。

サンプル実行
$ python read.py /dev/ttyS0 38400
initializing...
start!

何も表示されない...。
サンプルコードは、-n オプションでNMEA形式のセンテンスも表示されるようなので、-n オプションをつけて実行してみたところNMEA形式のセンテンスは表示されました。

サンプル実行
$ python read.py -n /dev/ttyS0 38400
initializing...
start!

\$GNVTG、\$GNGGA、\$GPGSV、\$GNRMCなどのセンテンスが取れてきていました。

こんな感じ。
位置情報はぼかしています。
image.png

ということで、データは取れてきそうなので、災危通報が出そうな天気の時にサンプルを試してみます。
今回はサンプルを動かしてみただけなので、この取得データをどうするかは追々考えていかなければって思っています。

災危通報

テスト通報送信まで受信を試せないかなと思っていたのですが、サンプルプログラムを起動してみたところ

災危通報受信
(.venv) $ python read.py /dev/ttyS0 38400
initializing...
start!
$QZQSM,56,9aadf3ca8c8002d400a08214106a823f50c26a1861430ea86220001290cb540*21
$QZQSM,56,53b0240de0000000000000000000000000000000000000000000000292ba9c0*74
$QZQSM,56,c6adf3ca8c80050faaa2008000000000000000000000000000000012f8dc79c*2c
$QZQSM,56,9ab0240de00000000000000000000000000000000000000000000002ee2ee34*7d
$QZQSM,56,53adf3ca8c8002c3e858898b1f4165e12cc1c5a008b4e2169fb0001324cc964*24
$QZQSM,56,c6b0240de000000000000000000000000000000000000000000000031d2a470*71
$QZQSM,56,9aadf3ca8c8002d400a08214106a823f50c26a1861430ea862200013771491c*77
$QZQSM,56,53b0240de00000000000000000000000000000000000000000000003756559c*79
$QZQSM,56,c6adf3ca8c80050faaa2008000000000000000000000000000000013bdb6ff4*7f
$QZQSM,56,9ab0240de00000000000000000000000000000000000000000000003ab4465c*2a
$QZQSM,56,53adf3ca8c8002c3e858898b1f4165e12cc1c5a008b4e2169fb00013e7eaebc*2b
$QZQSM,56,c6b2e40de00000000000000000000000000000000000000000000003d1f0734*22

のように通報を受信したので、一番最初の行($QZQSM,56,9aadf3ca8c8002d400a08214106a823f50c26a1861430ea86220001290cb540*21)をazarashiで解析してみたところ、

解析結果
$ python analize.py 
防災気象情報(海上)(発表)(通常)
海上警報が発表されました。

発表時刻: 7月19日5時25分

警報等情報要素: 海上濃霧警報
長崎西海上

警報等情報要素: 海上風警報
宗谷海峡

警報等情報要素: 海上風警報
北海道西方海上

警報等情報要素: 海上風警報
檜山津軽沖

警報等情報要素: 海上風警報
沿海州南部沖

警報等情報要素: 海上風警報
秋田沖

警報等情報要素: 海上風警報
佐渡沖

警報等情報要素: 海上風警報
能登沖

のような情報が取得できましたので、災危通報も受信できることが確認できました。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?