I have updated my code. is there anything wrong in my coding? and why i still get offline?
How long does it take your sendSensor to execute?
Pete.
timer.setInterval(5000L, sendSensor);
5 seconds
That’s how often your are calling the function. Once called, how long does it take to execute?
Pete.
about 2 seconds
quite fast to execute. I dont know how to fix it the offline issues. If anything wrong in my code, let me know
Could it be a power supply issue?
Are you powering your Mega, ESP-01, LCD display, sensors and relays from the same power supply?
Pete.
all my device connected power from arduino mega. later i show the circuit diagram
i power it from laptop
is there any recommendation I need to fix the power supply issue?
You need a decent stabilised power supply for your ESP-01, preferably independent from your Arduino power supply, but with shared grounds.
You also need to supply your relay coils separately, also with shared grounds to the other power connections.
Pete.
i dont get it what do you mean for esp-01. it means that I have to separate esp-01 but with shared ground with arduino? then, how do i need to supply relay separately?
It means that my esp-01 and relays need to connect to other power supply? is that right? if yes, could you suggest me, how?
Yes
As I said, a separate psu for each, with shared grounds to the GND pin on the Arduino.
Pete.