Adafruit IO

You can setup the cloud cam project to send to feeds on Adafruit IO.  Using these image feeds you can build interesting dashboards that combine live camera views, sensor readings, and more.

First you'll need to have access to the Adafruit IO beta--right now it's a limited invite beta but will be expanding more over time.

Next it will help to familiarize yourself with the following guides to get an overview of Adafruit IO:

You can also check out some example projects that use Adafruit IO to help understand its capbilities and get some inspiration:

Follow the steps below to setup the Pi to send data to Adafruit IO.  Make sure you're using the Raspbian Jessie operating system release and have followed the Pi Camera Setup steps before continuing!

Install Node.js

First you'll need to install the latest stable version of Node.js for the Raspberry Pi.  With the recent Raspbian Jessie release this process is much easier than it was in the past.  You just need to download a pre-built Node.js package from the node-arm project and install it.

Be aware that you'll need to make sure you don't already have a version of Node.js installed on the Pi.  If you're unsure or have an old version installed I recommend starting with a fresh new Raspbian Jessie image.

In a command terminal on the Pi execute the following commands:

Download: file
cd ~
wget http://node-arm.herokuapp.com/node_latest_armhf.deb
sudo dpkg -i node_latest_armhf.deb

This should install a recent stable version of Node.js and output text like:

Download: file
Selecting previously unselected package node.
(Reading database ... 117337 files and directories currently installed.)
Preparing to unpack node_latest_armhf.deb ...
Unpacking node (4.2.1-1) ...
Setting up node (4.2.1-1) ...
Processing triggers for man-db (2.7.0.2-5) ...

To double check Node.js and the NPM package manager are installed you can run commands to check their version.  

For example to check Node.js run:

Download: file
node -v

At the time of writing this guide the current stable version is:

Download: file
v4.2.1

And to check NPM run:

Download: file
npm -v

Which at the time of writing was version:

Download: file
2.14.7

Install adafruit-io-camera

Once the latest Node.js version is installed you can move on to intall the adafruit-io-camera tool.  This tool will monitor the Pi camera and send pictures to an Adafruit IO feed where they can be displayed on a dashboard.

To install adafruit-io-camera run:

Download: file
sudo apt-get update
sudo apt-get install -y imagemagick
sudo npm install --global --no-optional forever forever-service adafruit-io-camera

If you're interested in looking at the source code for the library, you can find it at https://github.com/adafruit/adafruit-io-camera.

You should see NPM go through and install the adafruit-io-camera tool and all of its dependencies:

Download: file
/usr/local/bin/forever-service -> /usr/local/lib/node_modules/forever-service/bin/forever-service
/usr/local/bin/get-forever-config -> /usr/local/lib/node_modules/forever-service/bin/get-forever-config
npm WARN engine [email protected]: wanted: {"node":"0.6 || 0.8 || 0.10"} (current: {"node":"4.2.1","npm":"2.14.7"})
/usr/local/bin/forever -> /usr/local/lib/node_modules/forever/bin/forever
/usr/local/bin/adafruit-io -> /usr/local/lib/node_modules/adafruit-io-camera/cli.js
[email protected] /usr/local/lib/node_modules/forever-service
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected] ([email protected])
└── [email protected] ([email protected], [email protected])

[email protected] /usr/local/lib/node_modules/forever
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected])
└── [email protected] ([email protected], [email protected], [email protected], [email protected])

[email protected] /usr/local/lib/node_modules/adafruit-io-camera
├── [email protected]
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected], [email protected], w[email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected])
└── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])

Configure adafruit-io-camera

After installing the tool you'll need to configure adafruit-io-camera to access your Adafruit IO account.  Before you start make sure you have the following information:

  • Adafruit account username - Find this by logging in to https://accounts.adafruit.com/ and copying the Username field value.
  • Adafruit IO key - Find this by accessing https://io.adafruit.com/settings and clicking the yellow View AIO Keys button, then copying the key value out (it will be a long string of hex characters).

Now to configure the camera run the following command:

Download: file
adafruit-io camera config --username USERNAME --key KEY

Where USERNAME is your Adafruit account username and KEY is your Adafruit IO key value.  For example if your username were mosfet and and you had a key value of 0123ffff you would run:

Download: file
adafruit-io camera config --username mosfet --key 0123ffff

Start adafruit-io-camera

Once the camera tool is configured you can turn it on to start sending picture data to an Adafruit IO feed.  Right now the easiest way to use the camera tool is to have it upload a new image periodically, like once every two seconds.  This way you can build a dashboard that shows camera feeds, sensor data, and buttons to interact with devices.

To start the camera and have it send an image to a feed every two seconds run the following command:

Download: file
adafruit-io camera start -f camera_feed -m false -r 2

This parameters to the command have the following meaning:

  • start - This is the camera command that tells the tool to start the camera process.
  • -f camera_feed - This tells the tool to write image data to the feed named camera_feed.  You can change this value to write to a different feed.  Don't worry if the feed doesn't exist as it will be created automatically.
  • -m false - This explicitly turns off motion detection and instead sends a new image to the camera feed at a fixed frequency.  Motion detection support in the tool and Adafruit IO dashboard is still a bit new and under development.  You can experiment with turning on motion detection, but be aware only the most recently detected motion image will be stored in the feed (i.e. you can't see a history or log of motion events yet).
  • -r 2 - This tells the tool to write a new image to the feed every 2 seconds.  You can use a different value (in seconds) to change how often image data is written.  Remember though you can only write data about once a second to Adafruit IO so keep this to a value like once every 2 seconds at most.

Once the camera tool loads you should see it print something like the following and exit:

Download: file
                                      ▄▄
                                    ▄████
                                  ▄███████
                                 █████████▌
                                ███████████
                               ████████████▌
              ███████████████▄ ████████████▌
               █████████████████████▀▀█████ ▄▄▄▄▄▄▄
                ▐██████████████████   █████████████████▄▄
                  ▀█████████  ▀▀███  ██████████████████████
                    █████████▄▄  ▐████▀    ▐█████████████▀
                      ▀▀███████████████▄▄█████████████▀
                       ▄███████   ██  ▀████████████▀
                      ███████▀  ▄████  ▐█████▄
                     █████████████████▄▄██████▄
                    ███████████████████████████
                   ██████████████ ▐████████████▌
                  ▐██████████▀▀    ▀███████████▌
                  █████▀▀            ▀█████████▌
                                        ▀██████
                                           ▀███
----------------------------------------------------------------------
                           adafruit io
----------------------------------------------------------------------
[info] starting camera...
[info] camera daemon started and is pushing images to Adafruit IO

If you see an error go back and check the camera tool was configured to use your Adafruit account username and IO key and try again.

Note that it takes a few seconds for the camera process to start and the red camera LED to turn on.

Create Dashboard

With the camera tool started and sending data to a feed you're ready to make a dashboard to view the data.  If you're new to creating dashboards it will help to familiarize yourself with a few guides that walk through the process of creating a dashboard:

To start navigate to https://io.adafruit.com/dashboards while you're logged in to your Adafruit account.  Click the Create Dashboard button in the upper right corner and give the new dashboard a descriptive name like Pi Camera Dashboard.

Once the dashboard is created click the New Block '+' button in the upper right to bring up the block selection list.  Scroll down to the image block highlighted below and click Create:

In the block creation wizard that appears find the feed named camera_feed by scrolling down to it or using the filter/search box in the upper left.  Then click the Choose action to select the feed.  

Don't worry if you see the last value is null, you can ignore the value for now and check how the feed looks on the dashboard.

Once you've chosen the feed click Next Step to continue:

On the next page you can give the block a better title.

Don't worry if the block preview shows a blank image, you can continue moving forward.

Click Create Block to finish creating the image block:

You should see the block added to the dashboard and it start to display camera images:

You might notice the image animating through different frames from the camera.  The dashboard webpage is actually caching the most recently sent images and animating the display of them.  This is handy to get a quick idea of what has recently happened in the feed.  Note that this animation will only run from data stored in the browser cache--there's no actual history of image data stored in the feed, only the most recent image.

Awesome, now you have an internet dashboard with a live image feed!  You can add more blocks with other camera feeds, sensor values, buttons, and more to build the perfect dashboard for your devices!

For example check out guides on using Adafruit IO to monitor and control devices like:

You could build a dashboard to monitor and control the devices in your room:

Stop adafruit-io-camera

To stop the camera tool from sending data to Adafruit IO go back to a terminal on the Pi and run the following command:

Download: file
adafruit-io camera stop

You should see the tool confirm that it stopped the camera:

Download: file
[info] stopping camera...

Run adafruit-io-camera at Boot

To setup the camera tool to run automatically at boot you can call it from the /etc/rc.local file as a simple means of starting the tool.

Run the following command to edit this file:

Download: file
sudo nano /etc/rc.local

Now add a new line right above the exit 0 line at the end:

Download: file
sudo -H -u pi adafruit-io camera start -f camera_feed -m false -r 2 &

This line will use the sudo command to switch to the default pi user (which has the Adafruit IO credentials associated with its home directory) and then run the camera start command (notice all the same parameters to control the tool are passed as before).

Be sure the lines ends with an ampersand '&' character!  If you forget to add this character the Pi might not boot up!

Here's what the /etc/rc.local file should look like:

Now save the file and exit the editor by pressing Ctrl-o then enter and then Ctrl-x.

Reboot the Pi by running:

Download: file
sudo reboot

When the Pi reboots it should start the camera tool and send data to Adafruit IO.

To disable the camera tool edit the /etc/rc.local file and remove the line that was added.  Then save and reboot the Pi.

That's all there is to using the adafruit-io-camera tool to send Pi camera images to Adafruit IO!

This guide was first published on Nov 05, 2015. It was last updated on Nov 05, 2015. This page (Adafruit IO) was last updated on Aug 21, 2019.