-1
A
回答
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
類似的結果,你可以接收使用Java程序以下程序
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;
相關問題
- 1. 我如何從json獲得價值?
- 2. HandlebarsJS如何從JSON獲得隨機值
- 3. 如何從JSON響應獲得價值
- 4. 如何獲得JSON值?
- 5. 獲得JSON值
- 6. 如何從json獲取值?
- 7. 如何從json獲取值
- 8. 獲取從JSON值與LINQ
- 9. 從json獲得前五個值,然後獲得剩餘值
- 10. 如何從$(this)獲得值
- 11. 如何從td獲得值
- 12. 如何獲得JSON數組值到J2ME
- 13. 如何獲得數組中的json值
- 14. 如何獲得json的返回值
- 15. 如何獲得第二級Json值
- 16. 如何獲得JSON
- 17. 獲得的JSON值
- 18. 如何從guzzle使用auth和body raw獲得響應?
- 19. 我如何獲得JSON的長度值與Alamofire
- 20. 如何從Laravel獲得JSON 5.1
- 21. 從JSON數據如何獲得數據
- 22. 如何從JSON獲得價格總
- 23. 如何從Facebook獲得JSON響應
- 24. 獲得從嵌套數組(JSON)值
- 25. 無法從JSON獲得價值存在
- 26. 從json數據獲得獨特價值
- 27. 不能從Json數組獲得鍵值:
- 28. 從網站獲取body標記值
- 29. 如何從HREF獲得價值,並與儲值
- 30. 如何從Json中獲得特定的值?