-->
Page 1 of 2

Sending a HTTP string to the ESP using a Public IP address

PostPosted: Sun Jan 22, 2017 6:07 am
by Knot83
Hello ESP Community,

I'm trying to send a HTTP string to the ESP8266 using it as a server AT+CIPSERVER=1,80.
I've opened the port 80 of my Technicolor Modem and assigned it to the ESP module.

If I send LED=0 to the ESP using the loacal IP address assigned it by the Modem it works correclty (http://192.168.1.210:80/led=0):

Code: Select all+IPD,1,410:GET /led=0 HTTP/1.1
Host: 192.168.1.210
Connection: keep-alive
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36
Accept: text/htmlnaxa;p tceq0


If instead I try to do the same thing sending the message with my public IP address (http://2.xxx.xx.xx:80/led=0) it doesn't answer at all.

To access the serial communication with the ESP8266 I first use the following simple sketch with Arduino due:
Code: Select allint LED = 13;
boolean LEDst = false;

//always high
int CH_PD_8266 = 53;

void setup() {
  Serial.begin(9600);     //quello che imposto nel monitor seriale cioè la comunicazione tra Arduino e PC
  Serial3.begin(115200);   
  pinMode(LED, OUTPUT);
  digitalWrite(LED, LEDst);
  pinMode(CH_PD_8266, OUTPUT);
  digitalWrite(CH_PD_8266, HIGH);
}

void loop() {
  while (Serial.available() > 0) {
    char a = Serial.read();
    Serial3.write(a);
  }
 
}

void serialEvent3() {
  while (Serial3.available() > 0) {
    char a = Serial3.read();
    Serial.write(a);
    ToggleLED();
  }
}

void ToggleLED(){
  digitalWrite(LED, LEDst = !LEDst);
}


...then I send AT commands for debug using the Serial Monitor of the Arduino IDE. Hereafter the command that I use to setup the ESP8266 for the comunication:

Code: Select allAT+RST
AT+CWQAP
AT+CWMODE=1
AT+CWLAP
AT+CWJAP="MyUserName","MyPassword"
AT+CIPMUX=1
AT+CIPSERVER=1,80


Am I doing something wrong?
Shall I add/modify some piece of code to access from a public IP address?

Thanks in advance for you support.

Re: Sending a HTTP string to the ESP using a Public IP addre

PostPosted: Mon Jan 23, 2017 12:06 pm
by eduperez
Are you sure your router is forwarding the request from the external interface down to the ESP? Also, most router will not redirect traffic that way when you use the external IP address form an internal machine, be sure to make your tests from a device not connected to your internal network.

Re: Sending a HTTP string to the ESP using a Public IP addre

PostPosted: Tue Jan 24, 2017 3:31 pm
by Knot83
eduperez wrote:Are you sure your router is forwarding the request from the external interface down to the ESP? Also, most router will not redirect traffic that way when you use the external IP address form an internal machine, be sure to make your tests from a device not connected to your internal network.


Dear, about your question if I use the private Ip assigned by the router to the ESP yes it forwards correcly. If instead I use the public IP not.
I perform the test from my mobile phone connected to a mobile provider not to my Wifi connection and it doesn't work :(
Any suggestion for other type of tests?

Re: Sending a HTTP string to the ESP using a Public IP addre

PostPosted: Tue Jan 24, 2017 5:48 pm
by martinayotte
The question eduperez was asking you is :
Did you configure your router to let external request been dispatched to internal device such ESP or any other such desktop computer.
If you didn't configure "IP forwarding rules" in the router, no request will ever comes in. Check your router manual for how to do that.
You can add several rules, one for ESP, another for a Desktop, etc, such rules are defined like :

<external port number> <internal port number><internal ip address><tcp or udp type>