2016-09-30 14 views

答えて

0
<?php 
$auth_token=$_REQUEST['auth_token']; 
//$email=$_REQUEST['email']; 
//$password=$_REQUEST['password']; 
//$url = "https://api.datonis.io/api_sign_in?email=$email&&password=$password"; 

// The data to send to the API 
$postData = array(
      'thing_key'=>'6f2159f998', 
      //'time_grouping'=>'hour', 
      //'idle_time_required'=>'true', 
      'from'=>'2016/08/29 16:55:00', 
      'to'=>'2016/08/29 17:05:00', 
      'time_zone'=>'Asia/Calcutta', 
      //'time_format'=>'int', 
      'per'=>200, 
      //'page'=>1, 
      'metrics'=>['1st data'], 

); 

// Setup cURL 
$ch = curl_init('https://api.datonis.io/api/v3/datonis_query/thing_data'); 
curl_setopt_array($ch, array(
    CURLOPT_POST => TRUE, 
    CURLOPT_RETURNTRANSFER => TRUE, 

    CURLOPT_HTTPHEADER => array(
      'X-Auth-Token:'.$auth_token, 
      'Content-Type:application/json', 
    ), 
    CURLOPT_POSTFIELDS => json_encode($postData) 

)); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
// Send the request 
$response = curl_exec($ch); 

// Check for errors 
if($response === FALSE){ 
    die(curl_error($ch)); 
} 

// Decode the response 


//print_r ($response); 

$responseData = json_decode($response); 
//print_r($responseData); 
// Print the date from the response 
var_dump($response); 
$thing_val='6f2159f998'; 
$stdata='1st data'; 
$timestamp='timestamp'; 
//$x=0; 
//for ($x = 0; $x <= 5; $x++) 
//{ 

//$result1 = ($responseData->$thing_val->event_data[$x]->data->$stdata); 
//$result2 = ($responseData->$thing_val->event_data[$x]->timestamp); 
//echo $result1."<br>"; 
//echo $result2."<br>"; 
//} 

?> 

<html> 
<head> 
<!-- 
<script src="/canvasjs.min.js"></script> 
<script type="text/javascript"> 

window.onload = function() { 
    var chart = new CanvasJS.Chart("chartContainer", { 
     theme: "theme2",//theme1 
     title:{ 
      text: "Basic Column Chart - CanvasJS"    
     }, 
     animationEnabled: false, // change to true 
     data: [    
     { 
      // Change type to "bar", "area", "spline", "pie",etc. 
      type: "column", 
      dataPoints: [ 
       <?php $x=0; 
for ($x = 0; $x <= 10; $x++) 
{ 

$result1 = ($responseData->$thing_val->event_data[$x]->data->$stdata); 
$result2 = ($responseData->$thing_val->event_data[$x]->timestamp); 
echo "{ label: '/".$result2."/', "; 
echo "y: ".$result1. "},"; 

} 
?> 
0

同様の結果は、次のプログラム

package IOT; 

import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStreamReader; 
import java.io.OutputStream; 
import java.net.HttpURLConnection; 
import java.net.MalformedURLException; 
import java.net.URL; 

import com.google.gson.Gson; 
import com.google.gson.GsonBuilder; 
import com.google.gson.JsonElement; 
import com.google.gson.JsonParser; 

import org.json.*; 




public class NetClientPost { 

    // http://localhost:8080/RESTfulExample/json/product/post 
    public static void main(String[] args) { 

     try { 

     URL url = new URL("https://api.datonis.io/api/v2/datonis_query/sensor_event_raw_data"); 
     HttpURLConnection conn = (HttpURLConnection) url.openConnection(); 
     conn.setDoOutput(true); 
     conn.setRequestMethod("POST"); 
     conn.setRequestProperty("Content-Type", "application/json"); 
     conn.setRequestProperty("X-Auth-Token", "BTydXutd1pF2yCaMvFsezw"); 

     String input = "{\"sensor_key\":\"6f2159f998\",\"from\":\"2016/08/29 16:55:00\",\"to\":\"2016/08/29 17:05:00\",\"time_zone\":\"Mumbai\",\"per\":20,\"metrics\":\"1st Data\"}"; 

     OutputStream os = conn.getOutputStream(); 
     os.write(input.getBytes()); 
     os.flush(); 

     //if (conn.getResponseCode() != HttpURLConnection.HTTP_CREATED) { 
      //throw new RuntimeException("Failed : HTTP error code : " 
       //+ conn.getResponseCode()); 
     //} 

     BufferedReader br = new BufferedReader(new InputStreamReader(
       (conn.getInputStream()))); 

     String output; 
     System.out.println("Output from Server .... \n"); 
     while ((output = br.readLine()) != null) { 
      System.out.println(output); 


      Gson gson = new GsonBuilder().setPrettyPrinting().create(); 
      JsonParser jp = new JsonParser(); 
      JsonElement je = jp.parse(output); 
      String prettyJsonString = gson.toJson(je);   

      System.out.println("Connection Status2: "+ prettyJsonString); 

//JSONObject obj = new JSONObject(); 
//String pageName = obj.getJSONObject("pageInfo").getString("pageName"); 

//JSONArray arr = obj.getJSONArray("posts"); 
//for (int i = 0; i < arr.length(); i++) 
//{ 
    // String post_id = arr.getJSONObject(i).getString("post_id"); 
// .... 
//}  


     } 

     conn.disconnect(); 

     } catch (MalformedURLException e) { 

     e.printStackTrace(); 

     } catch (IOException e) { 

     e.printStackTrace(); 

    } 

    } 

} 

//package com.objectplanet.chart.testing; 
のJavaプログラムを使用して受け取ることができます
関連する問題