Registering the iotsensor with Watson IoT Platform
Before you can receive events and datapoints from the sensor, your must register it with Watson IoT Platform by following these steps. This step is only required the first time that your follow this recipe.
- In your Watson IoT Platform dashboard, select Devices from the menu pane, then click Add Device in the upper-right.
- Click Create device type. Creating a device type will make it easier to find and identify the iotsensor device after connecting it.
- Enter iotsensor_device as the device type name then click Next and then click Create.
- Click Next.
- Enter iotsensor as the device ID.
- Click Next.
- Provide an authentication token, or accept an automatically generated token. Providing a memorable authentication token may be useful for recalling it later, for example “MyDevice”.
- Verify that the summary information shown is correct and then click Add.
- In the device information page, copy and save the following device information
- Organization ID
- Device Type
- Device ID
- Authentication method
- Authentication token
Connect the iotsensor to the Watson IoT Platform
This step connects the iotsensor to the registered device in your Watson IoT Platform organization.
- Go to: http://watson-iot-sensor-simulator.mybluemix.net/
- When prompted, enter the device information to connect to Watson IoT Platform.
- Verify that the connecting message changes to the name of your device, i.e. iotsensor. The device is now connected to Watson IoT Platform.
- In the Device browse dashboard, click your device and verify that data is being received.
Optional step: Create a board and some cards
At this point, you can create a board and some cards from your Watson IoT Platform dashboard. Boards and cards can be used to keep track of device data, for example the temperature, humidity and object temperature data being sent by the iotsensor. To set up a new board follow these steps.
- In your Watson IoT Platform dashboard click Create New Board in the upper right.
- Give the board a name and description.
- Click Next then Create.
- Click on the board you have just created.
- Click Add New Card in the upper right.
- Select the style of visualization, and select the iotsensor as the data source.
Create an iotsensor_device Schema
To be able to create rules that are triggered based on the datapoints from your device properties, you must first map these properties in a device type schema.
- In the Watson IoT Platform dashboard, select Devices from the menu pane, then select Manage Schemas.
- Click Add Schema.
- In the Add a schema editor, select the iotsensor_device device type and click Next.
- Click Add property.
- Selected the From Connected tab.
- Select the following properties:
- Click OK to save the schema.
Create iotsensor rules and actions
This step creates the rules and actions which will trigger based on data from the iotsensor.
- In the Watson IoT Platform dashboard select Rules from the menu pane then click Create Cloud Rule.
- Click Create A Rule.
- Name the rule Temp too high.
- Select the iotsensor_device device type and then click Next.
- In the rule builder, click New Condition rule block to edit it.
- Select the temperature property and enter 21 as the static value to compare to.
- Click OK to save the condition.
- Click the New Action block.
- In the Set The Action dialog, click Add action.
- Add the email action and click OK.
Activate the rule and send some data to test the rule
- In the Rules browser, activate the Temp too high rule.
- Open the iotsensor at http://watson-iot-sensor-simulator.mybluemix.net/ Note: If you are starting a new session, you must reconnect by using the same credentials as in step 2.
- Use the up arrow to raise the temperature to 22 degrees.
View the dashboard alert and the email alert
- In the Watson IoT Platform dashboard select Boards from the menu pane, the select the Rule-centric Analytics card to open it.
- The rule is now included in the Rules I Manage card and alerts from this rule will appear in the Rule Alerts card.
- Select an alert instance to see the alert details, the triggering condition, the property datapoints at the time the rule was triggered, and the action that was taken.
- Go to your email client to verify that the alert was sent as an email as expected.