-->
Page 1 of 3

Get external IP from Ipify

PostPosted: Wed Aug 12, 2015 3:19 pm
by Rafael R
Hi i'm newbie on ESP8266. I have a project that have to acquire a external IP.
I found this website https://www.ipify.org/ that has an API that return the external IP.
When i try to use AT+CIPSEND to get the response the ESP returns wrong syntax.

Code:

Code: Select all#include <SoftwareSerial.h>
 
SoftwareSerial esp8266(2,3); // make RX Arduino line is pin 2, make TX Arduino line is pin 3.
                             // This means that you need to connect the TX line from the esp to the Arduino's pin 2
                             // and the RX line from the esp to the Arduino's pin 3
void setup()
{
  Serial.begin(9600);
  esp8266.begin(9600); // your esp's baud rate might be different
}
 
void loop()
{
  if(esp8266.available()) // check if the esp is sending a message
  {
    while(esp8266.available())
    {
      // The esp has data so display its output to the serial window
      char c = esp8266.read(); // read the next character.
      Serial.write(c);
    } 
  }
 
 
 
  if(Serial.available())
  {
    // the following delay is required because otherwise the arduino will read the first letter of the command but not the rest
    // In other words without the delay if you use AT+RST, for example, the Arduino will read the letter A send it, then read the rest and send it
    // but we want to send everything at the same time.
    delay(1000);
   
    String command="";
   
    while(Serial.available()) // read the command character by character
    {
        // read one character
      command+=(char)Serial.read();
    }
    esp8266.println(command); // send the read character to the esp8266
  }
}

Link: http://allaboutee.com/2014/12/27/esp826 ... d-circuit/

The Steps followed are:
- AT+RST (restart the module)
-AT+CWMODE=3 (change the working mode to 3, AP+STA)
-AT+CWJAP=“you ssid”, “password” (join router)
-AT+CIPMUX=0 (Single connection)
-AT+CIPSTART="TCP","api.ipify.org",80 (connect to remote TCP server)
-AT+CIPSEND=45 (quantity of characters)
(Wait for ">")
GET / HTTP/1.0\r\nHost: api.ipify.org\r\n\r\n

Thank you all for your help

Re: Get external IP from Ipify

PostPosted: Wed Aug 12, 2015 4:34 pm
by martinayotte
You provide "HOST" in your GET, but you use "HTTP/1.0", I think you should try "HTTP/1.1" instead ...

Re: Get external IP from Ipify

PostPosted: Thu Aug 13, 2015 12:27 pm
by Rafael R
Hi, Thank you for help me.

I changed to:

GET / HTTP/1.1\r\nHost: api.ipify.org\r\nConnection:close\r\n\r\n

And now i received the response below:

+IPD,134:HTTP/1.1 505 HTTP Version Not Supported
Connection: close
Server: Cowboy
Date: Thu, 13 Aug 2015 17:23:52 GMT
Content-Length: 0


OK

OK
Unlink

Re: Get external IP from Ipify

PostPosted: Thu Aug 13, 2015 1:48 pm
by martinayotte
Your GET request was missing the "/?format=json" path/arguments. It should be like :
Code: Select allGET /?format=json HTTP/1.1\r\nHost: api.ipify.org\r\n\r\n