node.js、hubotの導入

node.jsの導入hubotの雛形の生成Raspberry Piの起動時に…の通り

sudo apt install -y nodejs npm
sudo npm cache clean
sudo npm install npm n -g
sudo n lts

sudo npm install -g yo generator-hubot
mkdir homebot; cd homebot
yo hubot

? Owner (User <user@example.com>) [Enter]
? Bot name (homebot) [Enter]
? Description (A simple helpful robot for your Company) [Enter]
? Bot adapter (campfire) slack[Enter]

sudo apt install redis-server
npm install coffee-script@^1.12.6
rm hubot-scripts.json
vi hubot-scripts.json    “hubot-heroku-keepalive”,を削除

npm install hubot-broadlink-rm
vi external-scripts.json    “hubot-broadlink-rm”,を追加
vi bin/hubot

#!/bin/sh
set -e

npm install
export PATH=”node_modules/.bin:node_modules/hubot/node_modules/.bin:$PATH”
export HUBOT_SLACK_TOKEN=xxx…
exec node_modules/.bin/hubot –name “homebot” “$@”

vi bin/homebot.sh

#!/bin/sh
cd /home/pi/homebot
sudo -u pi bin/hubot –adapter slack

chmod +x bin/homebot.sh
vi /etc/systemd/system/homebot.service

[Unit]
Description = hubot for smart home

[Service]
ExecStart=/home/pi/homebot/bin/homebot.sh
Restart=always
Type=simple

[Install]
WantedBy=multi-user.target

systemctl list-unit-files –type=service
sudo systemctl enable homebot
sudo reboot
systemctl status homebot

Raspberry pi zero wセットアップメモ

google homeでテレビや照明のコントロール用

stretch_liteイメージ(2017-11-29-raspbian-stretch-lite.zip)をダウンロード
イメージ書き込み(etcher使用)

bootに以下2つを作成
「ssh」(空ファイル)
「wpa_supplicant.conf」    秀丸なら「ファイル」「エンコード」で改行をLFのみにする

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=JP
network={
ssid=”xxxxxxxx”
scan_ssid=1
psk=0c09…
key_mgmt=WPA-PSK
}

起動後、teratermで接続
sudo swapoff –all
sudo apt-get remove dphys-swapfile
sudo reboot

vi /etc/dhcpcd.conf
interface wlan0
static ip_address=192.168.x.x
static routers=192.168.x.x
static domain_name_servers=x.x.x.x

vi /etc/fstab
tmpfs /tmp tmpfs defaults,size=40m,noatime,mode=1777 0 0
tmpfs /var/tmp tmpfs defaults,size=16m,noatime,mode=1777 0 0
tmpfs /var/log tmpfs defaults,size=32m,noatime,mode=0755 0 0

sudo vi /etc/rsyslog.conf
メールとかkern、lpr、userのログは取らない

sudo vi /etc/rc.local

mkdir -p /var/log/ConsoleKit
mkdir -p /var/log/samba
mkdir -p /var/log/fsck
mkdir -p /var/log/apt
mkdir -p /var/log/ntpstats
mkdir -p /var/log/apache2
mkdir -p /var/log/redis
touch /var/log/redis/redis-server.log
chmod 777 /var/log/redis/redis-server.log
chown root.ntp /var/log/ntpstats
chown root.adm /var/log/samba
touch /var/log/lastlog
touch /var/log/wtmp
touch /var/log/btmp
chown root.utmp /var/log/lastlog
chown root.utmp /var/log/wtmp
chown root.utmp /var/log/btmp

sudo apt-get install -y ntp
sudo vi /etc/ntp.conf

server ntp1.jst.mfeed.ad.jp
server ntp2.jst.mfeed.ad.jp
server ntp3.jst.mfeed.ad.jp

sudo raspi-config    タイムゾーンの設定

vi /etc/sysctl.conf    net.ipv6.conf.all.disable_ipv6=1を追加
sudo sysctl -p

sudo apt update
sudo apt upgrade

sudo reboot