Have questions about FETS, transistors, measurement, power supplies, or anything else electrical?

User avatar
By magpa
#79403 Until 1 week ago I connect my wificlient with:

if (client.connect(host, 80)) {
client.println(String("GET /waitfordbcommand.aspx" + matricola + String(" HTTP/1.1"));
client.println("Host: " + host );
client.println("Connection: close");
client.println();
}

where host was: "miodominio.com"

Since now esp no connects no more. I try to put IP address of the host and in this case it connects .
I thought it depended from router, I switch off and on the router, but nothing.
Why happened this? What is it depend from?
Please help me thanks.
paolo
User avatar
By magpa
#79428 Hi QuickFix thanks for your answer.
I know what you said but until now I use the following to config ESP:

IPAddress ip(192, 168, 1, 100);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 255, 0);
WiFi.config(ip, gateway, subnet);

and when I sent

client.connect("miodominio", 80);

every thing worked very good and fast.

Now no more, then do you think something has changed in my router? I realy have to say that if I put dns with thew some address of gateway (router):

IPAddress ip(192, 168, 1, 100);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 255, 0);
IPAddress dns(192, 168, 1, 1);
WiFi.config(ip, gateway, subnet, dns);

the connection works also if takes almost 40-50 secs to realize connection.

Instead if I put directly the address in the connection and I don't use dns in config
the connection up in 3-5 seconds.

Could all this depend from the router conf?
I didn't touch any time the router configurations, then this mean the provider changed some parameter in the router without telling me anything? Or what else?
User avatar
By QuickFix
#79447 In that case it looks like DHCP on your router is not working correctly (does, for instance, your mobile and/or laptop get a valid IP and gateway?) or something is going wrong while your ESP is retrieving and setting a gateway- (and possibly even a valid IP-) address from the router.

You could try to blank your ESP so that all is as new and flash a simple example client that just obtains an IP address (and gateway) from a router and does a simple GET-request.
Code: Select all#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
 
// WiFi parameters to be configured
const char* ssid = "ID_Of_Router"; // Case sensitive
const char* password = "Pass_Of_Router"; // Case sensitive

const char* http_site = "http://jsonplaceholder.typicode.com/users";
const int http_port = 80;

void setup(void) {
  Serial.begin(9600);
  Serial.print("Busy connecting");
  WiFi.begin(ssid, password); // Connect to WiFi
 
  // while wifi not connected yet, print '.'
  // then after it connected, get out of the loop
  while (WiFi.status() != WL_CONNECTED) {
     delay(500);
     Serial.print(".");
  }
 
  // Connnected.
  Serial.println("OK!");
 
  // Access Point (SSID).
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());
 
  // IP address.
  Serial.print("IP: ");
  Serial.println(WiFi.localIP());

  // Signaalsterkte.
  long rssi = WiFi.RSSI();
  Serial.print("RSSI: ");
  Serial.print(rssi);
  Serial.println(" dBm");
  Serial.println("");
}

void loop() {
 if(WiFi.status()== WL_CONNECTED){ //Check WiFi connection status
 
    HTTPClient http; //Declare an object of class HTTPClient
    http.begin("http://jsonplaceholder.typicode.com/users/1"); //Specify request destination
    int httpCode = http.GET(); //Send the request
    if (httpCode > 0) { //Check the returning code
      String payload = http.getString(); //Get the request response payload
      Serial.println(payload); //Print the response payload
    }
    http.end(); //Close connection
  } else {
    Serial.println("Error in WiFi connection");   
  }
  delay(30000); //Send a request every 30 seconds
}
Source