adafruit / Adafruit_CC3000_Library

Library code for Adafruit's CC3000 WiFi breakouts &c
http://www.adafruit.com/products/1469
Other
270 stars 153 forks source link

CC3000 can't connect with MQTT broker using IPAddress Object #150

Closed jefersonla closed 4 years ago

jefersonla commented 9 years ago

I really don't know why, but I found in the Arduino forum (http://forum.arduino.cc/index.php?topic=291523.0) that you need to put IP in reverse order, if you want to use IPAdrress Object with Adafruit_CC3000_Client::connect method. Looking for this method in the code, I found that if you change these lines on the library they will works well with PubSubClient Mqtt Library and IPAdress Object:

   // This part of code
  // --- 1462 ---
  socketAddress.sa_data[2] = destIP >> 24;
  socketAddress.sa_data[3] = destIP >> 16;
  socketAddress.sa_data[4] = destIP >> 8;
  socketAddress.sa_data[5] = destIP;
  // --- 1465 ---
  // Should be
  // ---
  socketAddress.sa_data[2] = destIP ;
  socketAddress.sa_data[3] = destIP >> 8;
  socketAddress.sa_data[4] = destIP >> 16;
  socketAddress.sa_data[5] = destIP >> 24;
  // ---
  // Or
  // ---
  socketAddress.sa_data[2] = destIP[0];
  socketAddress.sa_data[3] = destIP[1];
  socketAddress.sa_data[4] = destIP[2];
  socketAddress.sa_data[5] = destIP[3];
  //---

But I'm curious, is this only happening with me and the dude who submitted the topic on Arduino Forum, or more people are facing the same problem? I'm using the Arduino IDE version 1.6.3, and PubSubClient (https://github.com/adafruit/pubsubclient/) MQTT Library for arduino. Thx.