-
Notifications
You must be signed in to change notification settings - Fork 0
/
relayInterface.php
53 lines (38 loc) · 1.16 KB
/
relayInterface.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
<?php
require('EthRly.inc.php');
$board_ip = "192.168.1.1";
$board_port = 17494;
$board = new EthRly($board_ip, $board_port);
$board->connect();
$action = $_REQUEST['action'];
switch ($action) {
case 'turn_relay_on':
$relay = $_REQUEST['relay_num'];
$board->turnRelayOn($relay);
echo json_encode(array('success' => true));
break;
case 'turn_relay_off':
$relay = $_REQUEST['relay_num'];
$board->turnRelayOff($relay);
echo json_encode(array('success' => true));
break;
case 'turn_all_relay_off':
$board->turnAllRelayOff();
echo json_encode(array('success' => true));
break;
case 'get_all_statuses':
$status = $board->getRelayStatus();
echo json_encode(array('success' => true, 'data' => $status));
break;
case 'get_firmware':
$version = $board->getBoardVersion();
echo json_encode(array('success' => true, 'version' => $version));
break;
case 'get_input_voltage':
$voltage = $board->getInputVoltage();
echo json_encode(array('success' => true, 'voltage' => $voltage));
break;
case 'get_ip_address':
echo json_encode(array('success' => true, 'ip' => $board_ip));
break;
}