Smart Trash Can Powered by IBM Bluemix
This is the accompanying repository for the this blog post.
In order to make the communication work between the Trash can Hardware and mobile app, we will need to setup and configure the IBM IoT service as per our application needs. Follow along the steps given below to launch your IBM IoT service instance. If you do not yet have an IBM Id, this is the time to create one and get started.
Login to your IBM Bluemix account.
Step 2: Launch the Service
Click on the “IBM Internet of Things Platform” service icon to launch the service. Specify the service parameters
2.Connect to (You can specify an existing Application name to connect this service application in Bluemix or you can make it Leave unbound if you dont want to connect) 3.Selected Plan as shown below, and click on “CREATE” button(on the right side panel).
Step 3: Launch the service dashboard
Once created, a welcome screen will be displayed for your newly launched service. Scroll down on the welcome page and you will be able to locate a button “Launch Dashboard” under the “Connect your devices” section.
Step 4: Access the device profiles page on the service dashboard
To use this service with IOT devices, we must create the device profiles first. As described in the blog, we have two devices, the raspberry pi that is connected with the ultrasonic sensor mounted on top of the trash can and the mobile app. So to facilitate communication between the two devices, we will create a device profile for each. In the dashboard page, hover your mouse to left side menu to expand and bring it up.
Step 5 : Create device profile for the trash can
Click on the “Next” button on the bottom right corner of the “Create Device Type” dialog to move through the steps. All the subsequent steps are optional and can be skipped. Finally, the device type will be created and listed under the “Device Types” tab panel.
Step 6: Create device profile for the mobile app
Step 7: Create device instances
We now have the device types defined in the service. The next thing is to define the actual device itself which acts as a virtual identifier (device id) for every device instance that is going to access the service. In our case, we have the raspberry pi and the mobile app as our two device instances.
So lets go ahead and add them by clicking on the “Add Device” button under the “Browse” tab of “Devices” section in the dashboard. Lets create the device,by selecting a device type "Trashcan" And,assign a unique name to the device,Device in this case. Note: Just like in the case of adding device types, we can ignore the other steps in creating device and hit Next until we reach the end of “Add Device” dialog.
Note: Make a note of the Organization ID displayed in the "Your Device Credentials" Section of "Add Device" dialog.This will be required for programming the device SDKS
Step 8: Generate API Key and Auth Token
Now that all the devices are created , we need to generate the API key and auth token to access the IBM IOT service from our end point devices.
For this, go to the “APPS” sub-menu
You will see the API key and Auth token being displayed on a dialog. Make a note of these parameters.
Click “Finish” on the lower right corner of the dalog to return back to the “API Keys” tab and you can now see your newly generated API credentials listed over there.
Note:Make sure that you make a note of the API key & authentication token displayed on the screen for your device instance. This token will be used to program the application software later
#DEVICE SETUP step 1: Power On the raspberry.
step 2: Clone this repository Trashcan
[Trashcan Git Repo](https://github.com/rajeevbrahma/Trashcan.git)
step 3 : Install Dependency modules ibmiotf and twilio by doing
sudo pip install ibmiotf
sudo pip install twilio
##Python Script Configuration
You will have to add some configuration settings to make the application work with IBM IoT platform service and Twilio messaging. These configurations are to be done as variables, which are already defined in the trash can's application code under Trashcan.py
Edit the variables in the following lines as follows Variable name Line no. Description
account_sid 23 Twilio account SID auth_token 24 Twilio account authToken twilionumber 29 Twilio Number ( Your Twilio subscribed number) receivernumber 30 Twilio verified number (where you want to receive the SMS notifications). Should have country code, for example +18458892405 organization 174 IBM account organization ID authKey 179 Generated API key authToken 180 Generated Authentication token
#Mobile App Configuration
The IBM IoT platform configurations has to be done in the mobile app as well, since the mobile app is also registered as a device instance for receiving the readings published by the trash can.
Edit the line numbers in index.js
Variable Name Line no. Description
org 55 IBM account organization ID auth-key 60 Generated API key auth-token 61 Generated authentication token
##Steps to Build the Mobile App
For building the mobile app, please refer to the official Cordova & Android documentation to setup the build dependencies. You will have to setup a build system with the dependencies, primarily the NodeJS, Java and Ant among others.
Follow the steps below to build the APK file for the mobile app. All these steps are to be performed on the build system. These steps have been verified on a build system with Ubuntu mate OS along with Android version 23 & Cordova 6.3.0
Step 1: Clone this repository and run the following commands from within the repository to pull the submodules from https://github.com/ibm-watson-iot/iot-nodejs to get the nodejs sdk for the IBM IoT platform.
git submodule init git submodule update
Step 2: Add the android platform by executing this command in the terminal under the app root folder ( TrashCanApp)
cordova platform add android
Step 3: In the config.xml file in the root folder change the name of the app to the name you want. This is optional step. By default the app name is "Trash Can"
Step 4: Build the app by executing the following command in the terminal in the root folder of the cordova app
cordova build android
Step 5: Once build is successful, you can find the generated apk file in the following path relative to the cordova project root directory.