Static IP to NodeMCU ESP8266 on Local Server RPi

Hi all!
I need a static IP for my project at ESP8266. The local server runs on Raspberry Pi3 server-0.41.7-java8, library v0.6.1 on NodeMCU.
I carefully read all topics related to static addresses, but I can not solve the problem.
This is the code I use.

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h> 

char auth[] = "*******";
char ssid[] = "*****";
char password[] = "******";

IPAddress server_ip (xxx, xxx, xxx, xxx);
byte arduino_mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xFF };
IPAddress arduino_ip ( 192,  168,   100,  112);
IPAddress dns_ip     (  8,   8,   8,   8);
IPAddress gateway_ip ( 192,  168,   100,   100);
IPAddress subnet_mask(255, 255, 255,   0);

void setup() {
  Serial.begin(115200);
  Serial.println();
  WiFi.config(arduino_ip, gateway_ip, subnet_mask);
  WiFi.begin(ssid, password);
  Serial.print("localIP: ");
  Serial.println(WiFi.localIP());
  
//  Blynk.config(auth, server_ip, 8080);
  Blynk.config(auth, "******.ddns.net", 8080);
  while (Blynk.connect(1000) == false) { 
  }
}

void loop() {
  Blynk.run();
}

I have a dynamic external IP and configured port forwarding to the server.
Problem in this lines:

// Blynk.config (auth, server_ip, 8080);
   Blynk.config (auth, "*****. Ddns.net", 8080);

If select a line with a specified current external IP, then everything works. But if I choose a line with a domain name, then I get into the permanent

[] Connecting to ******. ddns.net:8080

That is, the IP address assigned by ESP is correct, but the connection to the local server by the domain name does not occur.
The domain name is relevant, linking to the IP is correct.

Sorry for my English :woozy_face:

You have a space between the dot and ddns.net
I assume that this occurred when you edited your NoIP URL to make it anonymous, but it’s worth checking.

Also, are you certain that your NoIP hostname is pointing to the current public address IP of the network where your server is located?

Pete.

Yes, space is really an editing error.
Yes, NoIP hostname points to a valid address. Ping hostname indicates the correct IP address.
Thanks for the reply, Pete.

OK folks, I solved the problem.
The WiFi initialization string

WiFi.config(arduino_ip, gateway_ip, subnet_mask);

should look like this:

WiFi.config(arduino_ip, gateway_ip, subnet_mask, dns);

And most importantly - the line at the beginning of the sketch must be commented.

// #define BLYNK_PRINT Serial

Thanks to all!

This shouldn’t affect operation at all when using an ESP8266 as a standalone WiFi device, as is your case.

It would only interfere if using an ESP-01 (or other networking interface) as a UART connected shield for an Arduino, and then only if over same Serial port.

1 Like

OK Gunner, you undoubtedly understand better than me.
But I can not understand why this happens?
I leave in the sketch line

#define BLYNK_PRINT Serial 

and I get at the com port output

[24143] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.6.1 on NodeMCU

localIP: 192.168.100.214
[24151] Connecting to xxxx.ddns.net:8080
[28118] Login timeout
[30118] Connecting to xxxx.ddns.net:8080
[33128] Login timeout
[35128] Connecting to xxxx.ddns.net:8080
[38138] Login timeout
[40138] Connecting to xxxx.ddns.net:8080
[41837] Ready (ping: 1689ms).
[62946] Connecting to xxxx.ddns.net:8080
[63258] Ready (ping: 299ms).
[82259] Heartbeat timeout
[84262] Connecting to xxxx.ddns.net:8080
[87275] Login timeout
[89275] Connecting to xxxx.ddns.net:8080
[91007] Ready (ping: 1723ms).
[110008] Heartbeat timeout
[112011] Connecting to xxxx.ddns.net:8080
[117012] Connecting to xxxx.ddns.net:8080
[117445] Ready (ping: 422ms).
[126952] Connecting to xxxx.ddns.net:8080
[129963] Login timeout
[131963] Connecting to xxxx.ddns.net:8080
[131996] Ready (ping: 14ms).
[152039] Heartbeat timeout
...

and so constantly, NodeMCU connects for a few seconds and disconnects .
If I comment out this line in the sketch, do I have a stable uptime connection for more than 3 days today?

That is quite unusual… I do wonder if those widely spread from low to very high ping times are the reason, or quite the “victim” of another issue. Have you tried to downgrade the Blynk library and test with enabled Serial Monitor?