WiFiEsp library

Hi I have 2 qouestions for this library, at least for now proabbaly :slight_smile:

My first question would be why do I get 3 requests when I for example just enter the page in browser.

Here is output in Serial Monitor:

Server started
[WiFiEsp] New client 0
New client
GET / HTTP/1.1
Host:;q=0.9
Accept-Encoding: gzip, deflate
Accept-Language: hr,en-US;q=0.9,en;q=0.8

[WiFiEsp] Disconnecting  0
Client disconnected
[WiFiEsp] New client 0
New client
0,CONNECT

[WiFiEsp] Disconnecting  0
Client disconnected
[WiFiEsp] New client 0
New client
[WiFiEsp] TIMEOUT: 337

I'm not so good when it comes to network,http requests and so on, but I should always have 2 requests cause second is for that flavicon right??

So why is there third request and are those 2 additional requests are smth "bad" for my code?

My second question is when I store web page data in PROGMEM how can I serve a client??

In ESP8266 library I can just use send_P() instead usual send().

Ufffff it's long question sorry and thank you all in advance :slight_smile:

Please read "Read this before posting a programming question" at the top of the forum and post your sketch- all of it- using code tags.

in esp8266 you have ESP8266WebServer. there is WebServer library derived from that but it is merged with a copy of WiFiEsp library so I don't know if you can use it. search in library manager

I think this is the library you mentioned - ESP8266_AT_WebServer by khoih-prog?

But again I have a problem. I’m using arduino uno with esp8266 wifi shield. I’m not sure what do I have to change in code to make it work on uno and I guess I have to change smth cause it doesn’t work like this.

So code and error are in attachments I know you don’t like that but I couldn’t post everything here cause it was to long, sorryyyy

I guess I have to do something whit all these def and ifdef but I don’t know that. I know it’s a looooong question but if you can help me please. HVALAA

Arduino_code.txt (9.87 KB)

Error.txt (9.04 KB)

yes that library.
there are Serials for many boards but no SoftwareSerial for Uno in the example. so remove that all and create SoftwareSerial named EspSerial. don't forget to change the baud rate to 9600 baud for SoftwareSerial

Thank for answering.

But now I have this error:

Sketch uses 32658 bytes (101%) of program storage space. Maximum is 32256 bytes.
Global variables use 3179 bytes (155%) of dynamic memory, leaving -1131 bytes for local variables. Maximum is 2048 bytes.
text section exceeds available space in board
Sketch too big; see http://www.arduino.cc/en/Guide/Troubleshooting#size for tips on reducing it.
Error compiling for board Arduino Uno.

I don't get it how come I have too big sketch if there iust basic and simple web page with authentication?

robo17:
Thank for answering.

But now I have this error:

Sketch uses 32658 bytes (101%) of program storage space. Maximum is 32256 bytes.

Global variables use 3179 bytes (155%) of dynamic memory, leaving -1131 bytes for local variables. Maximum is 2048 bytes.
text section exceeds available space in board
Sketch too big; see http://www.arduino.cc/en/Guide/Troubleshooting#size for tips on reducing it.
Error compiling for board Arduino Uno.




I don't get it how come I have too big sketch if there iust basic and simple web page with authentication?

so now we know why there wasn't a SoftwareSerial for Uno.

so you will have to code a simple web server.

Juraj:
so now we know why there wasn't a SoftwareSerial for Uno.

so you will have to code a simple web server.

I am reeeaaalllyy sorry but I don't understand either sentences.

One more question, I’m back on WiFiEsp library and is it really true that I can’t use ajax requests with it??

<body>
    <div>
    <button onclick="getRate()">Change</button>
    <p id="rate"></p>
    </div>
    <script>
      function getRate(){
          var xhr = new XMLHttpRequest();
          var url = "/ge";
          xhr.onreadystatechange = function() {
            if (this.readyState == 4 && this.status == 200) {
              console.log(this.responseText);
          };
          xhr.open("GET", url, true);
          xhr.send();
        }
      }
    </script>
  </body>

This is client side and on server(esp):

if (buf.endsWith("GET /ge")) {
          Serial.println("Druga str"); 
          sendHttpResponse2(client);
          break;
        }
.
.
.void sendHttpResponse2(WiFiEspClient client)
{
  client.print(
    "HTTP/1.1 200 OK\r\n"
    "Content-Type: text/plain\r\n"
    "Connection: close\r\n" 
    "\r\n");
  client.print(data[0]);
  
}

the sketch didn't fit into memory of Uno.

here in my project I have a web server which responds to Ajax request (and serves static files but that will not work on Uno).

it is written for Ethernet but should compile if you replace 'Ethernet' with 'WiFi'

note: the WiFiEsp library has problems so I wrote a new one last year

Juraj:
the sketch didn't fit into memory of Uno.

here in my project I have a web server which responds to Ajax request (and serves static files but that will not work on Uno).
IsgModbusTcpSG/WebServer.ino at master · jandrassy/IsgModbusTcpSG · GitHub
IsgModbusTcpSG/script.js at master · jandrassy/IsgModbusTcpSG · GitHub
it is written for Ethernet but should compile if you replace 'Ethernet' with 'WiFi'

note: the WiFiEsp library has problems so I wrote a new one last year
GitHub - jandrassy/WiFiEspAT: Arduino networking library. Standard Arduino WiFi networking API over ESP8266 or ESP32 AT commands.

Thanks again for answering.

So if I'm using your library I can send web page from SD with help of client.write() and I can also use AJAX req and res?

robo17:
Thanks again for answering.

So if I'm using your library I can send web page from SD with help of client.write() and I can also use AJAX req and res?

in Uno you can't use a networking library and SD together. there is not enough memory

So if I'm gonna use Uno or Nano I can't use library you mentioned in the beggining and not even your library?

I'm then back on WiFiEsp library in which I can't make AJAX request work and plus I can't use SD along with it?

Juraj sorry for my bad knowledge about all this, really and thank you for answering me.

but you could use Nano Every. it has 3 times more memory, 50% more flash memory, more hardware Serials so you can connect the esp8266 without SoftwareSerial.
but not all sensor libraries work with it

Juraj sorry it' me again.

I don't know that to dooooooo.

I'm back to WiFiEsp library cause others can't run on arduino uno, but I can't do what I want whit this library.

I don't know how to do a simple POST request in browser and to recieve those data in post form aaaaaaa.....

I don't even know what is my question now..

no networking library will reliably work with SD library together on Uno. it is on the limit of the SRAM usage. it applies to WiFiEsp library too. if you don't use SD library, you can use any compatible networking library.

I don't have a good example of url encoded parameters parsing for server.
I needed it only once and I used the C function strtok

       // parse the parameters sent by the html form
       const char* delims = "=&";
       strtok(line, delims);
       const char* ssid = strtok(NULL, delims);
       strtok(NULL, delims);
       const char* pass = strtok(NULL, delims);

I see thank you Juraj.

But I have this question now, this is POST request I get on arduino:

POST / HTTP/1.1
Host: 192.168.1.34
Connection: keep-alive
Content-Length: 39
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
Origin: http://192.168.1.34
Content-Type: application/x-www-form-urlencoded
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Referer: http://192.168.1.34/L
Accept-Encoding: gzip, deflate
Accept-Language: hr,en-US;q=0.9,en;q=0.8

WHERE is post data??

And Juraj maybe I should explain this I don't know eventhough I think you undes+rstand me :slight_smile:

I'm not using my esp as a client to send post request. My esp is a server and I'm making a web page that will have form in it and then after clicking I want that data to be recieved by esp.

But as I said in previous post, in my recieved request I don't have my post data.

the ‘form’

        client.println(F("<form action='/' method='POST'>Enter valid parameters, please.

"));
         client.println(F("SSID:
<input type='text' name='i'>
"));
         client.println(F("Password:
<input type='password' name='p'>

"));
         client.println(F("<input type='submit' value='Submit'></form>"));

the whole sketch is a little tricky
https://github.com/jandrassy/WiFiEspAT/blob/master/examples/Advanced/ConfigurationAP/ConfigurationAP.ino

robo17:
Juraj sorry it' me again.

I don't know that to dooooooo.

I'm back to WiFiEsp library cause others can't run on arduino uno, but I can't do what I want whit this library.

I don't know how to do a simple POST request in browser and to recieve those data in post form aaaaaaa.....

I don't even know what is my question now..

R - Are you trying to do this the hard way?

If you need WiFi, use a board with WiFi. The Uno is a learning board with training wheels. My go-to board is the Wemos D1 Mini or if I need more I/O, the NodeMCU. They both have 4mb of Flash and WiFi. There are example sketches in the IDE for using them as Web Servers.