title: Mosquitto socket read error Arduino client
body: <p>I have just downloaded the latest Arduino Library code from Github, and it's broken my MQTT client program.  I'm using PubSubClient 1.91 on Arduino, and Mosquitto 1.1.2 (Build 2013-03-07) on Mac OSX. (I also tested against Mosquitto on Windows 7, same problem.)</p>
  
  <p>The supplied Mosquitto clients work fine, (Mac over to Windows, Windows over to Mac) so it's some problem with what's coming from the Arduino end. A wireshark trace shows the Arduino client sending the following data packet:</p>
  
  <p>10:15:ff:ff:4d:51:49:73:64:70:03:02:00:0f:00:07:41:72:64:75:69:6e:6f</p>
  
  <p>And the Mosquitto broker shows:
  New connection from 10.0.0.115
  Socket read error on client (null), disconnecting.</p>
  
  <p>Before I start to crawl through the MQTT spec, can anyone see anything wrong with the data packet being sent? It's got to be something to do with new Arduino library code... </p>
  
  <p><em>*</em> Update
  Upon further investigation, it appears to be a code generation problem with avr-g++, although life experience tells me it will turn out not to be so. Here is a snippet of code from PubSubClient.cpp</p>
  
  <pre><code>boolean PubSubClient::connect(char *id, char *user, char *pass, char* willTopic,     uint8_t willQos, uint8_t willRetain, char* willMessage) {
     if (!connected()) {
        int result = 0;
  
        if (domain != NULL) {
          result = _client-&gt;connect(this-&gt;domain, this-&gt;port);
        } else {
          result = _client-&gt;connect(this-&gt;ip, this-&gt;port);
        }
  
        if (result) {
           nextMsgId = 1;
           uint8_t d[9] = { 0x00, 0x06, 'M','Q','I','s','d','p',MQTTPROTOCOLVERSION};
  //         d[0] = 0;
  //         d[1] = 6;
           Serial.print("d[0]="); Serial.println(d[0],HEX);
  </code></pre>
  
  <p>Now, the result of the Serial.print just above turns out to be 0xFF !!! So, the uint8_t array is not being initialised correctly. @knoleary Your pointer to the bad FF bytes lead me to this.</p>
  
  <p>If I now uncomment the two lines above, and manually initialise the first 2 bytes to 0 and 6, all works fine, and my program communicates happily with Mosquitto. </p>
  
  <p>I've looked at the generated code, but I'm not an Atmel expert. </p>
  
  <p>Does anyone have any clue why this might be? </p>
  
  <p>I'm compiling using the AVR-G++ toolset from Arduino 1.05, in Eclipse.</p>
  
  <p>I'm going for a beer!</p>