Blynk app cannot be online problem (after entering ssid, pass value by wifi manager and connecting)

I set the ssid and password on the phone by WiFi manager and I want to control the servo by blink app.
The code that combines the two does not work properly.

WiFi Manager Basic example (autoConnect) works properly.
The blink code (servo motor control) also works properly.
But it does not work out.

I think the connection is done in ap mode through the value input from the phone.
It seems that it does not change to station mode after connection.
The Blink app will not change online.

Upload code with each code combined. Please help me.


#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Servo.h>

#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>         
#include <EEPROM.h>

char auth[] = "00000000000";



Servo servo;
int sw = 13;
int degree = 140;


BLYNK_WRITE(V3)
{
  servo.write(param.asInt());
  delay(300);
  servo.write(140);
  degree = param.asInt();
}
BLYNK_WRITE(V4)
{
  servo.write(param.asInt());
  delay(300);
  servo.write(140);
  degree = param.asInt();
}


void setup()
{
  // Debug console
  EEPROM.begin(512);
  Serial.begin(115200);
  pinMode(sw, INPUT_PULLUP);

  WiFiManager wifiManager;
  wifiManager.resetSettings();
  wifiManager.autoConnect("NodeMCU");
  Serial.println("connected...yeey :)");

  Serial.printf("SSID: %s\n", WiFi.SSID().c_str());   **//Exact ssid and pass values are displayed in the serial window**
  Serial.printf("PSK: %s\n", WiFi.psk().c_str());

  Blynk.begin(auth, WiFi.SSID().c_str(), WiFi.psk().c_str());  **//This code seems to not work well**


  servo.attach(15);
  servo.write(degree);

}


void loop()
{
  Blynk.run();
  if (digitalRead(sw) == LOW && degree == 170) {
    servo.write(110);
    delay(300);
    servo.write(140);
    degree = 110;
    delay(500);
  }
  else if (digitalRead(sw) == LOW && degree == 110 || degree == 140) {
    servo.write(170);
    delay(300);
    servo.write(140);
    degree = 170;
    delay(500);
  }
}

I am not a pro but ,don’t use delays inside the loop, use Simple Timer or Blynk Timer instead

1 Like

I’ll note that, but that was not a problem in particular. Thanks

My baord was rebooting when I used blynk.begin(). Had to do with the blocking call change made recently. I replaced it with blynk.config() and blynk.run() as given under:

void setup(){
.
.
.
.
.
  //if you get here you have connected to the WiFi
  Serial.print("connected to wifi Access Point configured....");
  Serial.print(WiFi.SSID());
  Serial.print("\nlocal ip: ");
  Serial.print(WiFi.localIP());
  Serial.print("\n");
  digitalWrite(BlynkLED, LOW);
  digitalWrite(wifiLED, HIGH);
  
  //config blynk
  Blynk.config(settings.blynkToken, settings.blynkServer, atoi(settings.blynkPort));
 
  connectBlynk();
  //Blynk.begin(settings);

  //check if connected to Blynk server
  if (!wifiClient.connected()) {
    digitalWrite(BlynkLED, HIGH);
    digitalWrite(wifiLED, HIGH);
    Serial.print("\nBlynk server unreachable. Trying once more");
    connectBlynk();
    return;
  }
  Serial.println("Setup done");
  digitalWrite(wifiLED, HIGH);
  digitalWrite(BlynkLED, LOW);
}


void loop()
{
  // Reconnect to Blynk Cloud
  if (!wifiClient.connected()) {
    digitalWrite(BlynkLED, HIGH);
    connectBlynk();
    return;
  }
  Blynk.run();  
}

connectblynk() routine:

// This function tries to connect to the Blynk cloud using TCP
bool connectBlynk()
{
  wifiClient.stop();
  //All LEDs off in this routine
  digitalWrite(BlynkLED, HIGH);
  digitalWrite(wifiLED, HIGH);
  return wifiClient.connect(settings.blynkServer, atoi(settings.blynkPort));
}