Overview

Skill Level: Beginner

This recipe will guide you through connecting a Modcam MOD.01 intelligent vision sensor to Watson IoT Platform inside your own organization, and setting up a small Node-RED flow that demostrates the real-time aspects of the device and WIoTP

Ingredients

note: If you only want a MOD.01 to send data to your Internet of Things Platform instance, you can perform steps 1 and 2 only.

To properly implement this recipe you need the following:

  • A fully set up Modcam MOD.01 Intelligent Sensor running Peoplecounter connected to a network
  • A Bluemix organization
  • Some experience with Node-RED
  • An instance of Internet of Things Platform (IoTP) running inside your Bluemix organization.
  • (optionally) an SMTP-server that you may use to send email through

Once the recipe is completed you should have the following components in place:

  • A Modcam MOD.01 device connected to your Watson IoTP instance
  • Realtime peoplecount events in your WIoTP instance
  • A Node-RED application that demonstrates real-time aspects of IoTP using Modcam data.

Step-by-step

  1. Add the device type to Watson IoT Platform

    Go to “Services”, then “Dashboard” in your Bluemix console and select or create your IoT Platform instance. Click “Launch dashboard”

    1. Click “Devices” in the left panel and then “+ Add Device”
    2. Click “Create device type” and then click “Create device type” again.
    3. Input “MOD01” without quotes in the “Name” field and then click “Next”.
    4. For the purposes of this recipe none of the following fields are necessary to enter any information in so continue clicking “Next” and then finally “Create”.

    This step is required only once for each Watson IoTP instance deployed.

  2. Connect your Modcam MOD.01

    (If you’re not coming to this step directly from step 1, go to the Watson IoTP dashboard and click “+ Add Device”)

    With “MOD01” selected under “Choose Device Type”, click “Next”

    Locate the serial number of your MOD.01, you can find it on the back of the device:

    serial_number

    As “Device ID” enter “01” and then your full serial number for a total of 8 characters, e.g. “0100133a”, it is important that the Device ID is lowercase letters.

    Continue clicking “Next” – then finally click “Add”

    Make sure your MOD.01 is turned on and then email iotp@modcam.com with the contents in the grey box under “Your Device Credentials”: including deviceId, organization id and authentication token under the “your Device Credentials” heading. You must send this email from the email address you set up your MOD01 with. This is temporarily a manual process and response times are within 18 hours.

    Once you’ve received confirmation from iotp@modcam.com your device will be pushing data to your Bluemix account, if you have several devices you can repeat this step for each device.

     

  3. Setting up Node-RED

    In Bluemix:

    1. Click “Services”, “Application Services” and “Create Application Service”
    2. In the search box, type “Node-RED” and click the “Node-RED Starter” item
    3. Enter an application name and click “Create”

    Your new Node-RED instance should be starting by now, click “Connections” in the menu to the left and then “Connect existing” in the main page area.

    You should now see your Watson IoT Platform instance in a box on screen, click it and then “Connect”, when asked to restage, press cancel.

    Back in overview press the restart button on the top right to restart the Node-RED instance.

    Once restarted, click the link to go to your new Node-RED application url, go through the quick setup tutorial and move on to step 4.

  4. Set up the demo

    In the Node-RED flow editor we’re going to create a flow that looks something like this:

    sample_flow

    The function of the flow will be to keep count of people passing below the MOD.01 and sending an alert email at set thresholds.

    The first node – “IBM IoT” can be found under the “input” section to the left, add it by dragging it to the big blank space and double click the node to edit its configuration.
    Change authentication to “Bluemix Service” and enable all the checkboxes, then click “done”. This will automatically connect to the IoT service you bound in step 3 and make sure all device events come through here.

    The next node “Collect” is a function type node that will allow us to input a minimal amount of javascript to parse out the data we need from events. In essence, this node will keep a global store of counts in/out and add new incoming events on to them. Drop in a “function”-node from the menu, double click it to name it “Collect” and insert the following block of code.

    // create a global to hold our total if it doesn't already exist
    if(!global.get("counts")) {
    global.set("counts", {in: 0, out: 0});
    }
    // get the global object and add the amount from the device event into whatever direction
    // the event indicated
    counts = global.get("counts");
    counts[msg.payload.direction] += msg.payload.amount;
    // pass on the global count object as the payload to the next node
    msg.payload = counts;
    return msg;

     

    If you want to, you can add a “Debug” output node as indicated in the image above, this will allow you to see the raw data flow as it comes in.

    The purpose of the “Filter” function node is to monitor the global count object and pass on a human readable message when counts passes a threshold. The node should be set to execute the following block of code.

    // when passages in or out are in even multiples of 10, forward a payload that says so.
    if(msg.payload.in % 10 === 0 || msg.payload.out % 10 === 0) {
    return {
    payload: "Your MOD.01 has counted " +
    msg.payload.in +
    " passages going in and " +
    msg.payload.out +
    " passages going out"
    }
    } else {
    return null;
    }

     

    Finally, an e-mail node from the “social” block of the menu to the left is attached to the “Filter” node, configure this node with an recipient email of your choice and an SMTP-server that you are allowed to send e-mail through.

    Clicked “Deploy” on the top right of the Node-RED editor and walk back and forth under the MOD.01 sensor; every 10 passages in or out you should receive an email in your inbox!

Join The Discussion