RaspberryPiとAIを使用したTPH予測。

Raspberry PiとAIを使用したTPH予測のドキュメントへようこそ!

このプロジェクトについて

このプロジェクトは、気温、気圧、湿度(TPH)の予測を目的としています。そしてエアコンを制御します。RaspberryPiとRIpTPHモニターを使ったAIによるホームオートメーション。

This is integrated your home automation, controling air-conditioner with AI and another infrared controlled devices such as television set or celling light and so on.

Documentation Status

Raspberry PiとAIを使用したTPH予測。

最初のRaspberryPiの起動と、開発用のPython環境をセットアップする方法について説明します。

このプロジェクトは現在開発中ですが、まだ完了していません。

準備

次のリストのものをを入手してください。

  • Raspberry Pi 3B, 3B+

  • RPi TPH Monitor Rev2

  • micro SD card, 16GB above(recommended)

  • USB connected key board

  • USB connected mouse

  • Raspbian

  • HDMI cable and display

    • use TV instead of display

  • Python development environment

    • We supported only Python 3.7 upper version.

Raspberry Piをセットアップする

Raspberry Piをセットアップする必要があります。

MacまたはPC(Linux、MS-Windows)では、RaspbianをmicroSDカードにインストールできます。

最新のRaspbianをダウンロード

Raspberry Pi Downloads からダウンロードできる公式のRaspbianを使用することをお勧めします

「デスクトップと推奨ソフトウェアを備えたRaspbian Buster」または「デスクトップを備えたRaspbian Buster」を選択します。

オペレーティングシステムイメージのインストール

オペレーティングシステムイメージをインストールするには、`インストールガイド<https://www.raspberrypi.org/documentation/installation/installing-images/README.md>`_を読む必要があります。

そして `balenaEtcher <https://www.balena.io/etcher/>`_をダウンロード

macOS

Apple Macを使用している場合は、 brew を介してインストールできます。

$ brew cask install balenaetcher
初回起動

初回起動時のみ、HDMI経由でUSBキーボード、USBマウス、モニターを接続する必要があります。 Wi-Fiネットワークを設定し、 raspbian-config を介してSSHを有効にする必要があります。192.168.0.121/24 などの固定IPアドレスを設定してください。

リモート接続をテスト

MacまたはPCで、ssh を介したリモート接続テスト。

$ ssh pi@192.168.0.121
パッケージのアップグレード

Raspbianをアップグレードすることをお勧めします。

$ sudo apt update
...
$ sudo apt upgrade

開発環境の準備

Raspberry Piで開発できます。

MacまたはPCで開発環境を準備することをお勧めします。

pyenv と pyenv-virtualenv

インストールしてください

macOS, Linux

PyEnv を利用した Python のインストール

$ pyenv install 3.8.0

次に pyenv-virtualenv の設定

$ pyenv virtualenv 3.8.0 djrpi380

cf. my home directory.

$ pyenv versions
* system (set by /Users/mitsu/.pyenv/version)
 3.7.4
 3.7.4/envs/djsample374
 3.8.0
 3.8.0/envs/djrpi380
 djrpi380
 djsample374
$ python --version
Python 2.7.16

開発環境

$ cd ~/git/hub/django-rpi-tph-monitor
$ pyenv local djrpi380
$ pyenv versions
 system
 3.7.4
 3.7.4/envs/djsample374
 3.8.0
 3.8.0/envs/djrpi380
* djrpi380 (set by /Users/mitsu/git/hub/django-rpi-tph-monitor/.python-version)
 djsample374
$ python --version
Python 3.8.0
MS-Windows

MS-Windows を利用しているなら, pyenv の代わりに venv です。

Hydrogen

Hydrogen は、Python、R、JavaScript やその他の Jupyter カーネルをサポートする対話型コーディング環境です。

$ python -m ipykernel install --user --name=dj3rpi380 --display-name=dj3rpi380

複数のpyenvバージョンがある場合は、このコマンドを繰り返すべきです。

ipkernel のリスト。

$ jupyter kernelspec list

「ホームオートメーションアプリケーション」の開発を始めましょう。

ドキュメンテーション

Read the Docs <https://readthedocs.org>`_ にドキュメントを公開しました。

Raspberry PiとAIを使用したTPH予測の ドキュメンテーション

開発

これは、Raspberry PIとAIを使用してホームオートメーションを開発するためのセットアップ手順です。

このプロジェクトはまだ完了していません。

入門

必要なもの

Pythonモジュール
  • Django

  • djangorestframework

  • django-filter

  • django-background-tasks

  • dash

  • plotly

  • 等々。

$ cd tph

`pip`を使ってPythonパッケージをインストールできます。

$ pip install -r requirements.txt

On your development Mac, Ubuntu, or MS-Windows.

$ pip install -r requirements_dev.txt
ターゲットのラズベリーパイで。

私のラズベリーパイ3Bについて。

$ cat /etc/debian_version
10.9
$ uname -a
Linux raspi3b 5.10.17-v7+ #1414 SMP Fri Apr 30 13:18:35 BST 2021 armv7l GNU/Linux
$ lsb_release -a
No LSB modules are available.
Distributor ID: Raspbian
Description:    Raspbian GNU/Linux 10 (buster)
Release:    10
Codename:   buster
$ cat /proc/device-tree/model
Raspberry Pi 3 Model B Rev 1.2
raspi-configを使ってi2cを有効にします。
$ sudo raspi-config
Add i2c group your user account.
$ sudo usermod -aG i2c pi
MariaDBをインストールします。
$ sudo apt install mariadb-server
$ sudo mysql_secure_installation
Change the root password? [Y/n] y
Remove anonymous users? [Y/n] y
Disallow root login remotely? [Y/n] y
Remove test database and access to it? [Y/n] y
Reload privilege tables now? [Y/n]
Cleaning up...
Pythonの 'mysqlclient' モジュールをインストールします。
$ sudo apt install python3-dev default-libmysqlclient-dev build-essential
$ pip install mysqlclient
タイムゾーンをMariaDBに設定します。
$ /usr/bin/mysql_tzinfo_to_sql /usr/share/zoneinfo > timezone.sql
$ mysql -u root -p -Dmysql < ./timezone.sql
MariaDBを再起動します。
$ sudo /etc/init.d/mysql restart
Pythonモジュールをインストールします。

別のPythonモジュールをインストールする必要があります。

$ pip install -r requirements_rpi.txt

And edit your tph/tph/settings.py

274ON_RASPBERRY_PI = True
275USE_SMBUS2 = True
Hydrogenのセットアップ
$ pip install jupyter
$ python -m ipykernel install --user --name=<name> --display-name=<name>
$ jupyter kernelspec list

make

$ Python manage.py startapp monitor
$ Python manage.py makemigrations monitor
データベースを設定します
$ Python manage.py migrate
Operations to perform:
 Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
 Applying contenttypes.0001_initial... OK
 Applying auth.0001_initial... OK
 Applying admin.0001_initial... OK
 Applying admin.0002_logentry_remove_auto_add... OK
 Applying admin.0003_logentry_add_action_flag_choices... OK
 Applying contenttypes.0002_remove_content_type_name... OK
 Applying auth.0002_alter_permission_name_max_length... OK
 Applying auth.0003_alter_user_email_max_length... OK
 Applying auth.0004_alter_user_username_opts... OK
 Applying auth.0005_alter_user_last_login_null... OK
 Applying auth.0006_require_contenttypes_0002... OK
 Applying auth.0007_alter_validators_add_error_messages... OK
 Applying auth.0008_alter_user_username_max_length... OK
 Applying auth.0009_alter_user_last_name_max_length... OK
 Applying auth.0010_alter_group_name_max_length... OK
 Applying auth.0011_update_proxy_permissions... OK
 Applying sessions.0001_initial... OK
SCSS/SASS の利用
Sass を使用して Djangoプロジェクトをセットアップする
ownload Bootstrap Source file here.
そして、SCSSファイルを `` static / bootstrap``にコピーします。
$ cp -r your/bootstrap-4.x.x/scss/* tph/static/bootstrap

いくつかのPythonモジュールをインストールします。

pip install django_compressor
pip install django-libsass
Background tasks
I selected Django Background Tasks for save datas interval.
For Django 3.2, pip install django-background-tasks.
pip install django-background-tasks

background tasks の登録と実行

最初の一歩

Djangoプロジェクトを作成します。

mkdir django-rpi-tph-monitor
cd django-rpi-tph-monitor
django-admin startproject tph
cd tph
python manage.py runserver

Access http://localhost:8000/ on your browser. Django First Boot

リモートコンピューターからRaspberry Piにアクセスするには、Raspberry Piで次の手順を実行します。

python manage.py runserver 192.168.xxx.xxx:8000

別のシェル(ターミナル)を入手する必要があります。 2番目の登録タスク。

$ curl -X GET http://localhost:8000/monitor/tasks/5/30

3番目の実行プロセスタスク。

$ ./manage.py process_tasks

デフォルトがdb.sqlite3であるデータベースからタスクをチェックできます。background_task、background_task_completed_tasks、またはmonitor_bme280テーブルを参照してください。

ドキュメンテーション

This project's documents are making with SPHINX. How to use, please see Installing Sphinx.

注釈

PyEnvを使用している場合は、pip を使ってインストールする必要があります。

$ pyenv virtualenv 3.9.4 dj32rpi394docs
$ cd ${your django-rpi-monitor}/docs
$ pyenv local dj32rpi394docs
$ pip install --upgrade pip
$ pip install -r requirements.txt
追加パッケージ
Sphinx-copybutton

Sphinx-copybutton

$ pip install --upgrade sphinx-copybutton
Read the Docs Theme
$ pip install --upgrade sphinx-rtd-theme
ドキュメントを作る。

ドキュメントを作成できます。

cd docs
make html

索引と表索引