You are reading a single comment by @Ickis and its replies. Click here to read the full conversation.
  • ok. this problem solved by setting options when 'create'

    but i have next one. i can see messages in debug, but mqtt module give me error again

    function mqttRun(){
      var server = 'my_broker';
      var options = {
              keep_alive: 60,
              port: my_port,
              clean_session: my_port,
              client_id: "my_id",
              username: "my_user",
              password: "my_pass",
              protocol_name: "MQTT",
              protocol_level: 4,
      };
      var mqtt = require("MQTT").create(server, options); // changes here
        mqtt.on('connected', function() {
        mqtt.subscribe("/test");
      });
       mqtt.on('publish', function (pub) {  // this place throw error
        console.log("topic: "+pub.topic);
        console.log("message: "+pub.message);
      });
    
      mqtt.connect();
    
    }
    
    

    Uncaught Error: Field or method "topic" does not already exist, and can't create it on undefined

About

Avatar for Ickis @Ickis started