 uint32_t lastReconnectAttempt = 0;  // MQTT last attempt reconnection number
 bool boot = true;
 bool ir_lock = false;  // Primitive locking for gating the IR LED.
+uint32_t sendReqCounter = 0;
 
 #ifdef MQTT_ENABLE
+String lastMqttCmd = "None";
+uint32_t lastMqttCmdTime = 0;
+
+
 // MQTT client parameters
 void callback(char* topic, byte* payload, unsigned int length);
 PubSubClient mqtt_client(MQTT_SERVER, MQTT_PORT, callback, espClient);
 // Create a unique MQTT client id.
-const char* mqtt_clientid = String(MQTTprefix +
-                                   String(ESP.getChipId(), HEX)).c_str();
+String mqtt_clientid = MQTTprefix + String(ESP.getChipId(), HEX);
 #endif  // MQTT_ENABLE
 
 // Debug messages get sent to the serial port.

  // Make a copy of the callback string as strtok destroys it.
  char* callback_c_str = strdup(callback_str.c_str());
  debug("MQTT Payload (raw): " + callback_str);

  // Get the numeric protocol type.
  int ir_type = strtoul(strtok_r(callback_c_str, ",", &tok_ptr), NULL, 10);

      break;
#endif
  }
  sendReqCounter++;
  // Release the lock.
  ir_lock = false;

