BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Terminal Widget not send Text in Setup()

Hi, i want to send some information to the terminal in my project after booting the NodeMCU. Unfortunately i don’t get any information after booting. What am I doing wrong?
Here my configuration:

• NodeMCU 1.0
• iOS
• Blynk server
• Blynk Library 0.5.0

thanks Torsten


#define BLYNK_PRINT Serial

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

//needed for library
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>         //https://github.com/tzapu/WiFiManager

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

BlynkTimer timer;
WidgetTerminal terminal(V1);


void reconnectBlynk() {
  if (!Blynk.connected()) {
    if (Blynk.connect()) {
      BLYNK_LOG("Reconnected");
    } else {
      BLYNK_LOG("Not reconnected");
    }
  }
}

BLYNK_WRITE(V1)
{

  // if you type "Marco" into Terminal Widget - it will respond: "Polo:"
  if (String("Marco") == param.asStr()) {
    terminal.println("You said: 'Marco'") ;
    terminal.println("I said: 'Polo'") ;
  } else {

    // Send it back
    terminal.print("You said:");
    terminal.write(param.getBuffer(), param.getLength());
    terminal.println();
  }

  terminal.flush();
}


void setup()
{
  Serial.begin(115200);
  Blynk.config(auth);

  WiFiManager wifiManager;
  //reset saved settings
  //wifiManager.resetSettings();
  wifiManager.autoConnect("myBlynk-AP");

  if (!WiFi.status() == WL_CONNECTED)
  {
    Serial.println("not connected to AP!");
  }
  else
  {
    Serial.println("connected...");
    // This will print Blynk Software version to the Terminal Widget when
    // your hardware gets connected to Blynk Server
    terminal.println(F("Blynk v" BLYNK_VERSION ": Device started"));
    terminal.println(F("-------------"));
    terminal.println(F("Type 'Marco' and get a reply, or type"));
    terminal.println(F("anything else and get it printed back."));
    terminal.flush();
  }

  timer.setInterval(60000L, reconnectBlynk);



}

void loop()
{
  Blynk.run();
  timer.run();
  delay(10);
}



Blynk.config()

config() allows you to manage network connection. You can set up your connection type (WiFi, Ethernet, …) by yourself, and then call:

Blynk.config(auth, server, port);

or just

Blynk.config(auth);

NOTE: After Blynk.config(...) is called, your hardware is not yet connected to the server. It will try to connect while until it hits first instance of Blynk.run() or Blynk.connect() routine.
To skip connecting to the server or to disconnect manually, call Blynk.disconnect() after configuration.

Use connectWiFi to conveniently set up WiFi connection:

Blynk.connectWiFi(ssid, pass);

To connect to open WiFi networks, set pass to an empty string ( "" ).

You’re calling Blynk.config at the beginning of your void setup, but there is no Blynk.connect or Blynk.run until the code execution hits the void loop for the first time.

Pete.

2 Likes

Hi Pete,
i put the Blynk.run() in the Void-Setup after the Blyk.config(auth).

void setup()
{
  Serial.begin(115200);
  Blynk.config(auth);
  Blynk.run();
  WiFiManager wifiManager;
...

Unfortunately nothing changes

Torsten

You have to read more carefully what @PeteKnight wrote. But to make it simple, try replacing setup() and loop() with the following code (with comment) to see what Pete means:

void setup()
{
  Serial.begin(115200);

  WiFiManager wifiManager;
  //reset saved settings
  wifiManager.resetSettings();
  wifiManager.autoConnect("myBlynk-AP");

  if (WiFi.status() != WL_CONNECTED)
  {
    Serial.println("not connected to AP!");
  }
  else
  {
    Blynk.config(auth);
    
    // After Blynk.config(...) is called, your hardware is not yet connected to the server. 
    // It will try to connect while until it hits first instance of Blynk.run() or Blynk.connect() routine.
    if (Blynk.connect())
    {
      Serial.println("Blynk connected...");
      // This will print Blynk Software version to the Terminal Widget when
      // your hardware gets connected to Blynk Server
      terminal.println(F("Blynk v" BLYNK_VERSION ": Device started"));
      terminal.println(F("-------------"));
      terminal.println(F("Type 'Marco' and get a reply, or type"));
      terminal.println(F("anything else and get it printed back."));
      terminal.flush();
    }
  }
  
  timer.setInterval(60000L, reconnectBlynk);
}

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