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");
}