繁体   English   中英

使用paho mqtt的javascript版本订阅主题时,无法应用通配符

[英]Can't apply wildcard when subscribe to a topic with the javascript version of paho mqtt

首次测试MQTT Paho javascript库,并且以下代码是文档中提供的默认示例。 一旦我尝试使用通配符“#”订阅主题(例如'hermes /#'),就会出现此错误:

onConnectionLost:AMQJS0005E内部错误。 错误消息:AMQJS0009E格式错误的UTF数据:80 -42。,堆栈跟踪:错误:AMQJS0009E格式错误的UTF数据:80 -42。

该文档确实非常简洁,无论如何也没有提及通配符,是js库缺少功能还是有其他方法?

    <!DOCTYPE html>
<html>
  <head>
  <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
  <script src="paho-mqtt.js" type="text/javascript"></script>
  <script type="text/javascript">

        var mqtt;
        var reconnectTimeout = 2000;
        var host="mywairaspi.local"; //change this
        var port= 8080;

// Create a client instance
client =  new Paho.MQTT.Client(host,port,'60');

// set callback handlers
client.onConnectionLost = onConnectionLost;
client.onMessageArrived = onMessageArrived;

// connect the client
client.connect({onSuccess:onConnect});

// called when the client connects
function onConnect() {
  // Once a connection has been made, make a subscription and send a message.
  console.log("onConnect");
  client.subscribe("/World");
  client.subscribe('hermes/#');
  message = new Paho.MQTT.Message("Hello");
  message.destinationName = "/World";
  client.send(message); 
}

// called when the client loses its connection
function onConnectionLost(responseObject) {
  if (responseObject.errorCode !== 0) {
    console.log("onConnectionLost:"+responseObject.errorMessage);
  }
}

// called when a message arrives
function onMessageArrived(message) {
  console.log("onMessageArrived:"+message.payloadString);
}
</script>

  </head>
  <body>
  </body>

</html>

我相信您会在PAHO客户端中看到一个错误,因为肯定支持通配符。 截至2018年11月,如果接收到的任何消息都是原始二进制数据(或根本没有解析为有效的UTF),那么它将给出``格式错误的UTF数据''错误。

已在github上添加了pull-request,已为我修复了该请求,并希望它将很快合并到一个发行版中: https : //github.com/eclipse/paho.mqtt.javascript/pull/178

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM