# Pimatic Orange Pi PCへのインストール

**URL:** https://forum.ficusonline.com/t/pimatic-orange-pi-pc/76
**Category:** Automation
**Created:** [2017 年 1 月 31 日午前 8:31 UTC](https://forum.ficusonline.com/t/pimatic-orange-pi-pc/76 "2017-01-31T08:31:22Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![tk-fuse](https://forum.ficusonline.com/user_avatar/forum.ficusonline.com/tk-fuse/32/255_2.png) [@tk-fuse](https://forum.ficusonline.com/u/tk-fuse)
#### Post date: [2017 年 1 月 31 日午前 8:31 UTC](https://forum.ficusonline.com/t/pimatic-orange-pi-pc/76/1 "2017-01-31T08:31:22Z")

</div>

PimaticをOrange Pi PCへインストールする手順についてはRaspberry Piと同じです。  
まずNode.jsをインストールしますがversion7ではなくversion4の最新版をインストールします。

以下ページからNodo.jsのバージョンを選択します。

> **[Node.js — Node.js Releases](https://nodejs.org/en/about/previous-releases)**
>
> Node.js® is a free, open-source, cross-platform JavaScript runtime environment that lets developers create servers, web apps, command line tools and scripts.

バージョン４は以下の通りです。Orangepi PC向けARMに対応したarmv7lをダウンロードします。

> **[Index of /dist/latest-v4.x/](https://nodejs.org/dist/latest-v4.x/)**

バイナリファイルのダウンロード

> wget [https://nodejs.org/dist/latest-v4.x//node-v4.7.2-linux-armv7l.tar.gz](https://nodejs.org/dist/latest-v4.x//node-v4.7.2-linux-armv7l.tar.gz) -P /tmp

usr/localディレクトリに移動しバイナリを展開します。

> cd /usr/local

> sudo tar xzvf /tmp/node-v4.6.2-linux-armv7l.tar.gz --strip=1

インストールが完了したらNode.jsのバージョンを確認します。

> node -v

`v4.7.2`

と表示されればOKです。

その後のプロセスはPimaticインストールページを参照して下さい。

> **[Installation | pimatic - smart home automation for the raspberry pi](https://pimatic.org/guide/getting-started/installation/)**
>
> a home automation server and framework for the raspberry pi running on node.js

---

<div class="post-metadata">

### Author: ![tk-fuse](https://forum.ficusonline.com/user_avatar/forum.ficusonline.com/tk-fuse/32/255_2.png) [@tk-fuse](https://forum.ficusonline.com/u/tk-fuse)
#### Post date: [2017 年 2 月 3 日午前 7:59 UTC](https://forum.ficusonline.com/t/pimatic-orange-pi-pc/76/2 "2017-02-03T07:59:16Z")

</div>

セキュリティの観点から外部からリモートアクセスする場合はSSL接続(https)するようにします。SSLのデフォルトポートである443ポートが既に使用されている場合は別のポート番号を指定します。SSLにポート番号1443を指定する場合、次のような手順で設定します。

> **[Remote Access and SSL | pimatic - smart home automation for the raspberry pi](https://pimatic.org/guide/getting-started/remote-ssl/)**
>
> a home automation server and framework for the raspberry pi running on node.js

通常のルータでは80や443といった一般的なポートしか開放されていません。このため指定ポートである1443をポートマッピング設定やポートフォワード設定で開放します（指定ポート経由でPimaticがインストールされているIPアドレスへ導きます）。

SSL認証に必要なファイルを作成します。SSLによる情報の暗号化が目的なので公式な認証ではなく自己認証によるものとします。

次の一連のコマンドで作成します。パスフレーズの入力が必要です。

> cd pimatic-app

> wget [https://raw.githubusercontent.com/pimatic/pimatic/master/install/ssl-setup](https://raw.githubusercontent.com/pimatic/pimatic/master/install/ssl-setup)

> chmod +x ./ssl-setup

> ./ssl-setup

以下ファイルが作成されます。

```
パブリックキー ca/pimatic-ssl/public/cert.pem
プライベートキー ca/pimatic-ssl/private/privkey.pem
証明書 ca/certs/cacert.crt （クライアントのデバイスにインポートします）

```

config.jsonに以下項目を追加します。

> “httpsServer”: {  
> “enabled”: true,  
> “port”: 1443,  
> “hostname”: “”,  
> “keyFile”: “ca/pimatic-ssl/private/privkey.pem”,  
> “certFile”: “ca/pimatic-ssl/public/cert.pem”,  
> “rootCertFile”: “ca/certs/cacert.crt”  
> },

最後に以下サイトにアクセスし証明書をダウンロードして認証します。

`http://your-ddns/root-ca-cert.crt`

---

<div class="post-metadata">

### Author: ![tk-fuse](https://forum.ficusonline.com/user_avatar/forum.ficusonline.com/tk-fuse/32/255_2.png) [@tk-fuse](https://forum.ficusonline.com/u/tk-fuse)
#### Post date: [2019 年 1 月 24 日午前 7:07 UTC](https://forum.ficusonline.com/t/pimatic-orange-pi-pc/76/3 "2019-01-24T07:07:02Z")

</div>

最新リリース版はnode.js-v8で動作するようです。

[https://forum.pimatic.org/topic/4340/released-pimatic-0-9-43/63](https://forum.pimatic.org/topic/4340/released-pimatic-0-9-43/63)

```auto
$ wget https://nodejs.org/dist/latest-v8.x/node-v8.15.0-linux-armv7l.tar.gz -P /tmp
$ cd /usr/local
$ sudo tar xzvf /tmp/node-v8.15.0-linux-armv7l.tar.gz --strip=1
$ sudo apt-get install build-essential git
$ cd /home/pi
$ mkdir pimatic-app
$ npm install pimatic --prefix pimatic-app --production
$ cd pimatic-app
$ node node_modules/pimatic/pimatic.js

```

---

<div class="post-metadata">

### Author: ![tk-fuse](https://forum.ficusonline.com/user_avatar/forum.ficusonline.com/tk-fuse/32/255_2.png) [@tk-fuse](https://forum.ficusonline.com/u/tk-fuse)
#### Post date: [2019 年 1 月 24 日午前 11:07 UTC](https://forum.ficusonline.com/t/pimatic-orange-pi-pc/76/4 "2019-01-24T11:07:19Z")

</div>

node.jsのアンインストールは、

> <https://stackoverflow.com/questions/11177954/how-do-i-completely-uninstall-node-js-and-reinstall-from-beginning-mac-os-x>

You may need to do the additional instructions as well:

```auto
sudo rm -rf /usr/local/{lib/node{,/.npm,_modules},bin,share/man}/{npm*,node*,man1/node*}

```

which is the equivalent of (same as above)…

```auto
sudo rm -rf /usr/local/bin/npm /usr/local/share/man/man1/node* /usr/local/lib/dtrace/node.d ~/.npm ~/.node-gyp 

```

or (same as above) broken down…

To completely uninstall node + npm is to do the following:

1. go to **/usr/local/lib** and delete any **node** and **node\_modules**
2. go to **/usr/local/include** and delete any **node** and **node\_modules** directory
3. if you installed with **brew install node** , then run **brew uninstall node** in your terminal
4. check your Home directory for any **local** or **lib** or **include** folders, and delete any **node** or **node\_modules** from there
5. go to **/usr/local/bin** and delete any **node** executable

You may also need to do:

```auto
sudo rm -rf /opt/local/bin/node /opt/local/include/node /opt/local/lib/node_modules
sudo rm -rf /usr/local/bin/npm /usr/local/share/man/man1/node.1 /usr/local/lib/dtrace/node.d

```

Additionally, NVM modifies the PATH variable in `$HOME/.bashrc` , which must be [reverted manually](https://github.com/creationix/nvm#removal).

Then download **nvm** and follow the instructions to install node. The latest versions of node come with **npm** , I believe, but you can also reinstall that as well.

---

<div class="post-metadata">

### Author: ![tk-fuse](https://forum.ficusonline.com/user_avatar/forum.ficusonline.com/tk-fuse/32/255_2.png) [@tk-fuse](https://forum.ficusonline.com/u/tk-fuse)
#### Post date: [2019 年 1 月 25 日午前 12:23 UTC](https://forum.ficusonline.com/t/pimatic-orange-pi-pc/76/5 "2019-01-25T00:23:26Z")

</div>

**グローバル環境でPimaticを起動**

```auto
cd ./node_modules/pimatic
sudo npm link

```

Then pimatic can be used with:

```auto
sudo pimatic.js [start|stop|status|restart]

```

**自動起動サービス設定**

[https://pimatic.teamemo.com/Guide/Autostarting](https://pimatic.teamemo.com/Guide/Autostarting)

You can autostart pimatic by additionally installing the init.d script:

```auto
wget https://raw.githubusercontent.com/pimatic/pimatic/v0.9.x/install/pimatic-init-d
sudo cp pimatic-init-d /etc/init.d/pimatic
sudo chmod +x /etc/init.d/pimatic
sudo chown root:root /etc/init.d/pimatic
sudo update-rc.d pimatic defaults

```

It should now start with:

```auto
sudo service pimatic start

```

and log the output to: `pimatic-app/pimatic-daemon.log`

---

<div class="post-metadata">

### Author: ![tk-fuse](https://forum.ficusonline.com/user_avatar/forum.ficusonline.com/tk-fuse/32/255_2.png) [@tk-fuse](https://forum.ficusonline.com/u/tk-fuse)
#### Post date: [2019 年 1 月 25 日午前 12:53 UTC](https://forum.ficusonline.com/t/pimatic-orange-pi-pc/76/6 "2019-01-25T00:53:12Z")

</div>

**プラグインインストール**

[https://pimatic.teamemo.com/Usage/Installing-Plugins](https://pimatic.teamemo.com/Usage/Installing-Plugins)

**Pimaticプラグイン**

> **[Plugins | pimatic - smart home automation for the raspberry pi](https://pimatic.org/pages/plugins/)**
>
> a home automation server and framework for the raspberry pi running on node.js

**マニュアルプラグインインストール**

You can manually install or update a plugin by running:

```auto
$ npm install --unsafe-perm pimatic-pluginname

```

inside your _ **pimatic-app** _ directory.

**npm --unsafe-perm オプション**

[https://docs.npmjs.com/misc/config#unsafe-perm](https://docs.npmjs.com/misc/config#unsafe-perm)

### [unsafe-perm§](https://docs.npmjs.com/misc/config#unsafe-perm)

- Default: false if running as root, true otherwise
- Type: Boolean

Set to true to suppress the UID/GID switching when running package scripts. If set explicitly to false, then installing as a non-root user will fail.

**プラグインに問題が有る場合は、githubからコード修正したフォークレポジトリをインストール**

[https://forum.pimatic.org/topic/1114/updated-how-to-install-a-plugin-from-github-using-npm-or-git](https://forum.pimatic.org/topic/1114/updated-how-to-install-a-plugin-from-github-using-npm-or-git)

pimatic-sysinfoプラグインは最新バージョンに対応していないため、オリジナルフォークしてコード修正後gitクローンインストール

> **[GitHub - capitalfuse/pimatic-sysinfo: CPU and Memory monitoring for pimatic](https://github.com/capitalfuse/pimatic-sysinfo)**
>
> CPU and Memory monitoring for pimatic

```auto
cd /home/pi/pimatic-app/node_modules/ 
sudo rm -rf <PLUGIN-PACKAGE>
git clone <URL>
cd <PLUGIN-PACKAGE>
npm install

```

---

<div class="post-metadata">

### Author: ![tk-fuse](https://forum.ficusonline.com/user_avatar/forum.ficusonline.com/tk-fuse/32/255_2.png) [@tk-fuse](https://forum.ficusonline.com/u/tk-fuse)
#### Post date: [2019 年 1 月 25 日午前 3:08 UTC](https://forum.ficusonline.com/t/pimatic-orange-pi-pc/76/7 "2019-01-25T03:08:06Z")

</div>

[https://github.com/mapbox/node-sqlite3](https://github.com/mapbox/node-sqlite3)

pimaticに必要な上記パッケージがビルド出来ていなかったため、gitソースからビルド・インストール

> $ cd pimetic-app/node\_modules  
> $ git clone [GitHub - TryGhost/node-sqlite3: SQLite3 bindings for Node.js](https://github.com/mapbox/node-sqlite3) sqlite3  
> $ cd sqlite3  
> $ npm install

---

<div class="post-metadata">

### Author: ![tk-fuse](https://forum.ficusonline.com/user_avatar/forum.ficusonline.com/tk-fuse/32/255_2.png) [@tk-fuse](https://forum.ficusonline.com/u/tk-fuse)
#### Post date: [2019 年 2 月 25 日午後 12:52 UTC](https://forum.ficusonline.com/t/pimatic-orange-pi-pc/76/8 "2019-02-25T12:52:45Z")

</div>

**以下スクリプトによりgithubのレポジトリからインストール**

**/home/user/install-git**

```
#!/bin/sh
BRANCH=$1
if [! -d pimatic-git]
then
  mkdir pimatic-git
fi
cd pimatic-git
DIR="$(pwd)"
echo "Will installing pimatic and pimatic plugins from git branch $BRANCH into $DIR"
if [! -d pimatic-git]
then
  mkdir node_modules
fi
for name in pimatic
do
  cd "$DIR/node_modules"
  if [-d $name]
  then
    INSTALL="cd $name && git pull && npm install"
    echo "Updating $name from git: $INSTALL"
  else
    INSTALL="git clone https://github.com/capitalfuse/$name.git --depth 1 -b $BRANCH && cd $name && npm install"
    echo "Installing $name from git: $INSTALL"
  fi
  bash -c "$INSTALL"
done

```

**pimatic-git** フォルダが作成されてgithubのレポジトリからカスタマイズしたpimaticをインストールすることが出来ます。
