For this use case, we present the Yahoo public weather service as an example of a web service that will be queried by a polling device. This can represent any web service that returns sensor data.
Query the Web Service
These steps query the web service, requesting the humidity, pressure, and temperature in Paris and New York.
- Open the Yahoo development portal in a browser: https://developer.yahoo.com/weather/
- Select JSON for the Response.
Enter the following query into the YQL Query field and click Test.
Each execution of the polling device creates two child devices (one for each city), with the following OMA resources:
Web Service Endpoint
Web Service Response
Create a Model to Poll the Web Service
To create a LoopCloud model to poll the web service:
- Click the company name at the top of the LoopCloud window.
- Click a Project.
- In the navigation panel, select Configuration > Models.
- Select the POLL tab. See also, Model Types.
- Click New Model.
- In the CONFIG tab:
- Enter a Model Name.
- Select a Method: Get.
Enter a Request URL.
Select a Poll Interval: every hour.
- The interval could be set to less than an hour.
- Keep in mind that the Yahoo web service used in this example is a public service, which has usage limits. Yahoo may restrict access if the web service is called too often.
- Click Test to view the JSON response:
- Click Save.
To configure transformation in the LoopCloud Poll Model:
- Select the TRANSFORMATION tab in the Device Model Editor, to configure transformation for the Yahoo weather poll model.
Paste the following Groovy script into the Step 1 window and select a script type of Groovy.
- Click Test.
- Click Save.
Add a Device from the Poll Model
To add a LoopCloud device directly from a Poll Model, see Add a Device from a Model.
The transformation script will autocreate two additional child devices, one for each city in this example.
View Devices and Data
Once the poll has triggered data collection (polling interval was set to one hour), the poll device and two autocreated child devices can be viewed in the Devices list (Device Mgmt > Devices).
In this example:
- Yahoo weather device is the user-created device.
- New York device was autocreated when the Yahoo web service was polled.
- Paris device was autocreated when the Yahoo web service was polled.
View Device Details
- Click the link for the New York device and select the EXPLORE tab to view the web service response.
2. Toggle the switch to view the parsed details:
This parsed view lists all resources from the web service response.
Steps in this example:
- No labels