-
Notifications
You must be signed in to change notification settings - Fork 0
/
pubMess.php
38 lines (36 loc) · 942 Bytes
/
pubMess.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
<?php
function sendMessage($topic, $message, $mqtt)
{
if ($mqtt->connect())
{
$mqtt->publish($topic,$message,0,1);
return true;
}
else
{
return false;
}
}
require("resources/phpMQTT.php");
$mqtt = new phpMQTT("192.168.1.20", 1883, "Web PHP MQTT Client", "ahmsNode", "ahms2013");
$message = trim($_GET["message"]);
$topic = trim($_GET["topic"]);
if (isset($message) && isset($topic) && strlen($message) > 0 && strlen($topic) > 0)
{
if(sendMessage($_GET["topic"], $_GET["message"], $mqtt))
{
$message = array ( "status" => "ok", "topic" => $topic, "message" => $message );
echo json_encode($message);
}
else
{
$message = array ( "status" => "failes to send message", "topic" => $topic, "message" => $message );
echo json_encode($message);
}
}
else
{
$message = array ( "status" => "invalid arguments", "topic" => $topic, "message" => $message );
echo json_encode($message);
}
?>