I have this code and with static ip it does not connect but with random ip it connects
#define BLYNK_TEMPLATE_ID "xxxxxxxxxxxxx"
#define BLYNK_DEVICE_NAME "xxxxxxxxxx"
#define BLYNK_AUTH_TOKEN "xxxxxxxxxxxxxxxx"
// Comment this out to disable prints and save space
#define BLYNK_PRINT Serial
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = BLYNK_AUTH_TOKEN;
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "xxxxxxxx";
char pass[] = "xxxxxxxxxxxx";
#define estatica_ip
#ifdef estatica_ip
IPAddress device_ip (192, 168, 1, 233);
IPAddress dns_ip ( 8, 8, 8, 8);
IPAddress gateway_ip (192, 168, 1, 1);
IPAddress subnet_mask(255, 255, 255, 0);
#endif
WidgetLED led1(V1);
BlynkTimer timer;
// V1 LED Widget is blinking
void blinkLedWidget()
{
if (led1.getValue()) {
led1.off();
Serial.println("LED on V1: off");
} else {
led1.on();
Serial.println("LED on V1: on");
}
}
void setup()
{
// Debug console
Serial.begin(115200);
#ifdef estatica_ip
// Setup WiFi network
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, pass);
WiFi.config(device_ip, gateway_ip, subnet_mask);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("WiFi conectado");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
// Setup Blynk
Blynk.config(auth);
while (Blynk.connect() == false) {
}
#else
// Setup Blynk
Blynk.begin(auth, ssid, pass);
#endif
timer.setInterval(1000L, blinkLedWidget);
}
void loop()
{
Blynk.run();
timer.run();
}
Debug Serial:
Random ip:
Comment #define estatica_ip:
//#define estatica_ip
[9312] Connected to WiFi
[9312] IP: 192.168.1.170
[9313]
___ __ __
/ _ )/ /_ _____ / /__
/ _ / / // / _ \/ '_/
/____/_/\_, /_//_/_/\_\
/___/ v1.1.0 on ESP8266
#StandWithUkraine https://bit.ly/swua
[9323] Connecting to blynk.cloud:80
[9415] Ready (ping: 34ms).
LED on V1: on
LED on V1: off
LED on V1: on
LED on V1: off
LED on V1: on
LED on V1: off
LED on V1: on
Static ip
Not Comment #define estatica_ip:
#define estatica_ip
IP address: 192.168.1.233
[4311]
___ __ __
/ _ )/ /_ _____ / /__
/ _ / / // / _ \/ '_/
/____/_/\_, /_//_/_/\_\
/___/ v1.1.0 on ESP8266
#StandWithUkraine https://bit.ly/swua
[4320] Connecting to blynk.cloud:80
[9321] Connecting to blynk.cloud:80
[14322] Connecting to blynk.cloud:80
[19323] Connecting to blynk.cloud:80