You are reading a single comment by @jfox and its replies. Click here to read the full conversation.
  • I am running v1.87 on an esp8266. I am able to subscribe to an MQTT broker running on my local network. I can publish and subscribe successfully.

    I am attempting to publish from one esp8266 and subscribe from another. I believe that both boards use the same default client_id, because when I connect the second one, the first is disconnected.

    I would expect to be able to work around this by setting a client_id in the MQTT connection options, as described here:

    My code looks like this:

    var server = "";
            mqtt = require("MQTT").create(server);
                client_id: 'webmos02'
            mqtt.on('connected', function() {
                mqtt.publish('led', 'webmos02 start');
                print('subscribed to led');
            mqtt.on('publish', function(pub) {
                print("topic: " + pub.topic);
                print("message: " + pub.message);

    I get these errors:

    Uncaught Error: Function "write" not found!
     at line 1 col 35
    ....log("Client connected");a.write(b.mqttConnect(b.clie­nt_id))...
    in function "e" called from line 3 col 353
    in function "connect" called from line 1 col 131
    in function called from system

    I have tried putting in other things in the connection options, like _protocolname: "MQTT" and get the same result. I get errors regardless of what I put in as a connection option.

    If I leave out the connection option I am able to connect and both publish and subscribe.

    1. Am I correct in assuming that two different esp8266s without a client_id set will use the same client_id and thus collide?
    2. How do I set a client_id?
    3. Is there possible another way to resolve this issue?


Avatar for jfox @jfox started