-->
Page 1 of 3

ESP8266WebServer.h and variables in string

PostPosted: Thu Sep 21, 2017 4:06 pm
by yonubear
I am hoping someone can help me out i am working on a peice of code on a nodmcu board using ide however when ever i place a variable in the webpage string i don't get the contents of the variable here is a samble of my code


webPage += "<a href=\"/b2on\"\">On LED2</a>";
webPage += "<a href=\"/b2off\"\"> Off LED2</a>";
webPage += WiFi.localIP();
webPage += "<br>";

Re: ESP8266WebServer.h and variables in string

PostPosted: Fri Sep 22, 2017 10:27 am
by martinayotte
WiFi.localIP() doesn't return a string, it is returning an IPAddress, so you have to convert it :
Code: Select allWiFi.localIP().toString()

Re: ESP8266WebServer.h and variables in string

PostPosted: Fri Sep 22, 2017 1:02 pm
by yonubear
that did the trick now i have one more question how can i get this to work?

webPage += String(digitalRead(led));
led is equal to digital port 4 in ide it never changes from 0

Re: ESP8266WebServer.h and variables in string

PostPosted: Fri Sep 22, 2017 4:12 pm
by martinayotte
Do you have placed a "pinMode(led, INPUT);" or "pinMode(led, INPUT_PULLUP);" in your setup() ?
If you use the first one, do you have have external PullUps ?