Chat here about code rewrites, mods, etc... with respect to the github project https://github.com/esp8266/Arduino

Moderator: igrr

User avatar
By lajolo
#27111 Hello,

I am trying to communicate between two ESP modules and I would like to check if what I am doing makes sense.

I have one ESP module running a simple WiFiWebServer.
My DHCP server assigns to it the (fixed) address 192.168.1.5 and it works correctly by serving the two following requests:
http://192.168.1.5/on --> LED is turned on
http://192.168.1.5/off --> LED is turned off

On another ESP module, I run a WiFiClient that tries to send the above commands with HTTP GET.

At the moment, the client ESP cannot connect to the server ESP.
The code below results in "connection failed":
Code: Select allconst char* host ="192.168.1.5";
const   int httpPort = 80;
  if (!client.connect(host, httpPort)) {
    Serial.println("connection failed");
    return;
  }


But on a web page, I can see the welcome page of the server at the address:
http://192.168.1.5:80

Could you please tell me if you know what I am doing wrong?

Thanks!
Marcello
User avatar
By forlotto
#30997 you are not going to see nothing on the web page if you do not have html code for the web page.

So you must write html if you wish to see a webpage and create a button to turn your led on and a button to turn it off.

Maybe I am not understanding your question but to me it seems as if you would like to see a web page that was never created...

Hope this helps.

-forlotto
User avatar
By lajolo
#31039 In the meantime, I have found a way to make it work.

Here is the web form on the server:

Code: Select allString form =
  "<head>"
  "<meta name='viewport' content='width=device-width, initial-scale=1'>"
  "<script src='https://code.jquery.com/jquery-2.1.3.min.js'></script>"
  "<link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css'>"
  "</head>"
  "<div class='container'>"
  "<h1>Led control</h1>"
  "<div class='row'>"
  "<div class='col-md-2'><input class='btn btn-block btn-lg btn-primary' type='button' value='On' onclick='on()'></div>"
  "<div class='col-md-2'><input class='btn btn-block btn-lg btn-danger' type='button' value='Off' onclick='off()'></div>"
  "</div></div>"
  "<script>function on() {$.get('/on');}</script>"
  "<script>function off() {$.get('/off');}</script>";


and here is the code that I use to send the same commands from another esp8266 module through http GET (only the last two lines are different):

Code: Select allString form =
  "<head>"
  "<meta name='viewport' content='width=device-width, initial-scale=1'>"
  "<script src='https://code.jquery.com/jquery-2.1.3.min.js'></script>"
  "<link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css'>"
  "</head>"
  "<div class='container'>"
  "<h1>Led control</h1>"
  "<div class='row'>"
  "<div class='col-md-2'><input class='btn btn-block btn-lg btn-primary' type='button' value='On' onclick='on()'></div>"
  "<div class='col-md-2'><input class='btn btn-block btn-lg btn-danger' type='button' value='Off' onclick='off()'></div>"
  "</div></div>"
  "<script>function on() {$.get('http://192.168.1.5/on');}</script>"
  "<script>function off() {$.get('http://192.168.1.5/off');}</script>";