-
Notifications
You must be signed in to change notification settings - Fork 7
/
module.php
52 lines (36 loc) · 1.54 KB
/
module.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
<?php
class IOSplitter extends IPSModule
{
public function ApplyChanges()
{
//Never delete this line!
parent::ApplyChanges();
//Always create our own VirtualIO, when no parent is already available
$this->RequireParent("{6179ED6A-FC31-413C-BB8E-1204150CF376}");
}
public function ForwardData($JSONString)
{
$data = json_decode($JSONString);
IPS_LogMessage("IOSplitter FRWD", utf8_decode($data->Buffer));
//We would package our payload here before sending it further...
$response = $this->SendDataToParent(json_encode(Array("DataID" => "{79827379-F36E-4ADA-8A95-5F8D1DC92FA9}", "Buffer" => $data->Buffer)));
//If the I/O sends a response you can use it
IPS_LogMessage("IOSplitter FRWD-RESP", $response);
//Normally we would wait here for ReceiveData getting called asynchronically and buffer some data
//Then we should extract the relevant feedback/data and return it to the caller
return "String data for the device instance!";
}
public function ReceiveData($JSONString)
{
$data = json_decode($JSONString);
IPS_LogMessage("IOSplitter RECV", utf8_decode($data->Buffer));
//We would parse our payload here before sending it further...
//Lets just forward to our children
$responses = $this->SendDataToChildren(json_encode(Array("DataID" => "{66164EB8-3439-4599-B937-A365D7A68567}", "Buffer" => $data->Buffer)));
//If a children sends a response you can use it
foreach($responses as $response) {
IPS_LogMessage("IOSplitter RECV-RESP", $response);
}
}
}
?>