Problem with WiFiClient connect(server,80) in NodeMCU 1.0 (ESP-12E Module)

Hello all,

I’m using a NodeMCU 1.0 (ESP-12E Module).

I used a code for transferring some sensor data to a domain.

Until recently I was using a free .ga domain and my code was working.

Now, I changed to a .ch domain

(so i just changed changed from char server[] = "mydomain.ga"; to char server[] = "mydomain.ch";)

The problem is that now (with the .ch domain) the
if (client.connect(server,80)) does not work (so it can’t transmit to the new domain).

If I ping the mydomain.ch it works. Also I can view from a browser.

But my NodeMCU can’t connect through the if (client.connect(server,80))
which returns “False” in my case.

Can you please help?
Do you think is a problem with .ch domains, with NodeMCU, something else?

Thanks a lot for the support!!

//library DHT11
#include <DHT.h>

//library esp
#include <ESP8266WiFi.h>

// Wifi Connection
char ssid[] = "ssid";      // your network SSID (name)
char password[] = "pass";   // your network password


//Server
char server[] = "mydomain.ch";

#define DHTPIN 5 // what pin we’re connected to

DHT dht(DHTPIN, DHT11,15);
WiFiClient client;


int photocellPin = 0;
int ledPin =15;
int ledLow = LOW;
int ledHigh = LOW;
//--------------------------setup-------------------------
void setup() {
  Serial.begin(115200);
  delay(10);
  
  dht.begin();
  
  Serial.println("Attempting to connect to WPA network...");
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  Serial.print("..........");
  Serial.println();
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.println("Couldn't get a wifi connection");
  }
  Serial.println("WiFi connected");
  Serial.print("IP Address: ");
  Serial.println(WiFi.localIP());
  printWifiStatus();
  pinMode(13, OUTPUT);
}


void loop() {
  //------------ DHT11 --------------
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  
  if (isnan(h) || isnan(t)) {
  Serial.println("Failed to read from DHT sensor!");
  delay(5000);
  return;
  }
  Serial.print("Temperature:      ");
  Serial.print(t);
  Serial.print(" degrees Celcius ");
  Serial.println();
  Serial.print("Humidity:         ");
  Serial.print(h);
  Serial.print("%");
  Serial.println();
  
  //--- extra---- you can measure dew point with the temperature and the humidity
  double gamma = log(h/100.0) + ((17.62*t) / (243.5+t));
  double dp = 243.5*gamma / (17.62-gamma);
  
  Serial.print("Dew point:        ");
  Serial.print(dp);
  Serial.print(" degrees Celcius ");
  Serial.println();

  //--- extra---- you can measure the lux
  double lux = analogRead(photocellPin);
   
  Serial.print("Photocell: ");
  Serial.println(lux);

  //--- extra---- you can measure the received signal strength and get the ip address
  IPAddress ip = WiFi.localIP();
  long rssi = WiFi.RSSI();
  
  Serial.print("IP Address: ");
  Serial.println(ip);
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);


if (client.connect(server,80)) {

  String postStr;
  postStr +="&temperature=";
  postStr += String(t);
  postStr +="&humidity=";
  postStr += String(h);
  postStr +="&dewpoint=";
  postStr += String(dp);
  postStr +="&lux=";
  postStr += String(lux);
  postStr +="&ip=";
  postStr += String(ip);
  postStr +="&rssi=";
  postStr += String(rssi);


    Serial.println("--> connection ok\n");
    client.print("GET /sensor2.php?"); // This
    client.print(postStr); // all data
    client.println(" HTTP/1.0"); // Part of the GET request
    client.print( "Host: " );
    client.println(server);
    client.println("User-Agent: ESP8266");
    client.println("Connection: close"); // Part of the GET request telling the server that we are over transmitting the message
    client.println(); // Empty line
    client.println(); // Empty line
    client.stop();    // Closing connection to server
    Serial.println("--> finished transmission\n");
}


client.stop();

Serial.println("Going to sleep 10 min...");
Serial.println();
digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
delay(1000);              // wait for a second
digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW

delay(10000);   //600000
}




void printWifiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}

Does your site use TCP or TLS? (Is port 80 open for HTTP requests, or does it only support HTTPS on port 443?)

Try doing a DNS lookup on the ESP8266. Does it return an IP address?

#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>

const char* server = "domain.ch";

IPAddress serverIP;

void startWiFi() { // Try to connect to some given access points. Then wait for a connection
  wifiMulti.addAP("ssid_from_AP_1", "your_password_for_AP_1");   // add Wi-Fi networks you want to connect to
  wifiMulti.addAP("ssid_from_AP_2", "your_password_for_AP_2");
  wifiMulti.addAP("ssid_from_AP_3", "your_password_for_AP_3");

  Serial.println("Connecting");
  while (wifiMulti.run() != WL_CONNECTED) {  // Wait for the Wi-Fi to connect
    delay(250);
    Serial.print('.');
  }
  Serial.println("\r\n");
  Serial.print("Connected to ");
  Serial.println(WiFi.SSID());             // Tell us what network we're connected to
  Serial.print("IP address:\t");
  Serial.print(WiFi.localIP());            // Send the IP address of the ESP8266 to the computer
  Serial.println("\r\n");
}

void setup() {
  Serial.begin(115200);          // Start the Serial communication to send messages to the computer
  delay(10);
  Serial.println("\r\n");

  startWiFi();                   // Try to connect to some given access points. Then wait for a connection

  if(!WiFi.hostByName(server, serverIP)) { // Get the IP address of the NTP server
    Serial.println("DNS lookup failed. Rebooting in 5 seconds.");
    Serial.flush();
    delay(5000);
    ESP.reset();
  }
  Serial.print("Server IP:\t");
  Serial.println(serverIP);
}
void loop() {}

Pieter