-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathcallback.php
65 lines (57 loc) · 1.84 KB
/
callback.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
/*
Webhook called from Netatmo server on Home events
While testing:
error_reporting(E_ALL);
ini_set('display_errors', true);
*/
//__________________________Get the post JSON sent by Netatmo server
$jsonData = file_get_contents('php://input');
//__________________________send ok answer to netatmo immediately to not be banned:
ob_end_clean();
ignore_user_abort(true);
ob_start();
header('Content-Encoding: none');
header("Content-Length: " . ob_get_length());
header("Connection: close");
ob_end_flush();
ob_flush();
flush();
//get data as json:
$data = json_decode($jsonData, true);
//Now you have event data, do what you want with it!
//If message AND known person seen by Welcome:
$eventType = $data['event_type'];
if(isset($data['message']) && isset($data['persons']) && ($eventType == 'person'))
{
try
{
//Can have more than one person:
if (strpos($data['message'], 'ont') == true)
{
$who = explode(' ont ', $data['message'])[0];
$who = explode(' et ', $who);
}
else
{
$who = array(explode(' a ', $data['message'])[0]);
}
foreach ($who as $person)
{
echo 'Hello '.$who.' welcome home!';
}
}
catch (Exception $e)
{
logAnswer('Error checking person: '.$e->getMessage());
}
}
//If message AND person seen by Presence
if(isset($data['message']) && isset($data['snapshot_id']) && ($eventType == 'human'))
{
$snapshotID = $data['snapshot_id'];
$snapshotKEY = $data['snapshot_key'];
$snapshotURL = 'https://api.netatmo.com/api/getcamerapicture?image_id='.$snapshotID.'&key='.$snapshotKEY;
echo 'Someone has been seen outdoor, I may arm the gatling.';
}
?>