title: Publishing multiple buffers in mqttjs
body: <p>So I want to send some bytes from a NodeJs script to my mosquitto server over mqtt. For this I am using the client library <a href="https://github.com/mqttjs/MQTT.js" rel="nofollow noreferrer">MQTT.js</a>. To send raw data, the library supports Buffers (also Strings).</p>
  <p>All of it works just fine until I try to publish multiple bytes (buffers) in a row. This will always result in publishing only the last buffer but multiple times. When I log the same buffers to the console instead of using mqttjs, I get my expected results (increment from 0xfa to 0xff). However, publishing normal Strings in a row works without trouble. The behaviour of this is inexplicable for me.</p>
  <p>Not quite sure if this is a problem from mqttjs, or if I’m just dumb. Would appreciate a short explenation on what i'm doing wrong since i did not find any related issues.</p>
  <pre class="lang-js prettyprint-override"><code>var buf = Buffer.from([0xfa]);
  
  client.on('connect', function () {
    client.subscribe('LED', function (err) {
      if (!err) {
        for (; buf[0] &lt; 0xff; buf[0]++) {
          client.publish('LED', buf);
        }
      }
    })
  })
  </code></pre>
  <p>Expected message (Result from logging to the console <strong>instead</strong> of publishing):</p>
  <pre><code>&lt;Buffer fa&gt;
  &lt;Buffer fb&gt;
  &lt;Buffer fc&gt;
  &lt;Buffer fd&gt;
  &lt;Buffer fe&gt;
  </code></pre>
  <p>Message that mosquitto receives:</p>
  <pre><code>&lt;Buffer ff&gt;
  &lt;Buffer ff&gt;
  &lt;Buffer ff&gt;
  &lt;Buffer ff&gt;
  &lt;Buffer ff&gt;
  </code></pre>
  <p>A funny discovery i made. If you put the publish before the loop (buf[0] = 0xfa):</p>
  <pre class="lang-js prettyprint-override"><code>client.publish('LED', buf)
  for (; buf[0] &lt; 0xff; buf[0]++) {;}
  </code></pre>
  <p>The output is still:</p>
  <pre><code>&lt;Buffer ff&gt;
  </code></pre>