GroveStreams

Uploading historical data via PHP501

JoEmbedded private msg quote post Address this user
Hi Forum!

I have an account where a data logger sends the collected data as one block (with ultra low power via 2/3/4G) to an intermediate server. From there times/values are extracted and shall be inserted to my account. (Device: clickable text )

The "direct way" works:

 
https://grovestreams.com/api/feed?api_key=68312ae5-XXXX-3e9d-8f4c-615a10d836f3&compId=Tbuero&data=-26&data=-27&asPut
 


However if sending the old data via PHP/JSON I always get "Unsupported Media Type". I tested it with a small sample script:

 
<?php
error_reporting(E_ALL);
 
// data
$data0=array(10,11);
$data_c0=array("data"=>$data0);
$data_c=array($data_c0);
$component=array("stream" => $data_c,  "compId" => "Tbuero");
$feed=array("startTime"=> time()*1000, "component" => $component);
$gs=json_encode(array("feed" => $feed));
 
// URL
$gs_api_key="68312ae5-XXXX-3e9d-8f4c-615a10d836f3"; // FEED
$gs_url="http://grovestreams.com/api/feed"; 
 
 
$url="$gs_url?api_key=$gs_api_key";
 
// CURL 
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS,$gs);
curl_setopt($ch, CURLOPT_TIMEOUT,15);	// opt. seconds timeout (for Tests)
$response = curl_exec($ch);
curl_close($ch);
 
echo $response;
?>
 


which sends:

 
PUT /api/feed?api_key=68312ae5-XXXX-3e9d-8f4c-615a10d836f3 HTTP/1.1
Host: grovestreams.com
Accept: */*
Content-Length: 96
Content-Type: application/x-www-form-urlencoded
 
{
	"feed":
	{
		"startTime":1540832371000,
		"component":
		{
			"stream":
			[
				{
					"data":[10,11]
				}
			],
			"compId":"Tbuero"
		}
	}
}
 


What am I doing wrong?
Thanks for your help!
Jo
Post 1 IP   flag post
MikeMills private msg quote post Address this user
I think Unsupported Media type means the content-type header needs to be set. Try setting the header: content-type:application/json

Here's a GS Python example: https://www.grovestreams.com/developers/getting_started_helloworld_python.html
Post 2 IP   flag post
2845 2 2
Log in or sign up to compose a reply.
destitute