HII
I am working on a project whether i am connected with webserver and sending data from nodemcu to webserver continuously.
According to the program, in the void setup(), I am connecting my nodemcu to webserver and once connected it jumps to the void loop and continously sends data to tcp server.
But the problem is once TCP server gets closed at that time esp still continues sending data and i want to detect whether nodemcu is connected to server or not?
What is the function that i can use. Ilready scrolled whole the library but got nothing
Can you please help.
I am using #include <ESP8266WiFi.h>
When you say "sending data continuously", that isn't realistic. If you are reading a sensor value every 100 ms, you can't send 10 readings over wifi every second. That just isn't practical for a protocol like wifi. You're going to wind up with a backlog of values to send that will continue to get bigger and your new data will be out of date. So, you aren't going to be able to send data continuously.
What you need to determine is how fast do you want to send data to the server. So, if you wanted to send it to the server every 10 seconds, you would have to either implement a timer or check for the duration since you last sent the data. You will also want to reopen connection to the server each time you want to send the data. It will not keep the connection open permanently. It will open the connection, send the data and then close the connection.
Be careful to not use any delays though...those will trip your ESP8266 watchdog timer.
well thankyou ryancasler,
The issue was i was not able to detect whether my nodemcu was still connected to server or not,
But later on i figured it out in library and used function client.connected(); whih returns true if connected and false if it isnt connected to TCP server.
So in this way i solved it
BTW thanks for your effort :))