-->
Page 1 of 2

Connecting two ESP modules with HTTP GET

PostPosted: Wed Aug 26, 2015 3:50 pm
by lajolo
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

Re: Connecting two ESP modules with HTTP GET

PostPosted: Fri Oct 09, 2015 11:57 pm
by forlotto
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

Re: Connecting two ESP modules with HTTP GET

PostPosted: Sat Oct 10, 2015 9:02 am
by eduperez
If you can control the LED from a browser, then the server is working properly; I would post the complete source for the client here.

Re: Connecting two ESP modules with HTTP GET

PostPosted: Sat Oct 10, 2015 11:39 am
by lajolo
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>";