How to fix ku8MBResponseTimedOut

Iam doing like building the communication between two ESP32s using ModbusTCP over WIFI. iam getting error code like 226 response time out how to fix these error can you please tell me.
MASTER CODE

#include <WiFi.h>
#include <ModbusMaster.h>
#include <ModbusTCP.h>

#define SLAVE_ID 1  // Slave device ID
#define READ_START 0// Starting address of holding registers
#define READ_COUNT 10 // Number of holding registers to read

// Replace with your WiFi credentials
const char* ssid = "realme C2";
const char* password = "chchchch";

// Slave Modbus TCP server details
const char* serverIP ="192.168.43.228"; // Modbus slave's IP
const int serverPort = 502;

WiFiClient client;
ModbusMaster node;

void setup() {
  Serial.begin(115200);
  WiFi.begin(ssid, password);
  Serial.println("Connecting to WiFi...");
  
  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.print(".");
  }
  Serial.println("\nConnected to WiFi!");
  
  // Connect to the Modbus TCP server
  if (client.connect(serverIP, serverPort)) {
    Serial.println("Connected to Modbus TCP server.");
  } else {
    Serial.println("Failed to connect to Modbus TCP server. Check IP and Port.");
    while (1);
  }
  
  // Assign the Modbus TCP client to ModbusMaster instance
  node.begin(SLAVE_ID, client);
   node.setTimeout(15000); 
   
}

void loop() {
  uint8_t result;
  uint16_t data[READ_COUNT];
//uint32_t startTime = millis();
//while ((millis() - startTime) < 50000) { // 10-second timeout
  // Send a Modbus read request
  result = node.readHoldingRegisters(READ_START, READ_COUNT);
    Serial.printf("PRAWIN-->  Error code: %d\n", result);
  if (result == node.ku8MBSuccess) {
    Serial.println("Received data from slave:");
    for (uint8_t i = 0; i < READ_COUNT; i++) {
      data[i] = node.getResponseBuffer(i);
      Serial.printf("Register %d: %d\n", READ_START + i, data[i]);
    }
  } else if (result == node.ku8MBResponseTimedOut) {
        Serial.println("Error: Response timed out. Check slave connectivity and settings.");
        Serial.printf("Failed to read holding registers. Error code: %d\n", result);

    } else {
        Serial.printf("Failed to read holding registers. Error code: %d\n", result);
    }
 //}
  delay(60000); // 4 min
}
SLAVE CODE

#include <WiFi.h>
#include <ModbusTCP.h>

// Replace with your Wi-Fi credentials
const char* ssid = "realme C2";
const char* password = "chchchch";

// Create Modbus server object
ModbusTCP modbusServer;

// Number of registers to hold random values
const int numRegisters = 10;

// Buffer to store the values
uint16_t dataBuffer[numRegisters] = {0};

// Counter for sent updates
int updateCount = 0;

void setup() {
Serial.begin(115200);

// Connect to Wi-Fi
Serial.print("Connecting to Wi-Fi");
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.print(".");
}
Serial.println("\nConnected to Wi-Fi");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());

// Start Modbus server
modbusServer.begin();
Serial.println("Modbus server started");

// Add holding registers for random values
for (int i = 0; i < numRegisters; i++) {
modbusServer.addHreg(i, 1); // Initialize registers from 0 to numRegisters-1 with 0
}
}

void loop() {
// If 10 updates are already sent, stop the server and disconnect clients
if (updateCount >= numRegisters) {
Serial.println("10 values sent. Stopping server and disconnecting clients.");
while (true) {
// Handle incoming Modbus TCP requests but do not update values
modbusServer.task();
}
}

// Handle incoming Modbus TCP requests
modbusServer.task();

// Update holding registers with random data
for (int i = 0; i < numRegisters; i++) {
updateCount++; // Increment the update counter
uint16_t number = random(1, 100); // Generate random number between 1 and 99
modbusServer.Hreg(i, number); // Update holding register at address i
dataBuffer[i] = number; // Store the value in the buffer
Serial.print("Register ");
Serial.print(i);
Serial.print(": ");
Serial.println(dataBuffer[i]); // Print the buffered value
}
delay(1000); // Update every second
}

please help me guys....

I have deleted your other cross-post @prawinuu .

Cross-posting is against the Arduino forum rules. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend a lot of time investigating and writing a detailed answer on one topic, without knowing that someone else already did the same in the other topic.

Repeated cross-posting can result in a suspension from the forum.

In the future, please only create one topic for each distinct subject matter. This is basic forum etiquette, as explained in the "How to get the best out of this forum" guide. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.