Arduino icon indicating copy to clipboard operation
Arduino copied to clipboard

simple http get request not working after WiFi.config();

Open ghost opened this issue 8 years ago • 4 comments

Hi!

Basic Infos

  • [x] This issue complies with the issue POLICY doc.
  • [x] I have read the documentation at readthedocs and the issue is not addressed there.
  • [x] I have tested that the issue is present in current master branch (aka latest git).
  • [x] I have searched the issue tracker for a similar issue.
  • [x] If there is a stack dump, I have decoded it.
  • [x] I have filled out all fields below.

Platform

  • Hardware: NodeMCU 1.0
  • Core Version: 2.4.1
  • Development Env: Arduino IDE
  • Operating System: Windows

Settings in IDE

  • Module: Nodemcu
  • Flash Mode: [qio|dio|other]?
  • Flash Size: 4MB
  • lwip Variant: v2 Lower Memory
  • Reset Method: [ck|nodemcu]?
  • Flash Frequency: [40Mhz]?
  • CPU Frequency: 80Mhz
  • Upload Using: SERIAL
  • Upload Speed: 115200

Problem Description

So if i don't request a static ip from my router with WiFi.config(); everything works fine. When I request a static ip, the ESP8266 gets the desired ip, but the get request to http://checkip.dyndns.com doesn't work at all. (I'm commenting/uncommenting that single line). I get -1 as a response code wich is wierd.

I don't get any error messages.

I haven't changed a thing on the router, so no port forwarding or any other thing.

I'm still a newbie so I might have done something wrong/stupid and this is not an actual bug, in witch case I'm sorry to waste your time. (I've tried my best to figure this out on my own but I couldn't)

screenshot 2

screenshot 3

MCVE Sketch


#include <ESP8266WiFi.h> 
#include <ESP8266HTTPClient.h>

const char* ssid = "mySSID";
const char* password = "myPASSWORD";
IPAddress ip(192, 168, 0, 38);
IPAddress gateway(192, 168, 0, 1);
IPAddress subnet(255, 255, 255, 0);

String cIp = "";                       //current Ip adress

void setup() {
  Serial.begin(115200);
  delay(10);

  
  //WiFi.config(ip, gateway, subnet);
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  
  while (WiFi.status () != WL_CONNECTED) {
    delay(250);
    Serial.print(".");
  }
  Serial.println();
  Serial.println("Wifi connected");

  Serial.print("Local ip: ");
  Serial.println(WiFi.localIP());
}

void loop() {
  
  HTTPClient http;                              //Declare an object of class HTTPClient
  http.begin("http://checkip.dyndns.com/");     //Specify request destination
  int httpCode = http.GET();                    //Send the request
  Serial.println(httpCode);
  cIp = http.getString();                     //Get the request response payload
  Serial.println(cIp);                        //Print the response payload
  http.end();
  delay(15000);
}

Debug Messages


ghost avatar Jun 27 '18 14:06 ghost

You defined ip, gateway and subnet but you forgot to define a dns server.

MarkusAD avatar Jun 27 '18 23:06 MarkusAD

Previous comment is correct, you forgot the dns argument. Closing.

devyte avatar Jun 28 '18 05:06 devyte

Thanks! And also sorry

ghost avatar Jun 28 '18 07:06 ghost

i want to get request for using this telegram api https://api.telegram.org/bot123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11/getMe how to do this

Alpha-1729 avatar May 02 '20 17:05 Alpha-1729