CommonGarden/BasicRaspberryPiExample

Name: BasicRaspberryPiExample

Owner: Common Garden

Description: null

Created: 2017-11-18 02:39:56.0

Updated: 2017-11-18 03:01:35.0

Pushed: 2018-01-03 00:52:44.0

Homepage: null

Size: 16

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

BasicRaspberryPiExample

Setup

Setup your raspberry pi by following these instructions.

Install the latest version of Node. Todo this, either search for an article to help walk you through it or run the following:

 https://nodejs.org/dist/v8.6.0/node-v8.6.0-linux-armv7l.tar.xz
-xvf node-v8.6.0-linux-armv7l.tar.gz 
ode-v8.6.0-linux-armv7l

Then copy to /usr/local:

 cp -R * /usr/local/

Test that's it's working with node -v.

To clean up after yourself:

& sudo rm node-v8.6.0-linux-armv7l.tar.gz

Now we're ready for the rest of the install.

 apt-get update
 apt-get install wiringpi git
clone https://github.com/CommonGarden/BasicRaspberryPiExample
install
 node example-driver.js

This example driver uses a BME280 climate sensor. If none is provided it will emit random numbers. See johnny-five for lots of plug and play sensors.

Connecting to Grow-IoT

By default, the example driver connects to https://grow.commongarden.org.

To change this see the bottom of the example-device.js file. It currently reads.

owHub.connect({
host: 'grow.commongarden.org',
port: 443,
ssl: true
;

For development it's easier to simply connect to you local computer. Find your computer's IP address and change the host, port, and ssl options:

owHub.connect({
host: '10.0.0.198', // The ip address of the host
port: 3000, // The port you are running Grow-IoT on
ssl: false
;
Run on boot

Once you're happy with your driver you'll want to start it on boot in case your device looses power.

Install forever globally.

 npm install forever -g

Then create a new text file in/etc/init.d/:

 nano /etc/init.d/grow

Paste in the follow (note this assumes you installed Grow-Hub in the root of the home folder for a user named pi):

in/bash
c/init.d/grow
rt PATH=$PATH:/usr/local/bin
rt NODE_PATH=$NODE_PATH:/usr/local/lib/node_modules

 "$1" in
t)
 sudo forever start --sourceDir=/home/pi/Grow-Hub/driver -p /home/pi/Grow-Hub/driver -l forever.log -o out.log -e err.log --append Grow-Hub.js

)
 sudo forever stop --sourceDir=/home/pi/Grow-Hub/driver Grow-Hub.js


 "Usage: /etc/init.d/grow {start|stop}"
 1


 0

Make it executable with the following command:

d 755 /etc/init.d/grow 

Feel free to test it:

etc/init.d/grow start/stop

If all goes well, make it bootable:

 update-rc.d grow defaults

To remove it from boot:

 update-rc.d -f grow remove

One last step, edit the /etc/rc.local file.

 nano /etc/rc.local

Insert the following line before exit 0:

etc/init.d/grow start

Reboot and your pi should start into the Grow-Hub driver.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.