• mqtt交互协议的交互


    <template>
      <div class="hello">
        <div id="app">
          <p>mqtt收到的数据:</p>
          <input type="text" v-model="this.msg" />
        </div>
      </div>
    </template>

    <script>
    import mqtt from "mqtt";

    const options = {
      // 超时时间
      connectTimeout: 10000,
      // 认证信息
      // clientId: guid,
      username: "emqx-connect-via-websocket",
      password: "emqx-connect-via-websocket",
      clean: true,
    };

    var client = mqtt.connect("ws://192.168.65.13:8083/mqtt", options);


    export default {
      data() {
        return {
          msg: {},
        };
      },
      created() {
        return;
        this.mqttMsg();
        console.log(this.msg);
      },
      methods: {
        mqttMsg() {
          
          client.on("connect", (e) => {
            console.log("连接成功!!!");
            // csot-lkwe
            client.subscribe("testtopic", { qos: 0 }, (error) => {
              if (!error) {
                console.log("订阅成功");
              } else {
                console.log("订阅失败");
              }
            });
          });
          // 接收消息处理
          client.on("message", (topic, message) => {
            console.log(888);
            console.log("收到来自", topic, "的消息", message.toString());
            this.msg = message.toString();
          });
        },
      },
    };
    </script>
        
    <!-- Add "scoped" attribute to limit CSS to this component only -->
    <style  scoped lang="scss">
    </style>
  • 相关阅读:
    day3-python之函数进阶(三)
    day3-python之函数初识(二)
    day3-python之文件操作(一)
    tomcat
    集群
    nginx
    nginx--zabbix监控status waiting
    zabbix监控之mysql主从状态&mysql主从延迟
    zabbix监控之进程&日志监控
    zabbix监控流程(监控linux上某个文件是否有改动)
  • 原文地址:https://www.cnblogs.com/shenbo666/p/13673450.html
Copyright © 2020-2023  润新知