REST API
Contents |
Installing & Configuring Node (on Raspbian)
I used a guide @ rueedlinger.ch for installing an up-to-date Node.js, as the one from apt-get was quite out of date. Also, I didn't have luck with Node 10.5, so I went with Node 10.2.
You download binaries, so it's very straight forward.
sudo mkdir /opt/node wget http://nodejs.org/dist/v0.10.2/node-v0.10.2-linux-arm-pi.tar.gz tar xvzf node-v0.10.2-linux-arm-pi.tar.gz sudo cp -r node-v0.10.2-linux-arm-pi/* /opt/node
Change the default profile with
sudo nano /etc/profile
And add these lines before "export PATH"
NODE_JS_HOME="/opt/node" NODE_PATH="/opt/node" PATH="$NODE_JS_HOME/bin/:$PATH"
And then log out and back in.
Installing NPM Modules
Install "forever" as a global npm module. To do this you might have to set the proper path as root. "sudo su" is used here as a stop gap / work-around, I don't recommend it as a habit. If I could've done it a different way here, I would've. However, this worked so it's worth the two lines as su.
sudo su PATH=/opt/node/bin/:$PATH npm install forever -g exit
(If you install it local first, before that, you might have to uninstall both, and then install globally)
Per node-i2c module readme on Raspbian
After installing i2c, you'll need to configure that the modules are available.
sudo vi /etc/modules
And add
i2c-bcm2708 i2c-dev
Then edit
sudo nano /etc/modprobe.d/raspi-blacklist.conf
And comment out the i2c module so it looks like:
# blacklist i2c-bcm2708
Load the kernel module
sudo modprobe i2c-bcm2708
...You may need to reboot at this point.
Check that it's there
pi@raspberrypi ~ $ sudo ls /dev/i2c-* -l crw------- 1 root root 89, 0 Oct 23 20:03 /dev/i2c-0 crw------- 1 root root 89, 1 Oct 23 20:03 /dev/i2c-1
Giving proper permissions to the i2c devices
Here we modify our udev rules in order to modify the i2c device to be owned by root. In the usermod command replace "pi" with the username of your choice, if you so wish.
sudo groupadd i2c sudo usermod -aG i2c pi sudo echo 'KERNEL=="i2c-[0-9]*", GROUP="i2c"' >> /etc/udev/rules.d/10-local_i2c_group.rules
Setting up syslog
The server process uses node-syslog to get the logging done, which in turn requires some setup on the syslogd on your system. Again note, if you're using a pre-configured distro, this will already be setup for you.
In my example configuration in Pidora, we'll edit our syslog.conf
nano /etc/rsyslog.conf
And we'll add these two lines:
# Save veeOP daemon messages to veeop.log local5.* /var/log/veeop.conf
Then restart the daemon with
sudo service syslog restart
You'll probably also want to rotate this log, go and edit instructions for syslog
nano /etc/logrotate.d/veeop
And fill it with:
/var/log/veeop.log {
missingok
notifempty
size 5M
yearly
create 0600 root root
}