Install the latest version of Node. To do this, either search for an article to help walk you through it or run the following:
wget https://nodejs.org/dist/v8.9.1/node-v8.9.1-linux-armv7l.tar.xz
tar -xvf node-v8.9.1-linux-armv7l.tar.xz
cd node-v8.9.1-linux-armv7l
Then copy to /usr/local
:
sudo cp -R * /usr/local/
Test that it's working with node -v
.
Once node.js is working, you're ready for the rest:
sudo apt-get update
sudo apt-get install wiringpi usbrelay git i2c-tools
git clone https://github.com/CommonGarden/Grow-Hub
cd Grow-Hub/driver
npm install
sudo node Grow-Hub.js
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:
growHub.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:
growHub.connect({
host: '10.0.0.198', // The ip address of the host
port: 3000, // The port you are running Grow-IoT on
ssl: false
});
Once you're happy with your driver you'll want to start it on boot in case your device loses power.
Install forever globally:
sudo npm install forever -g
Then create a new text file in/etc/init.d/
:
sudo nano /etc/init.d/grow
Paste in the following (note that this assumes you've installed Grow-Hub in the home
folder for a user named pi
):
#!/bin/bash
#/etc/init.d/grow
export PATH=$PATH:/usr/local/bin
export NODE_PATH=$NODE_PATH:/usr/local/lib/node_modules
case "$1" in
start)
exec 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
;;
stop)
exec sudo forever stop --sourceDir=/home/pi/Grow-Hub/driver Grow-Hub.js
;;
*)
echo "Usage: /etc/init.d/grow {start|stop}"
exit 1
;;
esac
exit 0
Make it executable with the following command:
sudo chmod 755 /etc/init.d/grow
Feel free to test it:
sh /etc/init.d/grow start
To stop it:
sh /etc/init.d/grow start/stop
If all goes well, make it bootable:
sudo update-rc.d grow defaults
To remove it from boot:
sudo update-rc.d -f grow remove
One last step, edit the /etc/rc.local file:
sudo nano /etc/rc.local
Insert the following line before exit 0
:
sh /etc/init.d/grow start
Reboot and your pi should start into the Grow-Hub driver.
To check the logs, ssh into the raspberry pi and see the out.log
and error.log
files in the home directory. An additional forever.log
file can be found in the driver/
folder. See forever documentation for more info.
These instructions come from this Headless Raspberry Pi configuration over Bluetooth article. Thanks to Mozilla and Patrick Hundal for providing an excellent resource.
Let’s start by creating the main script that will set up and establish the default Bluetooth services and serial port you will connect to on startup.
You’ll create this file in the root directory, like so:
sudo nano /btserial.sh
Add the following lines to the script:
#!/bin/bash -e
#Edit the display name of the RaspberryPi so you can distinguish
#your unit from others in the Bluetooth console
#(very useful in a class setting)
echo PRETTY_HOSTNAME=raspberrypi > /etc/machine-info
# Edit /lib/systemd/system/bluetooth.service to enable BT services
sudo sed -i: 's|^Exec.*toothd$| \
ExecStart=/usr/lib/bluetooth/bluetoothd -C \
ExecStartPost=/usr/bin/sdptool add SP \
ExecStartPost=/bin/hciconfig hci0 piscan \
|g' /lib/systemd/system/bluetooth.service
# create /etc/systemd/system/rfcomm.service to enable
# the Bluetooth serial port from systemctl
sudo cat <<EOF | sudo tee /etc/systemd/system/rfcomm.service > /dev/null
[Unit]
Description=RFCOMM service
After=bluetooth.service
Requires=bluetooth.service
[Service]
ExecStart=/usr/bin/rfcomm watch hci0 1 getty rfcomm0 115200 vt100 -a pi
[Install]
WantedBy=multi-user.target
EOF
# enable the new rfcomm service
sudo systemctl enable rfcomm
# start the rfcomm service
sudo systemctl restart rfcomm
Save the file, and then make it executable by updating its permissions like so:
chmod 755 /home/pi/btserial.sh
Now you have the basics of the script required to turn on the Bluetooth service and configure it. But to do this 100% headless, you’ll need to run this new script on startup. Let’s edit /etc/rc.local to launch this script automatically.
sudo nano /etc/rc.local
Add the following lines after the initial comments:
#Launch bluetooth service startup script /home/pi/btserial.sh
sudo /btserial.sh &
Save the rc.local
script.
Now you are ready to go. Plug in power to the Rpi and give it 30 seconds or so to startup. Then unplug it, and plug it in again and let it boot up a second time. Restarting the Bluetooth service doesn’t work correctly, so we need to reboot.
Now let’s connect.
On your desktop/laptop, open up your Bluetooth preferences and ensure Bluetooth is enabled.
Select “raspberrypi” (or whatever you have used for PRETTY_HOSTNAME in the btserial.sh script) when it appears and pair with it. It should pair automatically (remember what we said earlier about security issues?)
Open a terminal window on your local machine, and start a screen session to connect via the new Bluetooth serial port created from the RPi connection. First let’s check the name of the serial connection:
ls /dev/cu.*
This should produce a list of available serial ports, one of which should now be named after your pi. Then we can connect.
screen /dev/cu.raspberrypi-SerialPort 115200
Give it a second, and you should be at the prompt of the RPi console! Congrats!
After you setup a solid wifi connection, it's good to secure the bluetooth configuration. To do so, Let’s edit /etc/rc.local
to NOT launch the btserial.sh
script automatically.
sudo nano /etc/rc.local
Comment out the following lines:
#Launch bluetooth service startup script /home/pi/btserial.sh
#sudo /btserial.sh &