-
Notifications
You must be signed in to change notification settings - Fork 25
/
post.php
executable file
·39 lines (33 loc) · 1.15 KB
/
post.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
/**
* POST fake DHT22 sensor data
*
* NOTICE: NO device registration required for sensors such as DHT22
*/
$host = 'http://localhost:8080'; // Default if https://github.com/sensorlogger/owncloud-docker-development used
$path = 'index.php/apps/sensorlogger';
$endpoint = 'api/v1/createlog';
$url = $host . DIRECTORY_SEPARATOR .
$path . DIRECTORY_SEPARATOR .
$endpoint . DIRECTORY_SEPARATOR;
$humidity = mt_rand (1.00*10, 99.99*10) / 10;
$temperature = mt_rand (-9.00*10, 49.99*10) / 10;
$array = [
"deviceId" => "101010-fe8c-11e6-bc64-92361f002671",
"temperature" => $temperature,
"humidity" => $humidity,
"date" => date('Y-m-d H:i:s')
];
$data_json = json_encode($array);
$username = 'admin';
$token = 'EDDUA-BGCAA-WUNYU-AVYYY';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $token);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$data_json);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
$response = curl_exec($ch);
curl_close($ch);
return $response;