Modified terminal example

Modified the example sketch to have Blynk.virtualWrite() calls instead of terminal.***() calls. Maybe the site admin can include this in the examples sketch library. Have the older calls also commented and flagged as
/
OLDER EXAMPLE VERSION HAD THESE LINES

/*************************************************************
  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 can send/receive any data using WidgetTerminal object.

  App project setup:
    Terminal widget attached to Virtual Pin V1

    Uses Blynk.virtualWrite calls instead of terminal.print calls
    More recent implementation and hopefully more stable thus.
 *************************************************************/

/* 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[] = "YourAuthToken";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "YourNetworkName";
char pass[] = "YourPassword";

// Attach virtual serial terminal to Virtual Pin V1
WidgetTerminal terminal(V1);

// You can send commands from Terminal to your hardware. Just use
// the same Virtual Pin as your Terminal Widget
BLYNK_WRITE(V1)
{

  // if you type "Marco" into Terminal Widget - it will respond: "Polo:"
  if (String("Marco") == param.asStr()) {
    Blynk.virtualWrite(V1, "You said: 'Marco'\nI said: 'Polo'\n");
    
/*  OLDER EXAMPLE VERSION HAD THESE LINES     
 *  terminal.println("You said: 'Marco'") ;
 *  terminal.println("I said: 'Polo'") ;
*/
  } else {

    // Send it back
    Blynk.virtualWrite(V1, "\nYou said:", param.asStr());

/*  OLDER EXAMPLE VERSION HAD THESE LINES     
*   terminal.print("You said:");
*   terminal.write(param.getBuffer(), param.getLength());
*   terminal.println(); 
*/
  }

}

void setup()
{
  // Debug console
  Serial.begin(115200);

  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);

  // This will print Blynk Software version to the Terminal Widget when
  // your hardware gets connected to Blynk Server
  Blynk.virtualWrite(V1,"Blynk v ", BLYNK_VERSION, ": Device started\n");
  Blynk.virtualWrite(V1,"-------------\n");
  Blynk.virtualWrite(V1,"Type 'Marco' and get a reply, or type\n");
  Blynk.virtualWrite(V1,"anything else and get it printed back.\n");

/*  OLDER EXAMPLE VERSION HAD THESE LINES     
*   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();
*/
}

void loop()
{
  Blynk.run();
}
1 Like