Jump to content









Photo

Data Stream in PHP or Google Gauge

data stream PHP

  • Please log in to reply
17 replies to this topic

#1 macckk

macckk

    Newbie

  • Members
  • Pip
  • 5 posts
  • LocationVotuporanga, Sao Paulo - Brasil

Posted 30 June 2014 - 03:12 AM

Hello,

 

How do I receive data stream using PHP?

 

Its use Google Gauge to display data graphically? (https://developers.g...s/gallery/gauge)

 

thanks

 

Marcelo



#2 sdeancos

sdeancos

    Master of Puppets

  • Members
  • PipPipPip
  • 102 posts
  • LocationMadrid, Spain.

Posted 30 June 2014 - 05:57 AM

Hi!

 

Perhaps the following example may be useful:

 

 

<?php
$headers = array();
$device = "YOUR_ID_DEVELOPER_DEVICE_HERE";
$headers[] = 'carriots.apikey: YOUR_APIKEY_HERE';
$url = "https://api.carriots.com/devices/".$device."/streams/";
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_NOBODY, false);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$output = curl_exec($ch);
curl_close($ch);
var_dump($output);

 

I hope you help!



#3 macckk

macckk

    Newbie

  • Members
  • Pip
  • 5 posts
  • LocationVotuporanga, Sao Paulo - Brasil

Posted 30 June 2014 - 11:53 AM

Thanks Sdeancos...

 

It worked. 
 
Only that is showing all records. 
I would like to selecioar some data? 
It would be cool also do a search between dates. 
 
Thank you very much.


#4 sdeancos

sdeancos

    Master of Puppets

  • Members
  • PipPipPip
  • 102 posts
  • LocationMadrid, Spain.

Posted 01 July 2014 - 05:56 AM

Hi

 

You can try:

$my_timestamp_to = YOU_TIMESTAMP_TO_HERE;
$my_timestamp_from = YOU_TIMESTAMP_FROM_HERE;
$url = "https://api.carriots.com/devices/".$device."/streams/?at_to=".$my_timestamp_to."&at_from_=".$my_timestamp_from;

where $my_timestamp_to and $my_timestamp_from are Unix timestamp http://en.wikipedia.org/wiki/Unix_time

 

 

I hope you help!



#5 macckk

macckk

    Newbie

  • Members
  • Pip
  • 5 posts
  • LocationVotuporanga, Sao Paulo - Brasil

Posted 01 July 2014 - 11:40 AM

Thanks Sdeancos...

 

You know what are the parameters that I can use in the URL? 
 
For example: my device sends 3 values ​​of 3 sensors. How do I separate them by URL. Have temperature and humidity. How do I make a query of temperature only. 
 
Thank you for listening.
 
Marcelo Cuin


#6 sdeancos

sdeancos

    Master of Puppets

  • Members
  • PipPipPip
  • 102 posts
  • LocationMadrid, Spain.

Posted 01 July 2014 - 12:56 PM

Hi!

 

You can try filter by _contains[]='temp'  for get only streams with key temp in data but filter the fields shown in stream for now not implemented.

 

For example:

 

$url = "https://api.carriots.com/devices/".$device."/streams/?_contains[]=temp";

 

 

 

I hope this help :D



#7 macckk

macckk

    Newbie

  • Members
  • Pip
  • 5 posts
  • LocationVotuporanga, Sao Paulo - Brasil

Posted 01 July 2014 - 06:16 PM

Thanks Sdeancos...

 

But this time it did not work. 
I have a configured device, sending 3 different values ​​for Carriots.com. (temperature, humidity and voltage) 
 
I need to make a query, like a SQL, where the return would be: 
- Last 30 records, sorted in decreasing order (by id), with the temperature parameter. 
 
How would it be? 
 
I'm trying to make that query to display in a chart (google gauge). 
 
Again, thanks for listening.
 
Marcelo


#8 sdeancos

sdeancos

    Master of Puppets

  • Members
  • PipPipPip
  • 102 posts
  • LocationMadrid, Spain.

Posted 02 July 2014 - 06:01 AM

Hello!

 

Maybe you can use a sort and order params:

 

 

For example:

 

$url = "https://api.carriots.com/devices/".$device."/streams/?max=30&sort=_id&order=-1&_contains[]=temperature";

 

 

I hope this is what you need.



#9 macckk

macckk

    Newbie

  • Members
  • Pip
  • 5 posts
  • LocationVotuporanga, Sao Paulo - Brasil

Posted 02 July 2014 - 11:48 AM

Thanks Sdeancos...

 

Almost got it right! 
 
Only the filter _contains[] did not work. 
Not only did the query temperature (lm35). Return all results. 
 
This was the return:

string(3345) "{"total_documents":1243,"result":[{"_id":"ID","protocol":"v2","checksum":"","_t":"str","at":1404301196,"device":"DEVICE","data":{"dht11_hum":"56","lm35":"21","dht11_temp":"22","rede":"122"},"id_developer":"ID_DEVELOPER","created_at":1404301196,"owner":"OWNER"}"

 

How would this query?

 

Thank you for listening.
 
Marcelo Cuin


#10 jpastor

jpastor

    Development leader

  • Administrators
  • 159 posts

Posted 04 July 2014 - 12:21 PM

Hello Macckk

 

You can try filter by _contains[]='temp'  to get only streams which contains this key in data, but currently Carriots doesn't show only these fields

Hope it helps



#11 Jac_cheik

Jac_cheik

    Newbie

  • Members
  • Pip
  • 5 posts

Posted 27 May 2015 - 11:16 AM

Hi everyone,

 

Do this php can using localhost(WAMP)?

 

I try run the program show above but it show the result in 'boolean false'.

 

How do i solve this problem?

 

Thanks 

 

Best regards

 



#12 sdeancos

sdeancos

    Master of Puppets

  • Members
  • PipPipPip
  • 102 posts
  • LocationMadrid, Spain.

Posted 28 May 2015 - 07:59 AM

Hi Jac_cheik,

 

Do you change the id developer device and apikey in $device and $headers?

 

Could you paste your code here? Maybe the users can help you if they could view your code.

 

In principle the code of the first post is working for me.

 

Best regards.



#13 Jac_cheik

Jac_cheik

    Newbie

  • Members
  • Pip
  • 5 posts

Posted 06 June 2015 - 06:04 AM

Hi Master of Puppets,

 

Sorry i just saw your reply.

 

<?php

$headers = array();
$device = "RFID@Jac_cheik.Jac_cheik";
$headers[] = 'carriots.apikey: 6a7f93cdd6b06633d22cd6a767212eab269f1e6fd65d5a497934c03274e5dde9';
$url = "https://api.carriots.com/devices/".$device."/streams/";
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_NOBODY, false);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$output = curl_exec($ch);
var_dump($output);
curl_close($ch);
echo"hi";
var_dump($output);
echo"+++$output";
?>

 

the output of this coding is 

boolean false

hi

boolean false

+++

 

Thanks for reply and I still cant solve it. 



#14 sdeancos

sdeancos

    Master of Puppets

  • Members
  • PipPipPip
  • 102 posts
  • LocationMadrid, Spain.

Posted 06 June 2015 - 11:08 AM

Hi,

 

I test the code with your account and is workinf for me, maybe you have some problem with curl module or connection.

 

You could try this and send the result please:

 

<?php 
$headers = array(); 
$device = "RFID@Jac_cheik.Jac_cheik"; 
$headers[] = 'carriots.apikey: 6a7f93cdd6b06633d22cd6a767212eab269f1e6fd65d5a497934c03274e5dde9'; 
$url = "https://api.carriots.com/devices/".$device."/streams/"; 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 
curl_setopt($ch, CURLOPT_NOBODY, false); 
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); 
$output = curl_exec($ch); 
var_dump($output); 
curl_close($ch);
echo curl_getinfo($ch) . '<br/>'; 
echo curl_errno($ch) . '<br/>'; 
echo curl_error($ch) . '<br/>';

 

?>

 

 

BR



#15 Jac_cheik

Jac_cheik

    Newbie

  • Members
  • Pip
  • 5 posts

Posted 07 June 2015 - 03:39 AM

Hi Master of Puppets,

 

I try ur code but the error show as link below.

 

https://plus.google....669557641512383

 

Now i am using WAMP Server with PHP5.5.12

 

the curl_php is enable already for both php.ini and apache,in file.

 

Thanks and have a nice day.



#16 sdeancos

sdeancos

    Master of Puppets

  • Members
  • PipPipPip
  • 102 posts
  • LocationMadrid, Spain.

Posted 08 June 2015 - 08:05 AM

Hi,

 

 

You can try to put debug lines before closing the connection:

<?php
..
..
echo curl_getinfo($ch) . '<br/>'; 
echo curl_errno($ch) . '<br/>'; 
echo curl_error($ch) . '<br/>';
curl_close($ch);

?>

 

I hope this help you.

 

BR



#17 Jac_cheik

Jac_cheik

    Newbie

  • Members
  • Pip
  • 5 posts

Posted 10 June 2015 - 03:49 AM

Hi Master of Puppets, 

 

I am very thank you reply me and helping me. 

But the error occur still occurring.

 

https://plus.google....669557641512383

 

Thank you and have a nice day. :)



#18 sdeancos

sdeancos

    Master of Puppets

  • Members
  • PipPipPip
  • 102 posts
  • LocationMadrid, Spain.

Posted 10 June 2015 - 03:28 PM

Hi, Jac

Could you send you code to support@carriots.com?

Maybe read your code complete we could help you.

 

 

BR :D







Also tagged with one or more of these keywords: data, stream, PHP

1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users