- Sign up for an IBM Cloud account.
- Download the IBM Cloud CLI.
- Download/clone the github folder.
- In the application folder, copy the .env.example file and create a file called .env
cp .env.example .env
- Navigate to catalog and search for iot platfrom starter kit.
- Enter a name for your application. Because this name is also used as the host name, it must be unique within the IBM Cloud.
- Click Create.
- After your app is created, in the left pane, click Overview. Notice that your app contains two connections, one to a Cloudant NoSQL database and another to an Internet of Things Platform service
- In the Overview view of your app, under Connections, click the Internet of Things Platform service.
- Click Launch to open the Watson IoT Platform dashboard
- The IBM Watson IoT Platform dashboard is displayed, which is a service that is independent of the IBM Cloud. An organization ID is assigned to your app, and you will need this ID later when developing the app.
- On the left menu, which pops out when you hover over it, click on Apps.
- Create an API key for standard application, copy the authentication key and token and paste it in the env file as shown below.
IOT_PLATFORM_ORG={your_organisation_id}
IOT_AUTH_KEY={iot_platform_authentication_key}
IOT_AUTH_TOKEN={iot_platform_authntication_token}
- On the left menu, which pops out when you hover over it, click Devices. Then, click Add a device type. In your organization, you can have multiple device types each with multiple devices. A device type is a group of devices that share characteristics; for example, they might provide the same sensor data. In our case, the device type name must be “Android” (this device type name is required by the app that you will use later). Enter the device ID. The device ID can be, for example, the MAC address of your smartphone. However, it must be unique within your organization only. For this application keep it '1234M'. Make note of the authorization token.
- Click Next. A page is displayed where you can enter metadata about the device type, such as a serial number or model. You don’t need to specify this information for this demo. Just click Done.
- Provide a value for the authentication token or auto-generate it. Then, click Next.
- Create a device similarly with device type as Temperature and id as '1234T' which we will use for simulation of temperature.
- Create anoter device with device type as Light and Door and id as '1234L' and '1234D' respectively to be used to control the smart lights through the app.
- On the left menu, click Settings and activate Device Simulator to be used by the app.
- You will see a tab for simulation on the bottom right. Click on that.
- Click on new simulation.
- Select the device type that we created before for temperature
- Schedule the event based on your preference.
- Add a payload to simulate temperature as follows
{
"randomNumber": random(20, 50)
}
- Click save.
- Click use regsitered device and select the device id. In this case it will be '1234T'
- You should be able to see the published events under the device type.
- Navigate to the catalog and search for Visual Recognition under watson services.
- Create an instance of the same.
- On the left menu, navigate to service credentials and create new credentials.
- copy the apikey and paste it in the env file for the visual recognition server as shown below
VISUAL_RECOGNITION_IAM_APIKEY={your_visual_recognition_key}
In this section, you will enhance your IBM Cloud IoT app by using a Node-RED flow to process messages from the devices and then visualize it on a dashboard.
- Open your IBM Cloud dashboard
- In your IBM Cloud dashboard, verify that your IBM Cloud IoT app is up and running.
- In a browser, open .mybluemix.net, where is the name for your IoT app. Follow the wizard steps to set a user name and password for the Node-RED editor.
- On the Node-RED page for your IoT app, click Go to your Node-RED flow editor. The editor opens, containing a sample flow.
- Using the drag-and-drop features of this editor, you can plug together a flow of messages. Although you can create your own flow here, we will import the code below. But first, select all existing nodes, and delete them by pressing the Delete key.
- Click on the settings icon on the top right corner.
- Click on Manage Pallete and then Install.
- Search for node-red-dashboard and install it.
- Download the text file (nodeRedCode.txt) from the githib folder.
- Open the file in a text editor. Make sure that all the code is on a single line. Remove any line breaks. Copy the line of code.
- In the Node-RED editor, press Ctrl-I to open the Import Nodes dialog. Paste the code, and click OK.
- Double click on the IBM IOT App In and make sure the autehentication is set to bluemix service and configure it to listen from all types of device for all events.
- Double click on the IBM IOT and make sure the autehentication is set to bluemix service.
- Click Deploy in the flow editor. The flow is deployed and should be active immediately.
- Click on the dashboard icon placed just below the Deploy button.
- Click on the new tab icon and you will see the dashboard opening up in a new tab.
- You will see the temperature data being visualized using the guage.
-
Install the dependencies
npm install -
Run the application
npm start -
View the application in a browser at
localhost:8080
-
On your phone, go to Settings > Security. Under Device Administration, enable Unknown sources. Now you can install .apk files from outside of Google Play.
-
Open the browser on your phone, and enter this URL:
-
Search for the iotstarter-v2.1.0.apk link, and click the link to download the .apk file. Click the downloaded file, and confirm that you want to install the app.
-
Start the IoT Starter app.
-
Click Skip tutorial.
-
Enter the following parameters: Organization: The organization ID that was displayed on the IBM IoT server (at the start of ” “). For example, mgso1i in this tutorial. Device ID: The device ID that you configured, at the end of ” .” For example, “112233445566” in this tutorial. Auth Token: The authorization token that you specified in ” .” Check Use SSL.
-
Click Activate Sensor. Now the app collects data from the acceleration sensor in your smartphone and sends the data to the IBM IoT server
-
Login to IBM Cloud with the IBM Cloud CLI.
ibmcloud login -
Target a Cloud Foundry organization and space.
ibmcloud target --cf -
Edit the manifest.yml file. Change the name field to something unique.
For example,- name: my-app-name. -
Deploy the application.
ibmcloud cf push -
View the application online at the app URL on a pc.
For example: https://my-app-name.mybluemix.net -
The front camera will take picture every 15 seconds and if a person is detected, you will be notified on your node red dashboard. You can use the switch on the dashboard to send commands to the pc to switch on/off the lights.