     }
 
 	//Publish payload to MQTT broker
-	if (mqttClient.publish(topic, msg))
+	if (mqttClient.publish(MQTT_TOPIC, msg))
 	{
 		Serial.print("Following data published to MQTT broker: ");
 		Serial.print(topic);

// MQTT server deliveres data to the Domoticz server running on a same Raspberry Pi
{

  // Create MQTT topic and convert it to char array
	String topicStr = "/actions/domoticz/";
	topicStr.concat(topicID);
	topicStr.toCharArray(topic, topicStr.length()+1);

	// Convert payload to char array
	payload.toCharArray(msg, payload.length()+1);


char subscribeTopic[ ] = MQTT_SUBSCRIBE_TOPIC; // Arduino will listen this topic for incoming MQTT messages from the Domoticz. The MQTT_SUBSCRIBE_TOPIC is defined in Arduino_Cottage_Monitoring_System.h header file

//MQTT variables
//String topicID = MQTT_TOPIC; // MQTT topic used in data transmission to the Domoticz. The MQTT_TOPIC is defined in Arduino_Cottage_Monitoring_System.h header file
int temperatureSensordtype = 80; // dtype (device type for temperature sensor) is used to help creating MQTT payload
int switchdtype = 32; // dtype (device type for door switches and siren) is used to help creating MQTT payload
const int temperatureSensorIDX = 18; // IDX number of temperature sensor
