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

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

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

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

https://nodejs.org/dist/latest-v4.x/

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

wget 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インストールページを参照して下さい。

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

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

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

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

cd pimatic-app

wget 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

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

https://forum.pimatic.org/topic/4340/released-pimatic-0-9-43/63

$ 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

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

You may need to do the additional instructions as well:

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

which is the equivalent of (same as above)…

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:

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.

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.

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

cd ./node_modules/pimatic
sudo npm link

Then pimatic can be used with:

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

自動起動サービス設定

https://pimatic.teamemo.com/Guide/Autostarting

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

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:

sudo service pimatic start

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

プラグインインストール

https://pimatic.teamemo.com/Usage/Installing-Plugins

Pimaticプラグイン

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

You can manually install or update a plugin by running:

$ npm install --unsafe-perm pimatic-pluginname

inside your pimatic-app directory.

npm --unsafe-perm オプション

https://docs.npmjs.com/misc/config#unsafe-perm

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

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

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

https://github.com/mapbox/node-sqlite3

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

$ cd pimetic-app/node_modules
$ git clone GitHub - TryGhost/node-sqlite3: SQLite3 bindings for Node.js sqlite3
$ cd sqlite3
$ npm install

以下スクリプトにより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をインストールすることが出来ます。