In this cookbook entry, I’m going to go over how to register your Raspberry Pi as a Bitdog Hub and connect it to the Bitdog Cloud.

Install OS

To get started, you will need to have an OS installed. I’m using NOOBS on my Raspberry Pi, which contains Raspian. For more information on installing NOOBS and Raspian, you can go here.

Update OS and Firmware

Depending on the version of the OS you installed, it may be a little out of date. Run the following commands to update the OS and firmware. Warning,  the upgrade may take a long time.

sudo apt update
sudo apt upgrade
sudo apt install rpi-update
sudo rpi-update

Install Node.js

Once you have your OS installed, you’re going to need to install Node.js. You’ll want to update your package repository, download the latest packages, and then install Node.js using the following commands:

curl -sL https://deb.nodesource.com/setup_4.x | sudo bash -
sudo apt install nodejs

Install node-gyp

We will be installing Node.js addons that use node-gyp as a build tool. We will need to install this globally.

sudo npm install node-gyp -g

Install open-zwave

We need to install the open-zwave package that is required by  Bitdog Hub. The open-zwave package depends on the libudev package which can be install with the following command.

sudo apt install -y libudev-dev

Once libudev is installed, grab the latest open-zwave package files from GitHub repo and unzip them onto your Raspberry Pi.

cd /tmp
wget https://github.com/OpenZWave/open-zwave/archive/master.zip
unzip master.zip

After you have the files unzipped on your device, you will need to compile them. Run the following command to compile them, and then go grab a coffee because this is going to take a little bit of time…

cd /tmp/open-zwave-master
sudo make && sudo make install

Coffee almost gone and open-zwave finally compiled, you will need to set an environment variable and put it in the “.bashrc” file so that it gets set on every new terminal session.

echo 'export LD_LIBRARY_PATH=/usr/local/lib' >> $HOME/.bashrc

After running this command, restart the terminal window so that the environment variable takes effect.

Install Bitdog Hub

Now that we have Node.js and open-zwave installed, we are ready to install the Bitdog Hub. We will create a new “hub” directory and install the Bitdog Hub.

mkdir $HOME/hub
cd $HOME/hub
bash <(curl -s https://bitdog.io/installhub)

Create Account and Download Mobile App

You need to create a Bitdog account if you haven’t already. Navigate to https://bitdog.io and click the Sign Up button to create an Account. Once your account is created,  install our mobile app on you phone.  Find “Bitdog Remote” in your mobile store and install it.

Automatic Pairing

Now that you have an account and have the mobile app on your phone, let’s automatically pair your Bitdog Hub with your account. You will be able to automatically pair your Raspberry Pi with your Bitdog account if your mobile phone is on the same Wi-Fi network.

While connected to the same WiFi as you Raspberry Pi, start the Bitdog Remote app on your phone. If this is the first Bitdog Hub you are setting up, then your app will look something like the image below. Click the large “START PAIRING” button to start the automatic pairing process.

welcome

Next, go back to your Raspberry Pi and issue the following commands.

cd $HOME/hub
./bitdoghub start

The hub will ask if you want to automatically pair. Enter “y” for yes and you should see the text “bitdog-hub started” if the pairing was successful.

start-hub

Close the mobile app and reopen it and you should be able to manage your Bitdog Hub from it now.

Manual Pairing

To manually pair your Bitdog Hub to your Bitdog Cloud account, copy the “Manual Hub Pairing”  passphrase from the mobile app or change it to something you can remember. Enter the following command on your Raspberry Pi.

cd $HOME/hub
./bitdoghub register -u {username} -p {passphrase}