Example sketches for the new Arduino IDE for ESP8266

Moderator: igrr

User avatar
By andrew melvin
#13329 Actually.....

I just modified the header and c++ file to return an argument that is already there...

Works a treat...

1) add this to the public part of ESP8266WebServer.h
````` int argcount();```````
2) add this to the ESP8266WebServer.cpp
````````
int ESP8266WebServer::argcount()
{

return _currentArgCount;
}
`````````


now when you want the number of arguments call

server.argcount();

returns an int. The only thing I'm not sure about is that the argcount variable in the class is defined as a size_t, not int... it works and doesn't throw any errors... but i've only been using c, for about 3 weeks so this is all very new to me.
User avatar
By Hack
#13930 I'm trying to build a 'configuration' page that builds an HTML list the user can use to select the network the user wants to connect to. I'm using the webserver example as a starting point.

This works:
Code: Select all  Serial.println("Scanning for networks...");
  int n = WiFi.scanNetworks();
  Serial.println("Scan complete.");

  server.send(200, "text/html", "<HTML><title>Tricket Config</title><form>SSID:<select name='ssid'>");
  for (int i = 0; i < n; ++i){
    server.send(200,"<option>");
    server.send(200,WiFi.SSID(i));
    server.send(200,"</option>");
  } 
  server.send(200,"</select><br>Password:<br><input type='text'name='pw'></form>");



But it includes the HTTP header. Other Arduino Wifi library examples show the use of client.print, but that doesn't seem to work with this library. I've looked through the source and I can't figure out how to emulate client.print or client.println.

Anyone know how I can make this work?
User avatar
By lakaszus
#13955 I construct the page as a String, then I send it...

Code: Select all...

String header = "<!DOCTYPE html><html><title>ESP8266</title><head></head><body><BR>";
String footer = "</body></html>";

...

void handle_wlan() {
  int n = WiFi.scanNetworks();

  String s = header;
  s += "<form>SSID: <select name='ssid'>";
  for (int i = 0; i < n; ++i) {
    s += "<option>";
    s += WiFi.SSID(i);
    s += "</option>";
  }
  s += "</select><br>Password: <input type='text'name='pw'></form>";
  s += footer;
  server.send(200, "text/html", s);
}

...