Hi every One
I'm using NodeMCU board to communicate a laptop through WiFi. Basic communication is ok with a code like this:
Code:
void loop (){
WiFiClient client = server.available();
if (client) {
while (client.connected()){
client.println(Data_mem[0]);
delay(2000);
}
client.stop(); // tarminates the connection with the client
}
}
But when i want to send data a Timer Tick, it seems the client couldn't connect to me.
I arduino serial monitor, i see only this:
40ms_Data A \r\n
40ms_Data A \r\n
....
So, could any one help me? maybe it a problem of WiFiClient deceleration in a non-forever loop (like example 1). But i have no idea to fix it.
Thanks
Most popular in client-server communication is that the client initiates the comunication. The server just responds.
The server usually does not send data without dedicated request by the client.
But it should be possible. But the client needs to be prepared for this.
Maybe some client side code (js, ajax ... I don't know) is necessary.
What commands do you use?
From what you said, you are seemingly running the server in your laptop (first code above) and a client at the ESP8266 (second code above), not the usual approach. Anyway, at the server side, you are calling a 2 seconds delay which will make it unavailable most of the time. Another point to remark: You didn' show the Loop() content of the client side, is the 2nd code within it? If yes, the 2s delay on the server side perhaps explains why client became at unconnected state.
Most popular in client-server communication is that the client initiates the comunication. The server just responds.
The server usually does not send data without dedicated request by the client.
But it should be possible. But the client needs to be prepared for this.
Maybe some client side code (js, ajax ... I don't know) is necessary.
What commands do you use?
I don't understand what you mean by this question: What commands do you use?
The ESP8266 is server and PC is client. Now, in this test code, the client is Packet Sender application. After i connect my PC to the Node MCU access point(i configured it so) and then connect to the 192.168.1.1 that is Node MCU(i configured it so). After that PC as a client connected to Node MCU, Node MCU start to send 1KB data every 40ms to PC.
You should have mentioned this from the 1st post. From what you have presented it did not appear to be the same program, since you implemented both Client and Server in the Arduino code.
Then not the server initiates the communication, but the clinet, maybe with some client side script:
PC requests periodically information (with js) and ESP just responds..