Giter Club home page Giter Club logo

ibm / guide-conveyor-simulator Goto Github PK

View Code? Open in Web Editor NEW
14.0 13.0 24.0 2.23 MB

# WARNING: This repository is no longer maintained :warning: This content is no longer being updated or maintained. The content is provided “as is.” Given the rapid evolution of technology, some content, steps, or illustrations may have changed.

Home Page: https://developer.ibm.com/code/patterns/build-monitor-iot-driven-conveyor-belt

License: Apache License 2.0

JavaScript 47.84% CSS 20.24% HTML 31.92%
iot iot-platform watson-iot-platform raspberry-pi nodejs ibmcode

guide-conveyor-simulator's Introduction

WARNING: This repository is no longer maintained ⚠️

This content is no longer being updated or maintained. The content is provided “as is.” Given the rapid evolution of technology, some content, steps, or illustrations may have changed.

Skill Level: Beginner
N.B: All services used in this repo are Lite plans.

Create a basic conveyor belt with an IoT device that sends monitoring data to Watson IoT Platform on IBM Cloud

Overview and goal

This guide steps you through the process of connecting devices to Watson IoT Platform, monitoring and acting on device data

We set up a connected conveyor belt and use it to send IoT data to Watson IoT Platform. Depending on your skill level, you can follow one or both of the following paths to set up your conveyor belt:

As part of this guide, you will:

  1. Create and deploy a Watson IoT Platform organization by using Cloud Foundry CLI.
  2. Build and deploy a sample conveyor belt device.
  3. Connect the simulated conveyor belt device to Watson IoT Platform.
  4. Monitor and visualize device data by using the Watson IoT Platform dashboards.

To get started with Watson IoT Platform using a different IoT device, see the Getting started tutorial.

Architecture Diagram

  1. Create & Deploy Watson IoT Platform on IBM Cloud
  2. Build & Deploy Simulated Sample Conveyor
  3. Connect the conveyor belt to the Watson IoT Platform
  4. Monitor & Visualize device data on the Watson IoT dashboard.

Click here to view the IBM Pattern for this project.

Prerequisites

You will need the following accounts and tools:

  • IBM Cloud account
  • Bluemix CLI
  • Optional: Git If you choose to use Git to download the code samples you must also have a GitHub.com account. You can also download the code as a compressed file without a GitHub.com account.
  • Optional: A mobile phone on which to run the Conveyor belt sample web application to send accelerometer data.

Deploy to IBM Cloud

If you want to deploy directly to IBM Cloud, click on Deploy to IBM Cloud button below to create a IBM Cloud DevOps service toolchain and pipeline for deploying basic conveyor belt with an IoT device that sends monitoring data to Watson IoT Platform on IBM Cloud, else jump to Steps

Deploy to IBM Cloud

After deploying the application, please continue with Step 3 - See raw data in Watson IoT Platform.

Steps

  1. Deploy Watson IoT Platform

  2. Do one of the following 2 steps:

    2a. Deploy the sample conveyor belt web application

    2b. Build a Raspberry Pi-powered conveyor belt

  3. See raw data in Watson IoT Platform

  4. Visualize live data in Watson IoT Platform

Step 1 - Deploy Watson IoT Platform

Watson IoT Platform provides powerful application access to IoT devices and data to help you rapidly compose analytics applications, visualization dashboards, and mobile IoT apps. The steps that follow will deploy an instance of the Watson IoT Platform service with the name iotp-for-conveyor in your IBM Cloud environment. If you already have a service instance running, you can use that instance with the guide and skip this first step. Just make sure that you use the correct service name and IBM Cloud space when you proceed through the guides.

  1. From the command line, set your API endpoint by running the bx api command.
    Replace the API-ENDPOINT value with the API endpoint for your region.
bx api <API-ENDPOINT>

Example: bx api https://api.ng.bluemix.net

Region API Endpoint
US South https://api.ng.bluemix.net
United Kingdom https://api.eu-gb.bluemix.net
  1. Log into your IBM Cloud account.
bx login

If prompted, select the organization and space where you want to deploy Watson IoT Platform and the sample app. Note example a) org: [email protected] b) space = dev

  1. Deploy the Watson IoT Platform service to IBM Cloud.
bx create-service iotf-service iotf-service-free YOUR_IOT_PLATFORM_NAME

For YOUR_IOT_PLATFORM_NAME, use iotp-for-conveyor.
Example: bx create-service iotf-service iotf-service-free iotp-for-conveyor

Next, you will create a sample conveyor belt device. Choose which path you want to take:

Step 2A - Deploy the sample conveyor belt web application

The sample app lets you simulate a IBM Cloud connected industrial conveyor belt. You can start and stop the belt and adjust the speed of the belt. Every change to the belt is sent to IBM Cloud in the form of an MQTT message that is displayed in the app. You can monitor the belt behavior by using the default dashboard cards. The sample app is built using the Node.js client libraries at: https://github.com/ibm-watson-iot/iot-nodejs

Conveyor belt app

  • From the guide-conveyor-simulator directory, push your app to IBM Cloud and give it a new name by replacing YOUR_APP_NAME in the bx push command. Use the --no-start option because you will start the app in the next stage after it is bound to Watson IoT Platform.

Note: Deploying your application can take a few minutes.

bx app push YOUR_APP_NAME --no-start
  • In the guide-conveyor-simulator directory, bind your app to your instance of the Watson IoT Platform by using the names that you provided for each.
bx bind-service YOUR_APP_NAME iotp-for-conveyor

For more information about binding applications, see Connecting applications.

  • Start your application for the binding to take effect.
bx start YOUR_APP_NAME

At this stage, your sample web application is deployed on IBM Cloud. When deployment is completed, a message is displayed to indicate that your app is running. Example:

name:              YOUR_APP_NAME
requested state:   started
instances:         1/1
usage:             64M x 1 instances
routes:            YOUR_APP_NAM.mybluemix.net
last uploaded:     Tue 09 May 09:29:49 EDT 2017
stack:             cflinuxfs2
buildpack:         SDK for Node.js(TM) (ibm-node.js-4.8.0,
                   buildpack-v3.11-20170303-1144)
start command:     ./vendor/initial_startup.rb

     state     since                  cpu    memory         disk            details
#0   running   2017-05-09T13:35:08Z   0.0%   19.6M of 64M   66.2M of 256M

Troubleshoot errors in the deployment process by using the bx app logs YOUR_APP_NAME --recent command.

  • In a browser, access the app.
    Open the following URL: https://YOUR_APP_NAME.mybluemix.net
    Example: https://conveyorbelt.mybluemix.net/.

  • Enter a device ID and token for your device.
    The sample app automatically registers a device of type iot-conveyor-belt with the device ID (e.g. my-first-device) and token that you provided. For more information about registering devices, see Connecting devices.

  1. Continue with Step 3 - See raw data in Watson IoT Platform.

Step 2B - Build a Raspberry Pi-powered conveyor belt

The Raspberry Pi solution is built using the Python client libraries at: https://github.com/ibm-watson-iot/iot-python

Schematic diagram for the circuit

Circuit Diagram

Required connections

The following connections between the Raspberry Pi and the L298N Dual H Bridge Motor Driver Board are required. Connect:

  • Pin 2 of the Raspberry Pi to +5v on the L298N board
  • Pin 6 of the Raspberry Pi to GND on the L298N board
  • Pin 13 of the Raspberry Pi to the IN1 of the L298N board
  • Pin 15 of the Raspberry Pi to the IN2 of the L298N board
  • +9v of the battery to +12v on the L298N board
  • -9v of the battery to GND on the L298N board
  • The +ve node of the motor to OUT1 on the L298N board
  • The -ve node of the motor to OUT2 on the L298N board

Hardware requirements

  1. Raspberry Pi(2/3) with Raspbian Jessie (8.x).
  2. L298N Dual H Bridge Motor Driver Board
  3. 9V DC motor
  4. 9V Battery

Raspberry Pi software requirements

  • Python 2.7.9 and above, installed with Raspbian Jessie (8.x).
  • Watson IoT Python library
  • Optional: Git.
    If you do not have git installed on your Raspberry Pi, you can install it by using the following command:
$ sudo apt-get install git

Detailed steps

  1. Open the terminal or SSH to your Raspberry Pi.
  2. Use your favorite git tool to clone the following repository to your Raspberry Pi:
    https://github.com/ibm-watson-iot/guide-conveyor-rasp-pi In Git Shell, use the following command:
$ git clone https://github.com/ibm-watson-iot/guide-conveyor-rasp-pi
  1. Register the device with Watson IoT Platform. For more information about registering devices, see Connecting devices.

    • In the IBM console, click Launch other Watson IoT Platform service details page. The Watson IoT Platform web console opens in a new browser tab at the following URL:
      https://ORG_ID.internetofthings.ibmcloud.com/dashboard/#/overview
      
      Where ORG_ID is the unique six character ID of your Watson IoT Platform organization.
    • In the Overview dashboard, from the menu pane, select Devices and then click Add Device.
    • Create a device type for the device that you are adding.
      • Click Create device type.
      • Enter the device type name iotp-for-conveyor and a description for the device type.

    Note: You can enter any device type name, but the other guides in the series expect devices that use the device type iotp-for-conveyor. If you use a different device type, you must modify the settings in the other guides accordingly.

      - Optional: Enter device type attributes and metadata.
    
    • Click Next to begin the process of adding your device with the selected device type.
    • Enter a device ID, for example, conveyor_belt.
    • Click Next to complete the process.
    • Provide an authentication token or accept an automatically generated token.
    • Verify the summary information is correct and then click Add to add the connection.
    • In the device information page, copy and save the following details:
      • Organization ID
      • Device Type
      • Device ID
      • Authentication Method
      • Authentication Token. You'll need the values for the Organization ID, Device Type, Device ID, and Authentication Token to configure your device to connect to Watson IoT Platform.
  2. Navigate to the guide-conveyor-rasp-pi root of the cloned repository.

  3. Make the shell script executable by using this command sudo chmod +x setup.sh

  4. Run the setup.sh file and enter the details that you copied from the device information page when prompted.

./setup.sh
  1. Run the deviceClient program.
    When you run the program, your Raspberry Pi starts the motor and it will run for up to 2 minutes based on parameter settings.
python deviceClient.py -t 2

While the motor is running, the program publishes events of event type sensorData that have the following sample payload structure:

{
"d": {
  "elapsed": 1,
  "running": true,
  "temperature": 35.00,
  "ay": "0.00",
  "rpm": "0.6"
}
}
  1. Continue with Step 3 - See raw data in Watson IoT Platform.

Step 3 - See raw data in Watson IoT Platform

  1. Verify that the device is registered with Watson IoT Platform.

    • Login to your IBM dashboard at: https://bluemix.net
    • From your list of services, click the iotp-for-conveyor Watson IoT Platform service.
    • Click Launch to open the Watson IoT Platform dashboard in a new browser tab.
      You can bookmark the URL for easy access later.
      Example: https://*iot-org-id*.internetofthings.ibmcloud.com.
    • From the menu, select Devices and verify that your new device is displayed.
  2. View raw data

    • From the menu, select Boards.
    • Select the Device Centric Analytics board.
    • Locate the Devices I Care About card and select your device.
      The device name is displayed in the Device Properties card.
  3. Send sensor data to the platform.
    The device sends data to Watson IoT Platform when sensor readings change. You can simulate this data sending by stopping, starting or changing the speed of the conveyor belt.

Path A: If you are accessing the app on a mobile browser, try shaking your smart phone to trigger accelerometer data for the conveyor belt.

  1. Verify that the updated device data points that correspond to the published message are displayed in the Device Properties card.
    Message example A:
{
  "d": {
      "id": "belt1",
      "ts": 1494341288662,
      "ay": "0.00",
      "running": true,
      "rpm": "0.6"
  }
}

Message example B:

{
  "d": {
  "elapsed": 1,
  "running": true,
  "temperature": 35.00,
  "ay": "0.00",
  "rpm": "0.6"
}
}

Step 4 - Visualize live data in Watson IoT Platform

To create a dashboard card to see live conveyor belt data:

  1. On the same Device Centric Analytics board, click Add New Card and then select Line Chart.
  2. For card source data, click Cards.
    A list of card names is displayed.
  3. Select Devices I Care About and then click Next.
  4. Click Connect new data set and enter the following values for the data set parameters:
    • Event: sensorData
    • Property: d.rpm
    • Name: Belt RPM
    • Type: Float
    • Unit: rpm
  5. Click Next.
  6. On the card preview page, select L, and then click Next.
  7. On the card information page, change the name of the title to Belt data and then click Submit.
  8. Change the speed of your belt to see live data in your new card.
  9. Optional: Add a second data set to add acceleration data for the belt.

If you use your phone to connect to the sample app, you can shake the phone to send acceleration data for the belt.

  1. Click the menu icon on your card and select to edit the card.
  2. For card source data, select Cards.
  3. Select Devices I Care About and click Next.
  4. Click Connect new data set and enter the following values:
    • Event: sensorData
    • Property: d.ay
    • Name: Accel. Y
    • Type: Float
    • Unit: gs
  5. Click Next.
  6. Path A only: Shake your phone to see the live accelerometer data in your new card. For more information about creating boards and cards, see Visualizing real-time data by using boards and cards.

Useful links

Learn more

  • Artificial Intelligence Code Patterns: Enjoyed this Code Pattern? Check out our other AI Code Patterns.
  • Data Analytics Code Patterns: Enjoyed this Code Pattern? Check out our other Data Analytics Code Patterns
  • AI and Data Code Pattern Playlist: Bookmark our playlist with all of our Code Pattern videos
  • With Watson: Want to take your Watson app to the next level? Looking to utilize Watson Brand assets? Join the With Watson program to leverage exclusive brand, marketing, and tech resources to amplify and accelerate your Watson embedded commercial solution.
  • Watson Studios: Master the art of data science with IBM's Watson Studios
  • PowerAI: Get started or get scaling, faster, with a software distribution for machine learning running on the Enterprise Platform for AI: IBM Power Systems
  • Spark on IBM Cloud: Need a Spark cluster? Create up to 30 Spark executors on IBM Cloud with our Spark service
  • Kubernetes on IBM Cloud: Deliver your apps with the combined the power of Kubernetes and Docker on IBM Cloud

License

This code pattern is licensed under the Apache Software License, Version 2. Separate third party code objects invoked within this code pattern are licensed by their respective providers pursuant to their own separate licenses. Contributions are subject to the Developer Certificate of Origin, Version 1.1 (DCO) and the Apache Software License, Version 2.

Apache Software License (ASL) FAQ

guide-conveyor-simulator's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

guide-conveyor-simulator's Issues

Deploy to IBM Cloud button is broken.

Hello.
Deploy to IBM Cloud button is broken.

Steps to recreate:
Press button 'Deploy to IBM Cloud'.

Expected:
Deployment to IBM Cloud started

Actual:
Error message: Page not found.

remove unmaintained tracker code

The metrics tracker project is no longer maintained.

Remove the following:

  • Badge at top of README
  • Privacy Notice from Readme
  • Disabling Deployment Tracking from Readme
  • Use of metric tracker in app, i.e. require('metrics-tracker-client').track();
  • The metrics-tracker library from requirement.txt or package.json
  • The repository.yml file at the app level

Update the deploy to ibm cloud button to use this image: https://bluemix.net/deploy/button.png

See https://github.com/IBM/watson-conversation-slots-intro/pull/71/files as an example

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.