Hi,
I have an ESP8266 (LOLIN WeMos D1 R1). I am trying to get familiar with Blynk so I tried two simple examples:
The first is ESP8266_Standalone
/*************************************************************
This is a simple demo of sending and receiving some data.
Be sure to check out other examples!
*************************************************************/
/* Fill-in information from Blynk Device Info here */
#define BLYNK_TEMPLATE_ID "xxxxxxxxxxxxxx"
#define BLYNK_TEMPLATE_NAME "Quickstart Template"
#define BLYNK_AUTH_TOKEN "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "xxxxxxxx";
char pass[] = "xxxxxxxxxxxxxxx";
BlynkTimer timer;
// This function is called every time the Virtual Pin 0 state changes
BLYNK_WRITE(V0)
{
// Set incoming value from pin V0 to a variable
int value = param.asInt();
// Update state
Blynk.virtualWrite(V1, value);
}
// This function is called every time the device is connected to the Blynk.Cloud
BLYNK_CONNECTED()
{
// Change Web Link Button message to "Congratulations!"
Blynk.setProperty(V3, "offImageUrl", "https://static-image.nyc3.cdn.digitaloceanspaces.com/general/fte/congratulations.png");
Blynk.setProperty(V3, "onImageUrl", "https://static-image.nyc3.cdn.digitaloceanspaces.com/general/fte/congratulations_pressed.png");
Blynk.setProperty(V3, "url", "https://docs.blynk.io/en/getting-started/what-do-i-need-to-blynk/how-quickstart-device-was-made");
}
// This function sends Arduino's uptime every second to Virtual Pin 2.
void myTimerEvent()
{
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V2, millis() / 1000);
}
void setup()
{
// Debug console
Serial.begin(115200);
delay(1000);
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
// You can also specify server:
//Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass, "blynk.cloud", 80);
//Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass, IPAddress(192,168,1,100), 8080);
Serial.print("Mac Address");
Serial.print(WiFi.macAddress());
// Setup a function to be called every second
timer.setInterval(1000L, myTimerEvent);
}
void loop()
{
Blynk.run();
timer.run();
// You can inject your own code or combine it with other sketches.
// Check other examples on how to communicate with Blynk. Remember
// to avoid delay() function!
}
When I run this code I get:
19:36:27.534 -> [5303] Connected to WiFi
19:36:27.534 -> [5304] IP: 192.168.1.43
19:36:27.534 -> [5304]
19:36:27.534 -> ___ __ __
19:36:27.534 -> / _ )/ /_ _____ / /__
19:36:27.534 -> / _ / / // / _ \/ '_/
19:36:27.534 -> /____/_/\_, /_//_/_/\_\
19:36:27.534 -> /___/ v1.3.2 on ESP8266
19:36:27.534 ->
19:36:27.534 -> #StandWithUkraine https://bit.ly/swua
19:36:27.576 ->
19:36:27.576 ->
19:36:27.576 -> [5314] Connecting to blynk.cloud:80
19:36:27.717 -> [5465] Ready (ping: 29ms).
However if I run the example ESP8266_Standalone_IP and try and use a static IP address I fail to connect.
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#define BLYNK_TEMPLATE_ID "xxxxxxxxxxxx"
#define BLYNK_TEMPLATE_NAME "Quickstart Template"
#define BLYNK_AUTH_TOKEN "xxxxxxxxxxxxxxxxxxxxxxxx"
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "xxxxxxxxx
char pass[] = "xxxxxxxxxxxxxxxxxxxxxxxx";
IPAddress device_ip (192, 168, 1, 186);
IPAddress dns_ip ( 8, 8, 8, 8);
IPAddress gateway_ip (192, 168, 1, 254);
IPAddress subnet_mask(255, 255, 255, 0);
void setup()
{
// Debug console
Serial.begin(9600);
// Setup WiFi network
WiFi.config(device_ip, gateway_ip, subnet_mask);
WiFi.begin(ssid, pass);
// Setup Blynk
Blynk.config(BLYNK_AUTH_TOKEN);
while (Blynk.connect() == false) {
}
}
void loop()
{
Blynk.run();
}
I fail to connect with:
20:01:59.696 -> [15145] Connecting to blynk.cloud:80
20:01:59.697 -> [15145] Connecting to blynk.cloud:8080
20:02:04.698 -> [20146] Connecting to blynk.cloud:80
20:02:04.698 -> [20146] Connecting to blynk.cloud:8080
20:02:09.681 -> [25147] Connecting to blynk.cloud:80
20:02:09.715 -> [25147] Connecting to blynk.cloud:8080
20:02:14.685 -> [30148] Connecting to blynk.cloud:80
20:02:14.732 -> [30148] Connecting to blynk.cloud:8080
20:02:19.687 -> [35149] Connecting to blynk.cloud:80
20:02:19.734 -> [35149] Connecting to blynk.cloud:8080
20:02:24.688 -> [40150] Connecting to blynk.cloud:80
20:02:24.734 -> [40150] Connecting to blynk.cloud:8080
20:02:29.703 -> [45151] Connecting to blynk.cloud:80
20:02:29.735 -> [45151] Connecting to blynk.cloud:8080
20:02:34.671 -> [50152] Connecting to blynk.cloud:80
20:02:34.705 -> [50152] Connecting to blynk.cloud:8080