     }
 
 	//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);


		Serial.println();
	}
	else
		Serial.println(F("Publishing to MQTT broker failed"));
}

// mqttCallback function handles message arrived on subscribed MQTT topic(s)
void mqttCallback(char* topic, byte* payload, unsigned int length) {
  Serial.print(F("MQTT message arrived ["));
  Serial.print(topic);
  Serial.print("] ");
  for (int i = 0; i < length; i++) {
    Serial.print((char)payload[i]);
  }
  Serial.println();

  // Receive data to be parsed
  Serial.println(F("Starting parsing received data..."));
  char *rest; // Help variable needed with following iterations
  
  //  First strtok iteration. Parses IDX number out from the received data.
  //receivedIDX = atoi (strtok_r((byte*)payload,":",&rest)); // Received IDX is converted to int with atoi function in order to use it as constructor parameter and with switch structure
  receivedIDX = atoi (strtok_r(payload,":",&rest));
  Serial.print(F("IDX = "));
  Serial.println(receivedIDX);

  //  Second strtok iteration. Parses status of device out from the received data.
  deviceStatus = atoi (strtok_r(NULL,":",&rest)); // Received dtype is converted to int with atoi function in order to use it as constructor parameter and with switch structure
  Serial.print(F("Status of device = "));
  Serial.println(deviceStatus);

  //Act according to the received data
  if (receivedIDX == sirenIDX && deviceStatus == 0) // Siren to be set Off
  {
    sirenOffFunction();
    Serial.println(F("Siren turned off"));
    sendMQTTPayload("MQTT command executed");
  }
  else if (receivedIDX == sirenIDX && deviceStatus == 1) // Siren to be set On
  {
    digitalWrite(sirenPin, HIGH);
    Alarm.timerOnce(sirenWatchDogTimer, sirenOffFunction); // Timer is set which will turn off siren after sirenWatchDogTimer period has elapsed
    Serial.println(F("Siren turned on"));
    sendMQTTPayload("MQTT command executed");
  }
  else //Not valid state. No actions to be taken
  {
    Serial.println(F("Incorrect IDX and/or status received"));
    sendMQTTPayload("MQTT command failed");
  }
}

