diff --git a/PHP/README.md b/PHP/README.md new file mode 100644 index 0000000..267c103 --- /dev/null +++ b/PHP/README.md @@ -0,0 +1,6 @@ +## IoT PAAS API put php functions. + +### Put + + $ php php-client-http-put.php + diff --git a/PHP/php-client-http-put.php b/PHP/php-client-http-put.php new file mode 100644 index 0000000..2b54853 --- /dev/null +++ b/PHP/php-client-http-put.php @@ -0,0 +1,46 @@ +'home.temp.indoor', + 'timestamp'=> time(), + 'value'=> rand(20, 35), + 'tags'=> [ + 'source'=>'dht22' + ] + ], + [ + 'metric'=>'home.temp.outdoor', + 'timestamp'=> time(), + 'value'=> rand(5, 25), + 'tags'=> [ + 'source'=>'dht22' + ] + ] +] +; + + + +$curl = curl_init($end_point); +curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); +curl_setopt($curl, CURLOPT_USERPWD, $token_id.":".$token_key); //Your credentials goes here +curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); +curl_setopt($curl, CURLOPT_VERBOSE, false); +curl_setopt($curl, CURLOPT_HEADER, false); +curl_setopt($curl, CURLOPT_POST, true); +curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data)); +curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); //IMP if the url has https and you don't want to verify source certificate + +$curl_response = curl_exec($curl); +curl_close($curl); +