Example sketches for the new Arduino IDE for ESP8266

Moderator: igrr

User avatar
By perecastor
#39215 You'r wright! those 2 includes files are both working good on this sketch. I can upload it on the esp.
But i can't see any effect of your code in this sketch. what it should do on the web page?
I'm sorry but i'm a realy noob with esp8266. I've done many sketch for my differents projects and all of them are working good.
But this esp8266 is killing me! I'm on it since yesterday on the morning and still not working.
User avatar
By WereCatf
#39227
perecastor wrote:But i can't see any effect of your code in this sketch. what it should do on the web page?
I'm sorry but i'm a realy noob with esp8266. I've done many sketch for my differents projects and all of them are working good.
But this esp8266 is killing me! I'm on it since yesterday on the morning and still not working.


The lineserver.on ( "/togglepin", TogglePin ); tells the webserver that when the user requests the URL http://your.esp.ip/togglepin the server should call the function TogglePin. In TogglePin there's the for-loop that goes through all the arguments passed to that URL, the line if (server.argName(i) == "gpio") compares the name of the argument to "gpio" and if it matches it then translates that argument's value to an integer with atoi() and then proceeds to reverse that pin's state. I didn't change the webpage, I just added the URL-handler. Try opening e.g. http://your.esp.ip/togglepin?gpio=2 in your browser and it should state "OK" and the state of the GPIO2 - pin will have reversed from HIGH to LOW or from LOW to HIGH.

If this still goes over your head you perhaps should start with some C++ - book and come back to the ESP a week or two later.
User avatar
By perecastor
#39229
Sans titre.jpg


I'm maybe a noob with esp, but not stupid.

So your code is the same as this :
Code: Select all// Read the first line of the request
  String req = client.readStringUntil('\r');
  Serial.println(req);
  client.flush();
 
  // Match the request
  int val;
  if (req.indexOf("/gpio/0") != -1)
    val = 0;
  else if (req.indexOf("/gpio/1") != -1)
    val = 1;
  else {
    Serial.println("invalid request");
    client.stop();
    return;
  }

  // Set GPIO2 according to the request
  digitalWrite(2, val);
 
  client.flush();

  // Prepare the response
  String s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>\r\nGPIO is now ";
  s += (val)?"high":"low";
  s += "</html>\n";
 

  // Send the response to the client
  client.print(s);
  delay(1);
  Serial.println("Client disonnected");

  // The client will actually be disconnected
  // when the function returns and 'client' object is detroyed

Isn't it?

I don't want to learn c++, i just want a simple page web with two bouton on and off.
So if "If this still goes over your head you perhaps should start with some C++ - book and come back to the ESP a week or two later." is your last option, thanks your and have a nice day.

ps: i'm a 36 years old guy with some basis on c++ ;) but for me a litle bit far away in the time.
You do not have the required permissions to view the files attached to this post.
User avatar
By WereCatf
#39230 Now you're coming off as rude. I provided you with everything you need to do it and I even explained how it works, all you have to do is modify the webpage to show those buttons you wanted; I am not going to write it all for you, especially when you're being so ungrateful. If you do not know how to make buttons on a webpage then I damn well recommend you go and learn some HTML.