Tasker is an automation application on the Android platform. It allows actions to be performed based on contexts (application, time, date, location, event, gesture). Therefore connecting an Android device (with Tasker) as a managed device in the IBM Watson IoT Platform, we can create an improvised IoT device that can react to a devices motion, light or GPS sensors for example.
Setup the IBM Watson IoT Platform Service
- In the IBM Bluemix platform dashboard select the CATALOG option in the main banner.
- Select the Internet of Things Platform service and create the service on the subsequent page.
Create the Android Device in the IBM Watson IoT Platform
- Back in the IBM Bluemix platform dashboard.
- Click the Internet of Things Platform entry in the Services section which was setup in the previous step.
- You will be presented with three main options, click Launch Dashboard.
- Now shown will be the device management page titled with your Organization ID. Click the DEVICES tab to show the currently managed IoT devices.
- Click the Add Device button to begin entering details about the Android device.
- Click Create device type. Enter the name of the device and give it a description. In this example we will use “Android_IoT_Device” as the name. Then click Next.
- In the Define Template step. The description attributes are all optional, select the attributes which you would use to define the device.
- The subsequent steps allows the input of the optional attributes, continue until the Create button is presented. Then click this button to create the device type.
- The device type will be created and the Add Device page is presented. Select the device type created in the previous step in the drop down and click Next to begin creating the device.
- The Device Info page is now presented. Enter the Device ID and click “Next”. In this example we will use “AndroidTasker”.
- Click Next until the Security page is presented. In this example we will use an auto-generated token by simply clicking Next.
- A Summary Page is now presented to show the device details. Click Add to create the new device.
- The next page displayed shows the device credentials, make a note of these settings they will be required when setting up the Android device.
Setting up your Android Device
Creating your first Tasker profile
In this tutorial we will create a Tasker profile which waits for the phone to be shaken. Once this is detected, it actions the task which sends the MQTT message to the IBM Watson IoT Platform. Beyond this example, any of the other sensors on the phone could be polled or even listen for message, network or application activity.
- Launch Tasker application on the Android Device.
- Ensure that the Profiles Tab is selected and click the “+” button on the bottom right to start creating the first profile.
- In the popup of available profile events, click the Event option.
- In the Select Event Category dialog select Sensor.
- Then select Shake in the Select Sensor Event dialog.
- Then the Event Edit page should now be presented. Click the back arrow on the top left to create the profile. Once the new profile is created, you can then associate an existing task or create a new task.
Creating your first Tasker task
Once we have a profile created, the next step is to create a task, which contains the action to communicate with the IBM Watson IoT Platform.
Using the MQTT plugin, generate the message which is understood by the IBM Watson IoT Platform.
- Select New Task which will create a new task for the current profile.
- Give the New Task a name. In this example I have called it “IoT Foundation” .
- You will be presented with the Action page. Click the “+” at the bottom.
- In the Select Action Category dialog, select Plugin.
- In the Action Plugin dialog, select MQTT Publisher.
- You will now be presented with the Action Edit page for the MQTT publisher, click the pencil icon to configure the MQTT message to be sent.
- The MQTT details are configured as follows (See MQTT protocol reference). At this stage you will need the device credential details which were obtained when registering the device in the IBM Watson IoT Platform.
- Server Address : <Organisation ID>.messaging.internetofthings.ibmcloud.com
- Port: 1883
- Client ID: d.<Organization ID>:<Device Type>:<Device ID>
- SSL/TLS: Unchecked
- Username: “use-token-auth”
- Password: Authentication Token
- Topic: iot-2/evt/<event name>/fmt/<format>
- Payload: In the example I send a single value with the value of a Tasker variable “%VAR”. This is set to “Hello” in Tasker, but shows the possibility for sending programmatic datapoint values.
- QOS: 0
- Retain Flag: Unchecked
- Click Accept once all details have been entered.
- On the Action Edit page, click the top left back arrow to save the task.
Verifying the connection with IBM Watson IoT Platform
- Navigate to the IBM Watson IoT Platform dashboard
- At the IBM Bluemix dashboard click on the IBM Watson IoT Platform Service
- or navigate directly via https://<OrganizationID>.internetofthings.ibmcloud.com/dashboard
- Click on the DEVICES tab to show the list of registered devices.
- Click on the “AndroidTasker” device from the list to show device details.
- On this page pay attention to the Recent Event and Sensor Information sections.
- Shake the Android device to activate the messaging task.
- If the message received by the IBM Watson IoT Platform is correctly formatted and authenticated, the Recent Events and Sensor Information will start to be populated, confirming a valid connection.
- Navigate to the IBM Watson IoT Platform dashboard
Once you have connected an Android IoT device, have a try of the “Internet Of Things Platform Starter” Boilerplate in the IBM Bluemix catalog.
See how the managed Android IoT device can be wired up using Node-RED in Bluemix.