www/cmd_fermenter.php

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

mercurial