Using Particle Photon with Johnny Five and VoodooSpark

I am elbow deep preparing an updated IoT workshop for three conferences in the next two months:

WeatherShieldFor these workshops I’ve decided to do something different – mostly driven by the fact that I gave away all 300 Arduino Yun kits I had (based on the SparkFun Inventors Kit) and one of my colleagues donated 180 Particle Photon development kits (and SparkFun Weather Shields) to me.

Particle already has some great getting started documentation and Paul DeCarlo already has a great tutorial on using the Weather Shield with Web Hooks on Hackster.io. I wanted to do something different to show how to build interesting IoT solutions, and leverage Microsoft Azure services where it makes sense.

I decided that my best angle is to build a series of labs that teach you how to use the Particle Photon with the Johnny Five framework (which we use in the existing Arduino labs on ThingLabs.io). The difference here is that, unlike the Arduino Yun which has a Linux distro onboard, the Photon has a small ARM M3 and a Broadcom Wi-Fi SOC – but no Linux distro. That means that unlike the Arduino labs I can’t build labs around creating Node.js apps that will eventually run in the onboard Linux environment (because there isn’t one).

Instead I looked around my house….WeMo. That is a great example of how the Photon works. Individual devices connected directly to a cloud service. SmartThings. Phillips Hue. Hmm. These are different. They use a hub-and-spoke model, with the hub acting as a field gateway between the spoke devices and the cloud service. The Photon is a Wi-Fi enabled board – why can’t it enable the spoke devices on my local Wi-Fi network and connect to a hub…perhaps a Raspberry Pi 2 or an Arduino Yun, which acts as the field gateway.

It turns out it can.PhotonRPi

I turned to the VoodooSpark firmware and the Particle-IO plugin for Johnny Five. VoodooSpark is open source firmware for the Particle Core and Photon that enables TCP communication with the device over a local Wi-Fi network instead of through the Particle Cloud. That means that with the VoodooSpark firmware you can build a local network with devices that you can communicate with. The way you accomplish that is with Johnny Five, an open source framework for hardware devices like Arduino, Raspberry Pi, Intel Edison and yes, the Particle Photon (enabled with the Particle-IO plugin).  With these bits of open source deliciousness I can configure the Photon to communicate over local Wi-Fi to whatever hub device I want, running a Node.js app. Right now that is my Windows 10 laptop, but soon it will be a Raspberry Pi 2 or an Arduino Yun (I haven’t decided yet). The hub device can communicate with multiple spoke devices (Photons or others) and act as the go-between to the Azure services. In the example shown here I simply configure two Johnny Five board objects based on a Particle object (or a Spark object as shown here – I am updating this to the Particle-IO code – Spark-IO is the old code from before Particle was Particle) that defines my Particle Cloud access token and the device ID (so the hub can call the service to get the Photon’s IP address).

2Photons

The labs currently use Nitrogen as the IoT device registry and pub-sub backend shim in front of Azure Event Hubs. The Nitrogen code to send a message from the Node app looks a bit like this:

        // Define the callback function for the photoresistor reading
        // The freq value used when the photoresistor was defined
        // determines how often this is invoked, thus controlling
        // the frequency of Nitrogen messages.
        photoresistor.on('data', function() {
            // Capture the ambient light level from the photoresistor
            var lightLevel = this.value;
            // Create a Nitrogen message
            var message = new nitrogen.Message({
                type: '_lightLevel',
                body: {
                    ambientLight: lightLevel
                }
            });
            
            // Log the light level value for debugging    
            session.log.info('Sending ambientLight: ' + lightLevel);
            // Send the message
            message.send(session);
        });

I am cranking away on the new labs – they will debut on ThingLabs.io around the same time as the TECHintersection conference in a couple weeks. This lab series will culminate (hopefully – I haven’t built this yet) in a smart home solution using a Raspberry Pi 2 as the hub and one or more Photons as spoke devices for things like ambient light and temperature, lighting control, open/close blinds, garage door monitoring, etc.

If you want to spy on me you can watch the code evolve here.

Advertisements

Comments

  1. Hi thanks for the article! so with Voodoo does that then mean that those devices could no longer be brokers for messages coming from the photon infrastructure or Azure IoT or AWS IoT you’d need something like your laptop for now or a Pi etc to be the message broker then distributing out to the local Photons?

    Is Johnny5 and that implementation mainly used for that local network type scenario? I was wondering if you could use Johnny5 on a Photon and still have it be able to receive messages from external providers
    Thanks 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: