-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.php
28 lines (26 loc) · 865 Bytes
/
template.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
<?php
$domoticz = "##URL##";
$idx = "##IDX##";
$raw = file_get_contents('php://input');
$data = json_decode($raw, true, 512, JSON_BIGINT_AS_STRING);
if (is_array($data) && isset($data['events'])) {
foreach ($data['events'] as $i => $val) {
$collectdate = strftime("%Y-%m-%d %H:%M:%S", ($val['timestamp']/1000));
$val["original_timestamp"] = $val['timestamp'];
$val["localip"] = $data['localip'];
$val["timestamp"] = $collectdate;
$url = $domoticz."json.htm?type=command¶m=udevice&idx=".$idx."&nvalue=0&svalue=".urlencode(json_encode($val));
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$data = curl_exec($ch);
if(!curl_errno($ch)){
echo $data;
} else {
echo 'Curl error: ' . curl_error($tuCurl);
}
curl_close($ch);
}
}
?>