-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathpub.php
40 lines (35 loc) · 1.09 KB
/
pub.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
<?php
function pubMqtt($topic,$msg) {
$APPID= "NETPIE_APPID/"; //PUT NETPIE APPID Name end with "/"
$KEY = "NETPIE_Key"; //PUT NETPIE Key ID
$SECRET = "NETPIE_Secret"; //PUT NETPIE Secret ID
$Topic = "$topic";
put("https://api.netpie.io/microgear/".$APPID.$Topic."?retain&auth=".$KEY.":".$SECRET,$msg);
}
function getMqttfromlineMsg($Topic,$lineMsg) {
$pos = strpos($lineMsg, ":");
if($pos) {
$splitMsg = explode(":", $lineMsg);
$topic = $splitMsg[0];
$msg = $splitMsg[1];
pubMqtt($topic,$msg);
}
else {
$topic = $Topic;
$msg = $lineMsg;
pubMqtt($topic,$msg);
}
}
function put($url,$tmsg) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, $tmsg);
$response = curl_exec($ch);
curl_close($ch);
echo $response . "\r\n";
return $response;
}
?>