提交 c03e571f5a5413f49e77b746aa6dd31202d78a4c

作者 mq_online_test
1 个父辈 70a4fe66

add php demo

... ... @@ -19,6 +19,7 @@
19 19 |C#| Eclipse Paho C# SDK|https://github.com/eclipse/paho.mqtt.m2mqtt|
20 20 |Go|Eclipse Paho Go SDK|https://github.com/eclipse/paho.mqtt.golang|
21 21 |Nodejs|MQTT JS|https://github.com/mqttjs/MQTT.js|
  22 +|PHP|Mosquitto-PHP|https://github.com/mgdm/Mosquitto-PHP|
22 23  
23 24 其他语言的客户端 SDK 如 PHP 等暂时没有提供测试。如有需要可以访问 https://github.com/mqtt/mqtt.github.io/wiki/libraries 进行下载。
24 25  
... ...
... ... @@ -52,12 +52,13 @@ public class Tools {
52 52 * 计算签名,参数分别是参数对以及密钥
53 53 *
54 54 * @param requestParams 参数对,即参与计算签名的参数
55   - * @param secretKey 密钥
  55 + * @param secretKey 密钥
56 56 * @return 签名字符串
57 57 * @throws NoSuchAlgorithmException
58 58 * @throws InvalidKeyException
59 59 */
60   - public static String doHttpSignature(Map<String, String> requestParams, String secretKey) throws NoSuchAlgorithmException, InvalidKeyException {
  60 + public static String doHttpSignature(Map<String, String> requestParams,
  61 + String secretKey) throws NoSuchAlgorithmException, InvalidKeyException {
61 62 List<String> paramList = new ArrayList<String>();
62 63 for (Map.Entry<String, String> entry : requestParams.entrySet()) {
63 64 paramList.add(entry.getKey() + "=" + entry.getValue());
... ... @@ -74,13 +75,14 @@ public class Tools {
74 75 }
75 76  
76 77 /**
77   - * @param text 要签名的文本
  78 + * @param text 要签名的文本
78 79 * @param secretKey 阿里云MQ secretKey
79 80 * @return 加密后的字符串
80 81 * @throws InvalidKeyException
81 82 * @throws NoSuchAlgorithmException
82 83 */
83   - public static String macSignature(String text, String secretKey) throws InvalidKeyException, NoSuchAlgorithmException {
  84 + public static String macSignature(String text,
  85 + String secretKey) throws InvalidKeyException, NoSuchAlgorithmException {
84 86 Charset charset = Charset.forName("UTF-8");
85 87 String algorithm = "HmacSHA1";
86 88 Mac mac = Mac.getInstance(algorithm);
... ... @@ -91,12 +93,6 @@ public class Tools {
91 93  
92 94 /**
93 95 * 创建HTTPS 客户端
94   - *
95   - * @return 单例模式的客户端
96   - * @throws KeyStoreException
97   - * @throws UnrecoverableKeyException
98   - * @throws NoSuchAlgorithmException
99   - * @throws KeyManagementException
100 96 */
101 97 private static HttpClient httpClient = null;
102 98  
... ... @@ -107,25 +103,25 @@ public class Tools {
107 103 X509TrustManager xtm = new X509TrustManager() {
108 104 @Override
109 105 public void checkClientTrusted(X509Certificate[] arg0, String arg1)
110   - throws CertificateException {
  106 + throws CertificateException {
111 107 }
112 108  
113 109 @Override
114 110 public void checkServerTrusted(X509Certificate[] arg0, String arg1)
115   - throws CertificateException {
  111 + throws CertificateException {
116 112 }
117 113  
118 114 @Override
119 115 public X509Certificate[] getAcceptedIssuers() {
120   - return new X509Certificate[]{};
  116 + return new X509Certificate[] {};
121 117 }
122 118 };
123 119 SSLContext context = SSLContext.getInstance("TLS");
124   - context.init(null, new TrustManager[]{xtm}, null);
  120 + context.init(null, new TrustManager[] {xtm}, null);
125 121 SSLConnectionSocketFactory scsf = new SSLConnectionSocketFactory(context, NoopHostnameVerifier.INSTANCE);
126 122 Registry<ConnectionSocketFactory> sfr = RegistryBuilder.<ConnectionSocketFactory>create()
127   - .register("http", PlainConnectionSocketFactory.INSTANCE)
128   - .register("https", scsf).build();
  123 + .register("http", PlainConnectionSocketFactory.INSTANCE)
  124 + .register("https", scsf).build();
129 125 PoolingHttpClientConnectionManager pcm = new PoolingHttpClientConnectionManager(sfr);
130 126 httpClient = HttpClientBuilder.create().setConnectionManager(pcm).build();
131 127 return httpClient;
... ... @@ -135,25 +131,25 @@ public class Tools {
135 131 X509TrustManager xtm = new X509TrustManager() {
136 132 @Override
137 133 public void checkClientTrusted(X509Certificate[] arg0, String arg1)
138   - throws CertificateException {
  134 + throws CertificateException {
139 135 }
140 136  
141 137 @Override
142 138 public void checkServerTrusted(X509Certificate[] arg0, String arg1)
143   - throws CertificateException {
  139 + throws CertificateException {
144 140 }
145 141  
146 142 @Override
147 143 public X509Certificate[] getAcceptedIssuers() {
148   - return new X509Certificate[]{};
  144 + return new X509Certificate[] {};
149 145 }
150 146 };
151 147 SSLContext context = SSLContext.getInstance("TLS");
152   - context.init(null, new TrustManager[]{xtm}, null);
  148 + context.init(null, new TrustManager[] {xtm}, null);
153 149 SSLConnectionSocketFactory scsf = new SSLConnectionSocketFactory(context, NoopHostnameVerifier.INSTANCE);
154 150 Registry<ConnectionSocketFactory> sfr = RegistryBuilder.<ConnectionSocketFactory>create()
155   - .register("http", PlainConnectionSocketFactory.INSTANCE)
156   - .register("https", scsf).build();
  151 + .register("http", PlainConnectionSocketFactory.INSTANCE)
  152 + .register("https", scsf).build();
157 153 PoolingHttpClientConnectionManager pcm = new PoolingHttpClientConnectionManager(sfr);
158 154 return HttpClientBuilder.create().setConnectionManager(pcm).build();
159 155 }
... ... @@ -161,7 +157,7 @@ public class Tools {
161 157 /**
162 158 * 发起Https Get请求,并得到返回的JSON响应
163 159 *
164   - * @param url 接口Url
  160 + * @param url 接口Url
165 161 * @param params 参数u对
166 162 * @return
167 163 * @throws IOException
... ... @@ -170,7 +166,8 @@ public class Tools {
170 166 * @throws NoSuchAlgorithmException
171 167 * @throws KeyManagementException
172 168 */
173   - public static JSONObject httpsGet(String url, Map<String, String> params) throws IOException, KeyStoreException, UnrecoverableKeyException, NoSuchAlgorithmException, KeyManagementException {
  169 + public static JSONObject httpsGet(String url,
  170 + Map<String, String> params) throws IOException, KeyStoreException, UnrecoverableKeyException, NoSuchAlgorithmException, KeyManagementException {
174 171 HttpClient client = Tools.getHttpsClient();
175 172 JSONObject jsonResult = null;
176 173 //发送get请求
... ... @@ -191,12 +188,13 @@ public class Tools {
191 188 /**
192 189 * 工具方法,发送一个http post请求,并尝试将响应转换为JSON
193 190 *
194   - * @param url 请求的方法名url
  191 + * @param url 请求的方法名url
195 192 * @param params 参数表
196 193 * @return 如果请求成功则返回JSON, 否则抛异常或者返回空
197 194 * @throws IOException
198 195 */
199   - public static JSONObject httpsPost(String url, Map<String, String> params) throws IOException, UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
  196 + public static JSONObject httpsPost(String url,
  197 + Map<String, String> params) throws IOException, UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
200 198 JSONObject jsonResult = null;
201 199 //发送get请求
202 200 HttpClient client = getHttpsClient();
... ... @@ -214,4 +212,10 @@ public class Tools {
214 212 }
215 213 return jsonResult;
216 214 }
  215 +
  216 + public static void main(String[] args) {
  217 + JSONObject object = new JSONObject();
  218 + object.put("order", "true");//设置顺序发送的标记
  219 + System.out.println(object.toJSONString());
  220 + }
217 221 }
... ...
  1 +<?php
  2 +
  3 +use Mosquitto\Client;
  4 +
  5 +##此处填写阿里云帐号 AccessKey
  6 +$accessKey = 'XXXX';
  7 +##此处填写阿里云帐号 SecretKey
  8 +$secretKey = 'XXXX';
  9 +## 接入点地址,购买实例后从控制台获取
  10 +$endPoint = 'XXXX.mqtt.aliyuncs.com';
  11 +##实例 ID,购买后从控制台获取
  12 +$instanceId = 'XXXX';
  13 +## MQTT Topic,其中第一级 Topic 需要在 MQTT 控制台提前申请
  14 +$topic = 'XXXX';
  15 +## MQTT 客户端ID 前缀, GroupID,需要在 MQTT 控制台申请
  16 +$groupId = 'GID_XXXX';
  17 +## MQTT 客户端ID 后缀,DeviceId,业务方自由指定,需要保证全局唯一,禁止 2 个客户端连接使用同一个 ID
  18 +$deviceId = 'XXXX';
  19 +$qos = 0;
  20 +$port = 1883;
  21 +$keepalive = 90;
  22 +$cleanSession = true;
  23 +$clientId = $groupId . '@@@' . $deviceId;
  24 +echo $clientId . "\n";
  25 +
  26 +$mid = 0;
  27 +## 初始化客户端,需要设置 clientId 和 CleanSession 参数,参考官网文档规范
  28 +$mqttClient = new Mosquitto\Client($clientId, $cleanSession);
  29 +
  30 +
  31 +## 设置鉴权参数,参考 MQTT 客户端鉴权代码计算 username 和 password
  32 +$username = 'Signature|' . $accessKey . '|' . $instanceId;
  33 +$sigStr = hash_hmac("sha1", $clientId, $secretKey, true);
  34 +$password = base64_encode($sigStr);
  35 +echo "UserName:" . $username . " Password:" . $password . "\n";
  36 +$mqttClient->setCredentials($username, $password);
  37 +
  38 +## 设置连接成功回调
  39 +$mqttClient->onConnect(function ($rc, $message) use ($mqttClient, &$mid, $topic, $qos) {
  40 + echo "Connnect to Server Code is " . $rc . " message is " . $message . "\n";
  41 + $mqttClient->subscribe($topic, $qos);
  42 +});
  43 +
  44 +
  45 +## 设置订阅成功回调
  46 +$mqttClient->onSubscribe(function () use ($mqttClient, $topic, $qos) {
  47 + $mqttClient->publish($topic, "Hello MQTT PHP Demo", $qos);
  48 +});
  49 +
  50 +## 设置发送成功回调
  51 +$mqttClient->onPublish(function ($publishedId) use ($mqttClient, $mid) {
  52 + echo "publish message success " . $mid . "\n";
  53 +});
  54 +
  55 +
  56 +## 设置消息接收回调
  57 +$mqttClient->onMessage(function ($message) {
  58 + echo "Receive Message From mqtt, topic is " . $message->topic . " qos is " . $message->qos . " messageId is " . $message->mid . " payload is " . $message->payload . "\n";
  59 +
  60 +});
  61 +$mqttClient->connect($endPoint, $port, $keepalive);
  62 +
  63 +
  64 +$mqttClient->loopForever();
  65 +
  66 +echo "Finished";
0 67 \ No newline at end of file
... ...
  1 +<?php
  2 +
  3 +use Mosquitto\Client;
  4 +
  5 +##此处填写阿里云帐号 AccessKey
  6 +$accessKey = 'XXXX';
  7 +##此处填写阿里云帐号 SecretKey
  8 +$secretKey = 'XXXX';
  9 +## 接入点地址,购买实例后从控制台获取
  10 +$endPoint = 'XXXX.mqtt.aliyuncs.com';
  11 +##实例 ID,购买后从控制台获取
  12 +$instanceId = 'XXXX';
  13 +## MQTT Topic,其中第一级 Topic 需要在 MQTT 控制台提前申请
  14 +$topic = 'XXXX';
  15 +## MQTT 客户端ID 前缀, GroupID,需要在 MQTT 控制台申请
  16 +$groupId = 'GID_XXXX';
  17 +## MQTT 客户端ID 后缀,DeviceId,业务方自由指定,需要保证全局唯一,禁止 2 个客户端连接使用同一个 ID
  18 +$deviceId = 'XXXX';
  19 +$qos = 0;
  20 +$port = 1883;
  21 +$keepalive = 90;
  22 +$cleanSession = true;
  23 +$clientId = $groupId . '@@@' . $deviceId;
  24 +echo $clientId . "\n";
  25 +
  26 +$mid = 0;
  27 +## 初始化客户端,需要设置 clientId 和 CleanSession 参数,参考官网文档规范
  28 +$mqttClient = new Mosquitto\Client($clientId, $cleanSession);
  29 +
  30 +
  31 +## 设置鉴权参数,参考 MQTT 客户端鉴权代码计算 username 和 password
  32 +$username = 'Token|' . $accessKey . '|' . $instanceId;
  33 +## Token模式,token 需要提前向自己的应用服务提供方申请,此处以读写权限类型的 token 为例,token内容以 xxx 为例。
  34 +$tokenStr = 'xxx';
  35 +$password = 'RW|' . $tokenStr;
  36 +echo "UserName:" . $username . " Password:" . $password . "\n";
  37 +$mqttClient->setCredentials($username, $password);
  38 +
  39 +## 设置连接成功回调
  40 +$mqttClient->onConnect(function ($rc, $message) use ($mqttClient, &$mid, $topic, $qos) {
  41 + echo "Connnect to Server Code is " . $rc . " message is " . $message . "\n";
  42 + $mqttClient->subscribe($topic, $qos);
  43 +});
  44 +
  45 +
  46 +## 设置订阅成功回调
  47 +$mqttClient->onSubscribe(function () use ($mqttClient, $topic, $qos) {
  48 + $mqttClient->publish($topic, "Hello MQTT PHP Demo", $qos);
  49 +});
  50 +
  51 +## 设置发送成功回调
  52 +$mqttClient->onPublish(function ($publishedId) use ($mqttClient, $mid) {
  53 + echo "publish message success " . $mid . "\n";
  54 +});
  55 +
  56 +
  57 +## 设置消息接收回调
  58 +$mqttClient->onMessage(function ($message) {
  59 + echo "Receive Message From mqtt, topic is " . $message->topic . " qos is " . $message->qos . " messageId is " . $message->mid . " payload is " . $message->payload . "\n";
  60 +
  61 +});
  62 +$mqttClient->connect($endPoint, $port, $keepalive);
  63 +
  64 +
  65 +$mqttClient->loopForever();
  66 +
  67 +echo "Finished";
0 68 \ No newline at end of file
... ...
  1 +<?php
  2 +
  3 +use Mosquitto\Client;
  4 +
  5 +##此处填写阿里云帐号 AccessKey
  6 +$accessKey = 'XXXX';
  7 +##此处填写阿里云帐号 SecretKey
  8 +$secretKey = 'XXXX';
  9 +## 接入点地址,购买实例后从控制台获取
  10 +$endPoint = 'XXXX.mqtt.aliyuncs.com';
  11 +##实例 ID,购买后从控制台获取
  12 +$instanceId = 'XXXX';
  13 +## MQTT Topic,其中第一级 Topic 需要在 MQTT 控制台提前申请
  14 +$topic = 'XXXX';
  15 +## MQTT 客户端ID 前缀, GroupID,需要在 MQTT 控制台申请
  16 +$groupId = 'GID_XXXX';
  17 +## MQTT 客户端ID 后缀,DeviceId,业务方自由指定,需要保证全局唯一,禁止 2 个客户端连接使用同一个 ID
  18 +$deviceId = 'XXXX';
  19 +$qos = 0;
  20 +$port = 1883;
  21 +$keepalive = 90;
  22 +$cleanSession = true;
  23 +$clientId = $groupId . '@@@' . $deviceId;
  24 +echo $clientId . "\n";
  25 +
  26 +$mid = 0;
  27 +## 初始化客户端,需要设置 clientId 和 CleanSession 参数,参考官网文档规范
  28 +$mqttClient = new Mosquitto\Client($clientId, $cleanSession);
  29 +
  30 +
  31 +## 设置鉴权参数,参考 MQTT 客户端鉴权代码计算 username 和 password
  32 +$username = 'Signature|' . $accessKey . '|' . $instanceId;
  33 +$sigStr = hash_hmac("sha1", $clientId, $secretKey, true);
  34 +$password = base64_encode($sigStr);
  35 +echo "UserName:" . $username . " Password:" . $password . "\n";
  36 +$mqttClient->setCredentials($username, $password);
  37 +
  38 +## 设置连接成功回调
  39 +$mqttClient->onConnect(function ($rc, $message) use ($mqttClient, &$mid, $topic, $qos) {
  40 + echo "Connnect to Server Code is " . $rc . " message is " . $message . "\n";
  41 + $mqttClient->subscribe($topic, $qos);
  42 +});
  43 +
  44 +
  45 +## 设置订阅成功回调
  46 +$mqttClient->onSubscribe(function () use ($mqttClient, $topic, $qos) {
  47 + $mqttClient->publish($topic, "Hello MQTT PHP Demo", $qos);
  48 +});
  49 +
  50 +## 设置发送成功回调
  51 +$mqttClient->onPublish(function ($publishedId) use ($mqttClient, $mid) {
  52 + echo "publish message success " . $mid . "\n";
  53 +});
  54 +
  55 +
  56 +## 设置消息接收回调
  57 +$mqttClient->onMessage(function ($message) {
  58 + echo "Receive Message From mqtt, topic is " . $message->topic . " qos is " . $message->qos . " messageId is " . $message->mid . " payload is " . $message->payload . "\n";
  59 +
  60 +});
  61 +$mqttClient->connect($endPoint, $port, $keepalive);
  62 +
  63 +
  64 +$mqttClient->loopForever();
  65 +
  66 +echo "Finished";
0 67 \ No newline at end of file
... ...
  1 +<?php
  2 +
  3 +use Mosquitto\Client;
  4 +
  5 +##此处填写阿里云帐号 AccessKey
  6 +$accessKey = 'XXXX';
  7 +##此处填写阿里云帐号 SecretKey
  8 +$secretKey = 'XXXX';
  9 +## 接入点地址,购买实例后从控制台获取
  10 +$endPoint = 'XXXX.mqtt.aliyuncs.com';
  11 +##实例 ID,购买后从控制台获取
  12 +$instanceId = 'XXXX';
  13 +## MQTT Topic,其中第一级 Topic 需要在 MQTT 控制台提前申请
  14 +$topic = 'XXXX';
  15 +## MQTT 客户端ID 前缀, GroupID,需要在 MQTT 控制台申请
  16 +$groupId = 'GID_XXXX';
  17 +## MQTT 客户端ID 后缀,DeviceId,业务方自由指定,需要保证全局唯一,禁止 2 个客户端连接使用同一个 ID
  18 +$deviceId = 'XXXX';
  19 +##用于设置顺序属性的系统命令 topic
  20 +$sysCmdTopic='$SYS/enableOrderMsg';
  21 +$qos = 0;
  22 +$port = 1883;
  23 +$keepalive = 90;
  24 +$cleanSession = true;
  25 +$clientId = $groupId . '@@@' . $deviceId;
  26 +echo $clientId . "\n";
  27 +
  28 +$mid = 0;
  29 +## 初始化客户端,需要设置 clientId 和 CleanSession 参数,参考官网文档规范
  30 +$mqttClient = new Mosquitto\Client($clientId, $cleanSession);
  31 +
  32 +
  33 +## 设置鉴权参数,参考 MQTT 客户端鉴权代码计算 username 和 password
  34 +$username = 'Signature|' . $accessKey . '|' . $instanceId;
  35 +$sigStr = hash_hmac("sha1", $clientId, $secretKey, true);
  36 +$password = base64_encode($sigStr);
  37 +echo "UserName:" . $username . " Password:" . $password . "\n";
  38 +$mqttClient->setCredentials($username, $password);
  39 +
  40 +## 设置连接成功回调
  41 +$mqttClient->onConnect(function ($rc, $message) use ($mqttClient, &$mid, $topic, $qos, $sysCmdTopic) {
  42 + echo "Connnect to Server Code is " . $rc . " message is " . $message . "\n";
  43 + ## 连接成功后需要在发消息之前提前设置顺序属性,然后再发消息,才能保证同一个 clientId 发的消息顺序。
  44 + $orderCmdBody = "{\"order\":\"true\"}";
  45 + $mqttClient->publish($sysCmdTopic, $orderCmdBody, 1);
  46 + $mqttClient->subscribe($topic, $qos);
  47 +});
  48 +
  49 +
  50 +## 设置订阅成功回调
  51 +$mqttClient->onSubscribe(function () use ($mqttClient, $topic, $qos) {
  52 + $mqttClient->publish($topic, "Hello MQTT PHP Demo", $qos);
  53 +});
  54 +
  55 +## 设置发送成功回调
  56 +$mqttClient->onPublish(function ($publishedId) use ($mqttClient, $mid) {
  57 + echo "publish message success " . $mid . "\n";
  58 +});
  59 +
  60 +
  61 +## 设置消息接收回调
  62 +$mqttClient->onMessage(function ($message) {
  63 + echo "Receive Message From mqtt, topic is " . $message->topic . " qos is " . $message->qos . " messageId is " . $message->mid . " payload is " . $message->payload . "\n";
  64 +
  65 +});
  66 +$mqttClient->connect($endPoint, $port, $keepalive);
  67 +
  68 +
  69 +$mqttClient->loopForever();
  70 +
  71 +echo "Finished";
0 72 \ No newline at end of file
... ...
  1 +<?php
  2 +
  3 +use Mosquitto\Client;
  4 +
  5 +##此处填写阿里云帐号 AccessKey
  6 +$accessKey = 'XXXX';
  7 +##此处填写阿里云帐号 SecretKey
  8 +$secretKey = 'XXXX';
  9 +## 接入点地址,购买实例后从控制台获取
  10 +$endPoint = 'XXXX.mqtt.aliyuncs.com';
  11 +##实例 ID,购买后从控制台获取
  12 +$instanceId = 'XXXX';
  13 +## MQTT 第一级 Topic 需要在 MQTT 控制台提前申请
  14 +$topic = 'XXXX';
  15 +## MQTT 客户端ID 前缀, GroupID,需要在 MQTT 控制台申请
  16 +$groupId = 'GID_XXXX';
  17 +## MQTT 客户端ID 后缀,DeviceId,业务方自由指定,需要保证全局唯一,禁止 2 个客户端连接使用同一个 ID
  18 +$deviceId = 'XXXX';
  19 +$qos = 0;
  20 +$port = 1883;
  21 +$keepalive = 90;
  22 +$cleanSession = true;
  23 +$clientId = $groupId . '@@@' . $deviceId;
  24 +echo $clientId . "\n";
  25 +
  26 +$mid = 0;
  27 +## 初始化客户端,需要设置 clientId 和 CleanSession 参数,参考官网文档规范
  28 +$mqttClient = new Mosquitto\Client($clientId, $cleanSession);
  29 +
  30 +
  31 +## 设置鉴权参数,参考 MQTT 客户端鉴权代码计算 username 和 password
  32 +$username = 'Signature|' . $accessKey . '|' . $instanceId;
  33 +$sigStr = hash_hmac("sha1", $clientId, $secretKey, true);
  34 +$password = base64_encode($sigStr);
  35 +echo "UserName:" . $username . " Password:" . $password . "\n";
  36 +$mqttClient->setCredentials($username, $password);
  37 +
  38 +## 设置连接成功回调
  39 +$mqttClient->onConnect(function ($rc, $message) use ($mqttClient, &$mid, $topic, $qos, $clientId) {
  40 + echo "Connnect to Server Code is " . $rc . " message is " . $message . "\n";
  41 + ## P2P消息的二级 topic 是/p2p/,三级 topic 是目标客户端的 clientId
  42 + $mqttP2PTopic = $topic . "/p2p/" . $clientId;
  43 + $mqttClient->publish($mqttP2PTopic, "Hello MQTT PHP Demo", $qos);
  44 +});
  45 +
  46 +## 设置发送成功回调
  47 +$mqttClient->onPublish(function ($publishedId) use ($mqttClient, $mid) {
  48 + echo "publish message success " . $mid . "\n";
  49 +});
  50 +
  51 +
  52 +## 设置消息接收回调
  53 +$mqttClient->onMessage(function ($message) {
  54 + echo "Receive Message From mqtt, topic is " . $message->topic . " qos is " . $message->qos . " messageId is " . $message->mid . " payload is " . $message->payload . "\n";
  55 +
  56 +});
  57 +$mqttClient->connect($endPoint, $port, $keepalive);
  58 +
  59 +
  60 +$mqttClient->loopForever();
  61 +
  62 +echo "Finished";
0 63 \ No newline at end of file
... ...