Overview

Skill Level: Any Skill Level

Video Turnstile counts pedestrians, passengers, bicycles and vehicles - logging the time, GPS location, direction and counts. This recipe explains how to collect data from the VT via the IBM cloud using IBM Watson and Node-RED.

Ingredients

What you'll need…

  • An organisation account with IBM Watson on Bluemix
  • A Video Turnstile (VT) unit counting people, bicycles or vehicles (contact Urban Sensing for more details)
  • A Node-Red flow to collect the VT data from IBM Watson

Steps to take…

  1. Create an account with IBM Watson
  2. Create a device in the IBM Watson IoT platform
  3. Configure the Node-RED flow to collect data

Step-by-step

  1. Create an account with IBM Watson

    IBM Watson runs on the Bluemix cloud platform and lets you communicate with connected devices on the Internet-of-Things, including our Video Turnstile counters.

    Before you can begin receiving data from the VT counters, you need to create an account with IBM Watson.

    IBM Bluemix

  2. Create a Device Type in IBM Watson IoT platform

    To connect a Video Turnstile counter to the IBM Watson platform, you need to associate it with a device type. (A device type is a group of devices sharing common characteristics.)

    IBM Watson IoT Platform

    • Select your organisation.
    • Add a device – click Devices in the left sidebar

    Add a device 

    • Choose the +Add Device button.

    Create Device Type 

    • Choose Create device type, enter a name and description then click Next (bottom right). Select the options you want to fill in.

    Device Options

    • Click Next and fill in the details.
    • Click Next – you can ignore the optional Metadata in JSON format. Click Create.
    • Choose your newly made Device and click Next.
    • Enter a Device ID – This is the only information that is required. Make a note of the Device ID. (The Device ID is used in the .js program sending data from the VT Loggers to the cloud.)
    • Click Next until you reach the security page.

      You now have two options:

      Auto-generated authentication token
      Allow the service to generate an authentication token for you. The token will be 18 characters long and will contain a mix of alphanumeric characters and symbols. The token will be shown to you at the end of the registration process – make a note of it.

      Self-provided authentication token
      Provide your own authentication token for this device. The token must be between 8 and 36 characters long, and should contain a mix of lower and upper case letters, numbers, and symbols (hyphen, underscore, exclamation-point, ampersand, @ sign, question mark, period, right and left parentheses are permitted). The token should be free of repetition, dictionary words, user names, and other predefined sequences. Make a note of the token.

      Click Next and you are taken to the Add Device page. This gives a summary of the information you have added. If you are happy with it click Add. This registers your device to the organization.

    Device

    • Make a note of these IDs and token as you will need them to access your device and will not be shown the token again. (For example, the .js program which grabs data from the VT Logger and sends it to the cloud uses this Authentication Token.)
    • Click close to go back to the main dashboard.

    Device

    • Click the Refresh button and then double click a device to see its current data.

    Sensor Information
    Here the time, counts of passengers getting onto and off a bus and gps location are shown.

    In future, to connect another VT unit:

    • Select Devices from the left menu.
    • Click the Add Device button.
    • Choose the Device type which you previously created and click Next.
  3. Create a Node-RED flow to collect data from the VT Counting Units

    Node-RED is a programming tool which, amongst other things, lets you create applications to acquire data from hardware devices over the Internet-of-Things. You can run it as an IBM Bluemix application to collect VT count data from the IBM cloud.

    More information about Node Red is at https://nodered.org/.

    • Log in at the Bluemix platform at https://console.bluemix.net/
    • Choose Catalog and search for Node-RED.
    • Choose Node-RED Starter.
    • Type an App name.
    • Click Create. You’re taken to a Cloud Foundry Apps page.
    • Click Visit App URL which is next to the Routes button. (If you get a Not Found error, wait a little longer and then try again.)

    Welcome to your Node-Red Installation 

    • Click Next and you will be asked for a username and password.

    Secure your application 

    • Click Next and you will be invited to browse the available IBM Bluemix nodes. You can click Next without selecting any of these.
    • Finally click Finish

    Finish the configuration of Node-Red 

     Go to Node-Red Flow Editor

    • Click Go to your Node-RED flow editor. You’ll be asked for your username and password. Make a note of the URL so you can quickly return to the flow editor in future.
    • Here is an example of a simple Node Red Flow which extracts counts from the VT unit.

    Node-Red Flow 

    To Create this Node Red Flow:

    • Drag ibmiot input to the Flow area. This node is used with IBM Watson to receive data from the VT units. Double-click to edit its settings to connect with the data.

      Edit ibmiot 

      The Device id is that that you entered when creating a device in IBM Watson – shown in the Devices screen above.

      To see your API keys, log in at https://internetofthings.ibmcloud.com/ and select Apps from the left menu.

      You can generate a new API key and token from here to use if you wish. Make a note of them, especially the token as this will not be shown again.

    • Drag the function node to the workspace and connect it to the output of the ibmiot (drag the mouse between the two to connect). Use this to write the code to extract counts and other data from the VT, as shown below. Double-click the node to bring up the Edit function node box.

      nr-edit-function-node
      This function returns the up counts (people getting on the bus) from a VT Passenger Counter

      The msg.payload property contains the body of the message from the VT logger. 2756 is the VT’s Device ID.

      var jsonMessage = msg.payload;
      var s = jsonMessage['2756'];
      s = s['counts'][0];
      s = s['up'];
      var newmsg = { payload: s};
      return newmsg;
    • To check your function is working properly, connect its output to a debug node. Drag debug from output nodes in the left sidebar. It defaults to msg.payload which is what we want. The debug information will be shown in the tab to the right of the screen.
    • To show your counts on your user interface, go to the dashboard section of the filter nodes in the left sidebar. Choose a display type (we’ve used gauge in our example) and connect it to the output of your function. Edit the settings then in the Dashboard tab click Go To to see what it looks like.
    • Deploy Node-Red.

Join The Discussion