I need help for my projects. I am new using Blynk, there is a problem on my project. I can’t connect to the Blynk server. I already update the newest library and arduino.
#define BLYNK_DEBUG
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h> // Essential for all Blynk Projects
char auth[] = "2ed13df8a2334ff1923638d49069d8bc";
char ssid[] = "PLum";
char pass[] = "tanyaandre";
bool Connected2Blynk = false;
int port = 8080;
SimpleTimer timer;
void setup() {
Serial.begin(115200);
delay(10);
timer.setInterval(11000L, CheckConnection); // check if still connected every 11 seconds
Serial.println("\nStarted");
MyWiFi();
}
void MyWiFi(){
int mytimeout = millis() / 1000;
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
if((millis() / 1000) > mytimeout + 3){ // try for less than 4 seconds to connect to WiFi router
break;
}
}
if(WiFi.status() == WL_CONNECTED){
Serial.print("\nIP address: ");
Serial.println(WiFi.localIP());
}
else{
Serial.println("\nCheck Router ");
}
Blynk.config(auth, port);
Connected2Blynk = Blynk.connect(1000); // 1000 is a timeout of 3333 milliseconds
mytimeout = millis() / 1000;
while (Blynk.connect(1000) == false) {
if((millis() / 1000) > mytimeout + 3){ // try for less than 4 seconds
break;
}
}
}
void CheckConnection(){
Connected2Blynk = Blynk.connected();
if(!Connected2Blynk){
Serial.println("Not connected to Blynk server");
MyWiFi();
}
else{
Serial.println("Still connected to Blynk server");
}
}
void loop() {
if(Connected2Blynk){
Blynk.run(); // only process Blyk.run() function if we are connected to Blynk server
}
timer.run();
}
First I fixed your post as required and mentioned above… please follow the required methods next time or topic many be deleted.
Second… this doesn’t look like a proper IP for Blynk’s Cloud server?
And finally, this looks like you are copying some older example from the web or somewhere (BlynkTimer has replaced SimpleTimer for a long time now…)
If you are just starting out, then stick with the simpler official Blynk Blink example. Worry about connection management once you can actually get connected
/*************************************************************
Download latest Blynk library here:
https://github.com/blynkkk/blynk-library/releases/latest
Blynk is a platform with iOS and Android apps to control
Arduino, Raspberry Pi and the likes over the Internet.
You can easily build graphic interfaces for all your
projects by simply dragging and dropping widgets.
Downloads, docs, tutorials: http://www.blynk.cc
Sketch generator: http://examples.blynk.cc
Blynk community: http://community.blynk.cc
Follow us: http://www.fb.com/blynkapp
http://twitter.com/blynk_app
Blynk library is licensed under MIT license
This example code is in public domain.
*************************************************************
You’ll need:
- Blynk App (download from AppStore or Google Play)
- ESP8266 board
- Decide how to connect to Blynk
(USB, Ethernet, Wi-Fi, Bluetooth, ...)
There is a bunch of great example sketches included to show you how to get
started. Think of them as LEGO bricks and combine them as you wish.
For example, take the Ethernet Shield sketch and combine it with the
Servo example, or choose a USB sketch and add a code from SendData
example.
*************************************************************/
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "575fd8241aa746558837304ab425cfb2";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "PLum";
char pass[] = "tanyaandre";
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
//Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);
//Blynk.begin(auth, ssid, pass);
// You can also specify server:
}
void loop()
{
Blynk.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!
}