MQTT knolleary connection issue in loop

Hi,
I have an issues with connection to MQTT in loop check.
Does anyone had similar issues?

Why knolleary is losing connection in loop? When I'm trying to connect while setup it works fine.

Sample code:

byte mqtt_server[] = { 192,168, 1, 11 };
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
byte ip[] = { 192, 168, 1, 100 }; 

EthernetClient ethClient;
PubSubClient mqtt_client(mqtt_server, 1883, callback, ethClient);

void callback(char* topic, byte* payload, unsigned int length) {
  payload[length] = '\0';
  String strPayload = String((char*)payload);
  Serial.println("IN: " + strPayload);
  
  executeRemoteCommand(strPayload);
}


void setup() {
  Serial.println("BEGIN - setup");
  Ethernet.begin(mac, ip);
  pinMode(HALOGEN_BUTTON_PIN, INPUT);
  pinMode(HALOGEN_RELAY_PIN, OUTPUT);  
  Serial.begin(9600);

  
}

void loop() {
  
  
  if (!mqtt_client.connected()) {
    delay(1000);
    Serial.println("Connecting to Mosquitto");
    if (mqtt_client.connect("ArduinoClient")) {
      mqtt_client.publish("/houseIn", "jop#1");
    Serial.println("Connected to Mosquitto");
    }
  } else {
    halogenButtonState = digitalRead(HALOGEN_BUTTON_PIN);
      if (halogenButtonState == HIGH) {
         Serial.println("Change");
        mqtt_client.publish("/houseIn", "halogen#1");
      }
  }
  
  
  mqtt_client.loop();
  }

MQTT can't connect even once

thanks in advance!!

Why are you pissing away resources on the String class? Is it really that difficult to type TWO Serial.print() statements? If the executeRemoteCommand() function REQUIRES a String, select all of it, and delete it and start over.

Where IS the executeRemoteCommand() function?

lonas:
I have an issues with connection to MQTT in loop check.
Does anyone had similar issues?

Why knolleary is losing connection in loop? When I'm trying to connect while setup it works fine.

hi ionas,

i just got a cc3000 myself and have the exact same problem.
a mqtt message is published correctly when located in setup.
when i put a publish into the loop it seems to lose connection.

did you find out why?

thx