Getting ESP to send command to Arduino using I2C

Hello I wanted to send the command from ESP to Arduino by I2C lines, where nano is master and ESP is slave but they switch in between states successfully, but it does not display on Arduino. I really hope someone can help me with this as I've been stuck for days on this. here are the codes:
ESP

#include <Wire.h>
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
int t;
signed int x;

void setup(void)
{
   Wire.begin(D6, D7); 
   Wire.begin(4);
  Serial.begin(115200);
  init_module1_clock = true;
}
void loop(){
{ // module 1
    static unsigned long module_time, module_delay;
    static bool module_doStep;
    static unsigned char timer_state; // state variable for module 1
    static int delay_time;

    if (init_module1_clock) {
      module_delay = 1;
      module_time = millis();
      module_doStep = false;
      init_module1_clock = false;
      timer_state = 0;
    }
    else {
      unsigned long m = millis();
      if ( ( (long)(m - module_time) ) >= module_delay ) {
        module_time = m; module_doStep = true;
      }
      else module_doStep = false;
    }

    if (module_doStep) {
      switch (timer_state) {
        
        case 0:
          delay_time = 19;
          timer_state = 1;
          break;
          
        case 1:
          delay_time--;
          if (delay_time <= 0)
          {
            timer_state = 2;
            trigger = true;
          }
          break;
        case 2:
          if (state == TriggerIamMaster)
            timer_state = 3;
          else timer_state = 2;
          break;

        case 3:

          Wire.write(x & 0x000000FF );
        Serial.println(x);

          
          //  Serial.println(c);
          timer_state = 0;
          trigger = false;
         break;
        default: timer_state = 0; 
      }
    }
  }
  server.handleClient();
}
void receiveEvent(int howMany)
{
  while( Wire.available()) // loop through all but the last
  {
  Wire.write(x);    
}
}
}

Nano code:

int t, ;
void setup() {
Wire.begin(8);
Wire.onRequest(requestEvent);
  Serial.begin(9600);
  priority = 0;
}
void loop() {
  { // module 12 - ESP
    static unsigned long module_time, module_delay;
    static bool module_doStep;
    static unsigned char espstate; // state variable for module 1
    static int delay_time;

    if (init_module12_clock) {
      module_delay = 1;
      module_time = millis();
      module_doStep = false;
      init_module12_clock = false;
      espstate = 0;
    }
    else {
      unsigned long m;
      m = millis();
      if (((long)(m - module_time)) > module_delay) {
        module_time = m; module_doStep = true;
      }
      else module_doStep = false;
    }

    if (module_doStep) {
      switch (espstate)
      {
        case 0:
          delay_time = 17;
          espstate = 1; 
          break;
        case 1:
          delay_time--;
          if (delay_time <= 0)
          {
            espstate = 2;
            trigger = true;
          }
          break;
        case 2:
          if (state == TriggerIamMaster) espstate = 3;
          else espstate = 2;
          break;

        case 3:
    uint8_t n = Wire.requestFrom(4, 1);
    if (n==1){
   uint8_t  g =  Wire.read();
   long x = Wire.read()
                | (Wire.read() << 8);
     Serial.println(x);
    }
          if (x == 97) {
            priority = 0;
          }
          if (x == 98) {
            priority = 1;
          }
          if (x == 99) {
            priority = 2;
          }
          if (x == 0x64) {
            MAINTENANCE = true;
          }
          if (x == 0x65) {
            Barrier = true;
          }
          if (x == 0x66) {
            Race = true;
          }
          if (x == 0x67 ) {
            RGB == false;
          }
          if (x == 0x68) {
            Hazard = true;
          }
          if (x == 0x69) {
            Emergency = true;
          }
          if (x == 0x6A) {
            Doctor = true;
          }
          if (x == 0x6B) {
            PoliceCar = true;
          }
          break;
        default: espstate = 0;
      }
    }
  }
  shiftByteMSF(ledState);
}

void receiveEvent() {
 Wire.read();
}

void requestEvent() {
Wire.write(t);
}

ps I have not included all of code as there is a total of 12 modules that work perfectly only this one is not as it differs from rest and works by using wire library that gives me headache

The Nano kind that has 5V on its GPIO pins and is connected directly to a 3.3V ESP32?

A ESP32/ESP8266 is not 5V tolerant. A ESP GPIO pins are 3.3V. Putting 5V onto the ESP's pins can destroy the pins or the ESP.

In the upper right hand corner is a input text box labeled "Search Forums". Do a search on the words "level shifter". Much has been written on the subject.

I have created safety circuitry

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