|
1 <?php |
|
2 |
|
3 /* |
|
4 * Sequence number file. Must be mode 666 in directory mode 777 |
|
5 */ |
|
6 $sfile = "run/sequence"; |
|
7 if (fopen($sfile, "r")) { |
|
8 $data = file_get_contents($sfile); |
|
9 $nr = intval($data); |
|
10 } else { |
|
11 $nr = 1; |
|
12 } |
|
13 $nr++; |
|
14 if ($fp = fopen($sfile, "w")) { |
|
15 file_put_contents($sfile, $nr); |
|
16 fclose($fp); |
|
17 } |
|
18 |
|
19 |
|
20 if (isset($_POST['node'])) { |
|
21 $node = $_POST['node']; |
|
22 } else { |
|
23 return 1; |
|
24 } |
|
25 if (isset($_POST['alias'])) { |
|
26 $alias = $_POST['alias']; |
|
27 } else { |
|
28 return 1; |
|
29 } |
|
30 if (isset($_POST['payload'])) { |
|
31 $payload = $_POST['payload']; |
|
32 } else { |
|
33 return 1; |
|
34 } |
|
35 |
|
36 |
|
37 /* |
|
38 * topic: mbv1.0/fermenters/DCMD/$node/$alias |
|
39 * payload: {"timestamp":1546956819,"seq":688,"metric":$payload} |
|
40 * $payload: {"product":{"code":"HUP001","name":"Hop Hup"}} |
|
41 * {"stage":"PRIMARY","mode":"FRIDGE","setpoint":{"low":17.8,"high":18.2}} |
|
42 * {"heater":{"state":0},"cooler":{"state":0},"fan":{"state":0}} |
|
43 * {"profile":{"uuid":"...","name":"profielnaam","inittemp":{"low":18.2,"high":20.5},"fridgemode":0, |
|
44 * "steps":[{"resttime":12,"steptime":36,"target":{"low":20.8,"high":23.1},"fridgemode":0}, |
|
45 * {"resttime":48,"steptime":48,"target":{"low":27.5,"high":28.0},"fridgemode":0}]}} |
|
46 */ |
|
47 $topic = "mbv1.0/fermenters/DCMD/" . $node . "/" . $alias; |
|
48 $payload = '\'{"timestamp":' . time() . ',"seq":' . $nr . ',"metric":' . $payload . '}\''; |
|
49 |
|
50 syslog(LOG_NOTICE, $topic . ' ' . $payload); |
|
51 shell_exec('mosquitto_pub -h seaport -q 0 -t '.$topic.' -m '.$payload); |
|
52 |
|
53 ?> |