Arduino Wifi Shield + MQTT problems

Hi everyone,
I am trying to make a arduino uno with a wifi shield to connect to my mqtt server, but I am having no success. I have another one with ethernet shield that works great, can someone help me out?
this is the code:

#include <WiFi.h>
#include <PubSubClient.h>
 
char ssid[] = "V@Z Wifi";     //  your network SSID (name) 
char pass[] = "mypass";    // your network password
int status = WL_IDLE_STATUS;     // the Wifi radio's status

const char* MQTTserver = "192.168.7.3";
const char* myMQQTClientID = "ArduinoClient02";

WiFiClient wfClient;
PubSubClient mqttClient(wfClient);

void setup() {
  // initialize serial:
  Serial.begin(9600);

  // Set MQTT Client
  Serial.println(F("MQQT arduino client by Luis Vaz"));
  Serial.print(F("Hello! My MQTT ClientID is "));
  Serial.println(myMQQTClientID);
 
  
  // attempt to connect using WPA2 encryption:
  Serial.print(F("Attempting to connect to Wifi network with SSID "));
  Serial.print(ssid);
  Serial.println(F("..."));
  status = WiFi.begin(ssid, pass);

  // if you're not connected, stop here:
  if ( status != WL_CONNECTED) { 
    Serial.println(F("Couldn't get a wifi connection. Is your wifi in range?"));
    while(true);
  } 
  // if you are connected, print out info about the connection:
  else
  {
    Serial.println(F("Successfully connected to Wifi network!"));
    printIPAddress();   
  }
  mqttClient.setServer(MQTTserver, 1883);
  mqttClient.setCallback(callback);
  delay(1500);
}

void loop()
{
  if (!mqttClient.connected())
  {
    reconnect();
  }
  mqttClient.loop();
}

void callback(char* topic, byte* payload, unsigned int length) 
{
  Serial.print(F("MQTT message arrived ["));
  Serial.print(topic);
  Serial.print(F("] "));
  for (int i=0;i<length;i++)
  {
    char inChar = (char)payload[i];
    //inMessage = inMessage + inChar;
    Serial.print(inChar);
  }
  Serial.println(F(""));
}

void reconnect()
{
  // Loop until we're reconnected
  while (!mqttClient.connected()) {
    Serial.print(F("Attempting MQTT connection on IP "));
    Serial.print(MQTTserver);
    Serial.println(F("..."));
    // Attempt to connect
    if (mqttClient.connect(myMQQTClientID)) {
      Serial.println(F("Successfully connected to MQTT server!"));
      // Once connected, publish an announcement...
      mqttClient.publish("ArduinoClient01/Messages","Hi there! I'm up and running!");
      // ... and resubscribe
      mqttClient.subscribe("ArduinoClient02/Messages");
    }
    else
      {
        Serial.print(F("Failed to connect to MQTT server, rc="));
        Serial.println(mqttClient.state());
        Serial.println(F("Preparing to try again in 5 seconds..."));
      // Wait 5 seconds before retrying
        delay(5000);
      }
  }
}

void printCurrentNet() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print the MAC address of the router you're attached to:
  byte bssid[6];
  WiFi.BSSID(bssid);
  Serial.print("BSSID: ");
  Serial.print(bssid[5], HEX);
  Serial.print(":");
  Serial.print(bssid[4], HEX);
  Serial.print(":");
  Serial.print(bssid[3], HEX);
  Serial.print(":");
  Serial.print(bssid[2], HEX);
  Serial.print(":");
  Serial.print(bssid[1], HEX);
  Serial.print(":");
  Serial.println(bssid[0], HEX);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.println(rssi);

  // print the encryption type:
  byte encryption = WiFi.encryptionType();
  Serial.print("Encryption Type:");
  Serial.println(encryption, HEX);
  Serial.println();
}

void printIPAddress()
{
  Serial.print(F("My IP address: "));
  for (byte thisByte = 0; thisByte < 4; thisByte++)
  {
    //print the value of each byte of the IP address:
    Serial.print(WiFi.localIP()[thisByte], DEC);
    if(thisByte <3)
      Serial.print(F("."));
  }
  Serial.println(F(""));
}

on the output serial, this is what i get:
MQQT arduino client by Luis Vaz
Hello! My MQTT ClientID is ArduinoClient02
Attempting to connect to Wifi network with SSID V@Z Wifi...
Successfully connected to Wifi network!
My IP address: 192.168.7.178
Attempting MQTT connection on IP 192.168.7.3...
Failed to connect to MQTT server, rc=-2
Preparing to try again in 5 seconds...
Attempting MQTT connection on IP 192.168.7.3...
Failed to connect to MQTT server, rc=-2
Preparing to try again in 5 seconds...
Attempting MQTT connection on IP 192.168.7.3...
Failed to connect to MQTT server, rc=-2
Preparing to try again in 5 seconds...
Attempting MQTT connection on IP 192.168.7.3...
Failed to connect to MQTT server, rc=-2
Preparing to try again in 5 seconds...
Attempting MQTT connection on IP 192.168.7.3...
No Socket available

On the arduino shield it works perfectly, except that using wifi client i use ethernet client. Am I missing something ?

        Serial.print(F("Failed to connect to MQTT server, rc="));
        Serial.println(mqttClient.state());

You should consult the documentation (or source code) for the class that mqttClient is an instance of, to determine what the value, -2, returned by state() means. Then, address that issue.

PaulS:

        Serial.print(F("Failed to connect to MQTT server, rc="));

Serial.println(mqttClient.state());



You should consult the documentation (or source code) for the class that mqttClient is an instance of, to determine what the value, -2, returned by state() means. Then, address that issue.

Which I did, -2 : MQTT_CONNECT_FAILED - the network connection failed

the shield gets and IP on the network, I can ping it, but it seems it can't connect anywhere..

Can you use your ESP shield to connect to ANY server?

I am using the Wifi Shield from arduino (Wifi R3)

vaz83:
I am using the Wifi Shield from arduino (Wifi R3)

Sorry about the mis-identification of the shield. Are you able to get the WiFi shield to connect to ANY server?

PaulS:
Sorry about the mis-identification of the shield. Are you able to get the WiFi shield to connect to ANY server?

yes, I tried to connect to google, with success. I really dont know what is wrong. maybe some compatibility with mqtt?