   DEBUG_PRINTLN();
 }
 
-// Process Ethernet communication
+// Process serial communication using Modbus protocol
 void communicate() {
-  /*
-  DEBUG_WRITETIME();
-
-  // manage connection
-  unsigned long inactiveSpan = millis() - commTime;
-  
-  if (clientConnected) {
-    if (inactiveSpan > DISCONN_TIME) {
-        DEBUG_PRINTLN("Disconnecting inactive client");
-        client.stop();
-        clientConnected = false;
-    } else if (client.connected()) {
-      DEBUG_PRINTLN("Client is still connected");
-    } else {
-      client.stop();
-      clientConnected = false;
-      DEBUG_PRINTLN("Client has been disconnected");
+#ifndef DEBUG
+  // wait for the request 00 03 00 00 00 0A C4 1C
+  boolean sendResponse = false;
+  while (Serial.available() > 0) {
+    byte inByte = (byte)Serial.read();
+    
+    if (inByte == 0x1C) {
+      sendResponse = true;
     }
   }
-
-  if (!clientConnected) {    
-    // connection is considered to be established only when data are received
-    client = server.available();
-    if (client) {
-      clientConnected = true;
-      DEBUG_PRINTLN("New client is connected");
-    } else {
-      DEBUG_PRINTLN("Client is not connected");
-    }
-  }
-
-  // communicating
-  if (clientConnected) {
-    // wait for the request 00 00 00 00 00 06 01 03 00 00 00 0A
-    DEBUG_PRINT("Receiving data: ");
-    boolean sendResponse = false;
-    while (client.available() > 0) {
-      DEBUG_PRINT("_");
-      char c = client.read();
-      DEBUG_PRINTHEX(c);
-  
-      if (c == 0x0A) {
-        sendResponse = true;
-        commTime = millis();  
-        inactiveSpan = 0;
-        client.flush(); // clear input buffer
-        break;
-      }
-    }
-    DEBUG_PRINTLN();
-  
-    // send response
-    if (sendResponse) {
-      DEBUG_PRINTLN("Sending response");
-      client.write(modbusHeader, MODBUS_HDR_LEN);
-      client.write((byte*)&dhtH, 4);
-      client.write((byte*)&dhtT, 4);
-      client.write((byte*)&dsT, 12);
-    } else {
-      DEBUG_PRINTLN("Response not required");
-    }
-  }
-  
-#ifdef USE_WATCHDOG
-  // reset Watchdog timer if client is active
-  if (inactiveSpan <= REINIT_TIME) {
-    wdt_reset();
-  }
-#else
-  // reinit Ethernet if client can't connect
-  if (inactiveSpan > REINIT_TIME) {
-    initEthernet();
-  }
-#endif
-  
-  DEBUG_WRITETIME();
-  DEBUG_PRINTLN();
-  */
+  
+  // send response
+  if (sendResponse) {
+    memcpy(modbusBuf + 3, (byte*)&dhtH, 4);
+    memcpy(modbusBuf + 7, (byte*)&dhtT, 4);
+    memcpy(modbusBuf + 11, (byte*)&dsT, 12);
+    unsigned short crc = CRC16(modbusBuf, MODBUS_BUF_LEN - 2);
+    memcpy(modbusBuf + 23, (byte*)&crc, 2);
+    Serial.write(modbusBuf, MODBUS_BUF_LEN);
+  }
+#endif
+}
+
+// The function returns the CRC as a unsigned int type (2 bytes)
+unsigned int CRC16(byte* buf, unsigned int len)
+{
+  byte crcHi = 0xFF;
+  byte crcLo = 0xFF;
+  unsigned int index;
+  while (len--)
+  {
+    index = crcLo ^ *buf++;
+    crcLo = crcHi ^ crcHiTable[index];
+    crcHi = crcLoTable[index];
+  }
+  return (crcHi << 8 | crcLo);
 }
 
 void setup() {
   Serial.begin(9600);
-  Serial.println("SERIAL TH meter started");
+  DEBUG_PRINTLN();
+  DEBUG_PRINTLN("SERIAL TH meter started");
   initDHT();
   initDS();
   DEBUG_PRINTLN();

float dsT[ONE_WIRE_CNT] = { EMPTY_VAL, EMPTY_VAL, EMPTY_VAL };

// Modbus
const byte modbusHeader[MODBUS_HDR_LEN] = { 
  0x00, 0x00, // Transaction identifier
  0x00, 0x00, // Protocol identifier
  0x00, 0x17, // Length
  0x00,       // Unit identifier
  0x03,       // Function code
  0x14        // Byte count (20)
};

// Speed control

#define DHT_TYPE        DHT11  // DHT11 or DHT22
#define ONE_WIRE_CNT    3      // count of 1-wire connections
#define EMPTY_VAL       -100.0 // empty float value of measurement
#define MODBUS_BUF_LEN  25     // length of Modbus RTU output buffer

//#define DEBUG                // write detailed log to Serial port and disable Modbus

#ifdef DEBUG
 #define DEBUG_PRINT(val)       Serial.print(val)
