   Serial.print(temperature);
   Serial.println(F("DegC"));
 
-  topicID = "Meriroom";
-  dtype = "80";
-  deviceType = atoi (dtype); // dtype is converted to int in order to use it with switch structure below and other functions
-
   //Measured temperature (float) is converted to char array
   char charVal[10];	//Temporarily holds data for dtostrf function
   dtostrf(temperature, 4, 1, charVal);  //4 is minimum width, 1 is precision; float value is copied into buff
   temp = charVal;
 
   //Send data to MQTT broker running on a Raspberry Pi
-  sendMQTTPayload(createMQTTPayload());
-}
-
-String createMQTTPayload() //Create MQTT message payload. Returns created message as a String.
-{
-
-	String dataMsg = "{\"dunit\":1,";
-	dataMsg.concat(F("\"dtype\":"));
-
-	switch (deviceType)
-	  {
-		case 82: // Combined temperature and humidity sensor
-	    	dataMsg.concat(dtype);
-	    	dataMsg.concat(F(",\"dsubtype\":1,"));
-	    	dataMsg.concat(F("\"svalue\":\""));
-	    	dataMsg.concat(temp);
-	    	dataMsg.concat(F(";"));
-	    	dataMsg.concat(hum);
-	    	dataMsg.concat(F(";0"));
-	    	break;
-
-		case 80: // Temperature sensor
-			dataMsg.concat(dtype);
-	    	dataMsg.concat(F(",\"dsubtype\":1,"));
-	    	dataMsg.concat(F("\"svalue\":\""));
-	    	dataMsg.concat(temp);
-	    	break;
-
-		default: // If dtype is unknown, then default case to be used. Default case is a temperature sensor.
-			Serial.println("Unknown dtype received. Default procedure to be done.");
-			dataMsg.concat(dtype);
-	    	dataMsg.concat(F(",\"dsubtype\":1,"));
-	    	dataMsg.concat(F("\"svalue\":\""));
-	    	dataMsg.concat(temp);
-	    	break;
-	  }
-
-	dataMsg.concat(F("\"}"));
-	return dataMsg;
+  sendMQTTPayload(createMQTTPayload(tempSensorIDX, temperatureSensordtype)); //Send data to MQTT broker running on a Raspberry Pi
+}
+
+String createMQTTPayload(int idx, int deviceType) //Create MQTT message payload. Returns created message as a String.
+{
+  String dataMsg = "{\"idx\":";
+  dataMsg.concat(idx);
+  dataMsg.concat(F(",\"nvalue\":0"));
+
+  switch (deviceType)
+    {
+    case 80: // Temperature sensor.
+        dataMsg.concat(F(",\"svalue\":\""));
+        dataMsg.concat(temp);
+        dataMsg.concat("\"}");
+        break;
+
+    case 82: // Temperature & humidity sensor
+        dataMsg.concat(F(",\"svalue\":\""));
+        dataMsg.concat(temp);
+        dataMsg.concat(F(";"));
+        dataMsg.concat(hum);
+        dataMsg.concat(F(";0"));
+        dataMsg.concat("\"}");
+        break;
+
+    default: // If dtype is unknown, then default case to be used. Default case is a temperature sensor.
+      Serial.println(F("Unknown dtype received. Default procedure to be done."));
+        dataMsg.concat(F(",\"svalue\":\""));
+        dataMsg.concat(temp);
+        dataMsg.concat("\"}");
+        break;
+    }
+
+  return dataMsg;
 }
 
 void sendMQTTPayload(String payload) // Sends MQTT payload to the Mosquitto server running on a Raspberry Pi.

		Serial.println();
		digitalWrite(RxLed, LOW);

		char *rest; // help variable

		Serial.println("Starting parsing received data...");

		//  First strtok iteration. Parses topicID out from the received data.
		topicID = strtok_r((char*)buf,":",&rest);
		Serial.print("topicID = ");
		Serial.println(topicID);

		//  Second strtok iteration. Parses dtype out from the received data.
		dtype = strtok_r(NULL,":",&rest);
		Serial.print("dtype = ");
		Serial.println(dtype);
		deviceType = atoi (dtype); // dtype is converted to int in order to use it with switch structure below and other functions

		//  Third strtok iteration. Parses temperature out from the received data.
		temp = strtok_r(NULL,":",&rest);
		Serial.print("temp = ");
		Serial.println(temp);

		if (deviceType == 82) // Humidity to be parsed only from combined temp & hum sensors
		{
			//  Fourth strtok iteration. Parses humidity out from the received data.
			hum = strtok_r(NULL,":",&rest);

  clientIDStr.toCharArray(clientID, clientIDStr.length()+1);

  //MQTT connection is established
  Serial.print(F("MQTT client ID: "));
  Serial.println(clientID);
  mqttClient.connect(clientID) ? Serial.println("MQTT client connected") : Serial.println("MQTT client connection failed..."); //condition ? valueIfTrue : valueIfFalse - This is a Ternary operator

  // Start up the Dallas temperature library
