QUICKSTART

Get started quickly with and overview of the components involved in a typical solutions and practical examples on how to connect a device and how to integrate an external system to the SDS Platform.

Overview

Before starting your project, you need to have a clear understanding of the components involved in your solution. The following questions will help you clarify what you may need.

  1. Devices
    From where are you trying to retrieve information or what device will you send instructions to?
    Common examples are utilities meters, temperature sensors, doors lock/unlock mechanisms, etc.
  2. Connectivity
    Does the device already has connectivity and allows to configure parameters to be sent, or do you need to provide connectivity through a gateway?
  3. SDS Platform: Will you use the platform as the user interface to provide your solution or will you create or use and external system
  4. External System: Will you develop your own external application or are you integrating a 3rd party system?

Connect a Device

In this example we will send a reading from a device to the platform through the Devices API. PHP has been used as scripting language, but you can select the language of your choice.

  1. /*
  2.  
  3. This example sends a numerical measurement (10.5) from sensor
  4. SENSOR001, owned by provider PROVIDER001, identified by token:
  5.  
  6. 79d2dfe9ea9af9dd015befebda62180673314c8abb8898d626c66959448cae0d
  7.  
  8. And then prints the platform server reply.
  9.  
  10. */
  11.  
  12. $providername = 'PROVIDER001';
  13. $sensorname = 'SENSOR001';
  14. $token = '79d2dfe9ea9af9dd015befebda62180673314c8abb8898d626c66959448cae0d';
  15.  
  16. $value = '10.5';
  17.  
  18. $json = '{"observations":[{"value":"'.$value.'"}]}';
  19.  
  20. $api_request_url = '[DEVICES API URL]/data/'.$providername.'/'.$sensorname;
  21.  
  22. $ch = curl_init();
  23. curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  24. curl_setopt($ch, CURLOPT_HEADER, TRUE);
  25. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
  26. curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
  27. curl_setopt($ch, CURLOPT_HTTPHEADER, array('IDENTITY_KEY: '.$token,'Content-Type: application/json'));
  28. curl_setopt($ch, CURLOPT_URL, $api_request_url);
  29.  
  30. $api_response = curl_exec($ch);
  31.  
  32. $api_response_info = curl_getinfo($ch);
  33.  
  34. curl_close($ch);
  35.  
  36. $api_response_header = trim(substr($api_response, 0, $api_response_info['header_size']));
  37.  
  38. echo $api_response_header;

For more examples on devices integration please click here.

Integrate an Application

Let’s read some data from the temperature sensor we have just connected (see “Connect Device”) through the Applications API, and insert into an external database.

  1. /*
  2.  
  3. This example gets the list of raw measurements sent by a temperature sensor, which ID is 5123, from 2016-10-10 00:00:00 UTC to 2016-10-11 00:00:00 UTC.
  4.  
  5. The user who's sending the request is identified by token:
  6.  
  7. 0a2fb1d34c30dab68c6cf36c7218b4b332059e19db35c6fc9f6c56fd30d0223d
  8.  
  9. After the request, it prints the list as a HTML table.
  10.  
  11. */
  12.  
  13. $sensorid = '5123';
  14.  
  15. $begin = '1476057600'; // 2016-10-10 00:00:00 UTC
  16.  
  17. $end = '1476144000'; // 2016-10-11 00:00:00 UTC
  18.  
  19. $apiKey = '0a2fb1d34c30dab68c6cf36c7218b4b332059e19db35c6fc9f6c56fd30d0223d';
  20.  
  21. $api_request_url = 'http://api.smartdatasystem.es/v1/measurements?sensorid='.$sensorid.'&begin='.$begin.'&end='.$end;
  22.  
  23. $ch = curl_init();
  24.  
  25. curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  26.  
  27. curl_setopt($ch, CURLOPT_HEADER, TRUE);
  28.  
  29. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
  30.  
  31. curl_setopt($ch, CURLOPT_HTTPHEADER, array('apiKey: '.$apiKey,'Content-Type: application/json'));
  32.  
  33. curl_setopt($ch, CURLOPT_URL, $api_request_url);
  34.  
  35. $api_response = curl_exec($ch);
  36.  
  37. $api_response_info = curl_getinfo($ch);
  38.  
  39. $results = json_decode(trim(substr($api_response, $api_response_info['header_size'])))->measurements;
  40.  
  41. curl_close($ch);