-
Notifications
You must be signed in to change notification settings - Fork 130
/
Copy pathpub.php
51 lines (39 loc) · 1.27 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
41
42
43
44
45
46
47
48
49
50
51
<?php
function pubMqtt($topic,$msg){
$APPID= "numpapicklinebot/"; //enter your appid
$KEY = "mJ7K4MfteC7p0dW"; //enter your key
$SECRET = "pp4gzMhCvJIqlxc66hKEvk46m"; //enter your secret
$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);
//curl_setopt($ch, CURLOPT_USERPWD, "mJ7K4MfteC7p0dW:pp4gzMhCvJIqlxc66hKEvk46m");
$response = curl_exec($ch);
curl_close($ch);
echo $response . "\r\n";
return $response;
}
// $Topic = "NodeMCU1";
//$lineMsg = "CHECK";
//getMqttfromlineMsg($Topic,$lineMsg);
?>