Hi.
I want to use ESP8266-07 with usb-to-ttl and arduino sketch.
So I wrote a simple code where in setup() I connect to a wifi modem correctly.
now I want go to loop() function.
I simply added only a serial.println("a").
then I entered module IP Address in web browser (mySTAIP:80) , I don't know why this loop repeats 10 times?
Why 10 times shows "a" in the serial monitor?
#include <ESP8266WiFi.h>
const char* ssid = "my_ssid";
const char* password = "my_pass";
WiFiServer server(80); //Service Port
void setup() {
Serial.begin(115200);
Serial.println();
Serial.println();
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
}
server.begin();
}
void loop() {
// Check if a client has connected
WiFiClient client = server.available();
if (client) {
Serial.println("a");
}
}
With this code I'm surprised it only prints 'a' ten times. It looks like it should print it continuously as long as there is a connection.
void loop() {
// Check if a client has connected
WiFiClient client = server.available();
if (client) {
Serial.println("a");
}
}
I don't know what you are trying to achieve so I don't know what to advise you. I doubt if your eventual goal is just to print 'a'
Another thing is that your code keeps trying to create a connection as often as it possibly can - perhaps thousands of times per second. I would not be surprised if your server gets tired of that.
Robin2:
With this code I'm surprised it only prints 'a' ten times. It looks like it should print it continuously as long as there is a connection.
...R
Hi.As you said,this simple loop() function repeats only 10 times.
while I expect print "a" over and over.
I think that ESP8266 module goes to sleep mode.
sleeping mode really confused me!
I know there is three modes : modem-sleep , light-sleep and deep-sleep.
which of them is best?modem sleep for continues power supply?deep sleep for battery?
and how can I wake up the module from sleep mode?
for example:
I uploaded the below simple code:
this works fine only for 5 attempts from web browser page.
namely I can toggle a LED only for 5 times and then pressing button in web browser page does not affect.
why?
ghasem_eng:
Hi.As you said,this simple loop() function repeats only 10 times. while I expect print "a" over and over.
Well you did not say that in your Original Post.
And what you did say "I don't know why this loop repeats 10 times? Why 10 times shows "a" in the serial monitor?" made me think you expected it only to print the 'a' once.
Try (as a test) adding delay(1000); into your loop() and see what happens.