WidgetTerminal

Hey I haven’t used the terminal widget before… Not sure if there is an error in my code or if my hardware can’t handle it. (NodeMCU 0.9)

I looked at the sketch link to GitHub
-defined BLYNK_PRINT Serial
-debug
-Defined a WidgetTerminal “name” and Vpin
-Is Serial.begin used or was it on the GitHub sketch because it was connected to the serial port?
-Called some terminal.prints and they don’t work.

See attached code…

#define BLYNK_DEBUG
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>

#ifndef STASSID
#define STASSID "**"
#define STAPSK  "**"
#define LED D4
long S = 300;
long O = 1200;
long off = 600;
int flagS=0;
int flagO=0;
int loopFlag=0;
int loopFlagO=0;
int loopFlagS=0;
#endif

const char* ssid = STASSID;
const char* password = STAPSK;
WidgetLCD lcd (V0);
WidgetTerminal terminal1(V5);

char auth[] = "@@@";
BlynkTimer timer;

void setup() {
  Serial.begin(9600);  //115200
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  while (WiFi.waitForConnectResult() != WL_CONNECTED) {
    delay(5000);
    ESP.restart();
  }
  Blynk.begin(auth,STASSID,STAPSK);
  ArduinoOTA.onStart([]() {
    String type;
    if (ArduinoOTA.getCommand() == U_FLASH) {
      type = "sketch";
    } else {
      type = "filesystem";
    }
  });
  ArduinoOTA.onEnd([]() {
  });
  ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
  });
  ArduinoOTA.onError([](ota_error_t error) {
    if (error == OTA_AUTH_ERROR) {
    } else if (error == OTA_BEGIN_ERROR) {
    } else if (error == OTA_CONNECT_ERROR) {
    } else if (error == OTA_RECEIVE_ERROR) {
    } else if (error == OTA_END_ERROR) {
    }
  });
  ArduinoOTA.begin();
  pinMode(LED,OUTPUT);
  digitalWrite(LED, HIGH);
  timer.setInterval(1000L,upTime);
  Blynk.notify("Up again!");
  lcd.clear();
  terminal1.println("started");
 }

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

BLYNK_WRITE(V10)
    {
    int buttonStatus = param.asInt();
    //lcd.print(0,0, "1");
    if ((buttonStatus == 1))
    {
      Blynk.setProperty(V10, "offLabel", "Start");
    lcd.clear();
    lcd.print(0,0, loopFlagO);
    lcd.print(1,0, loopFlagS);
    S1();
    terminal1.print("wow");
    }
    }

void S1()
{
  if(loopFlagS <= 2){
    digitalWrite(LED,LOW);
    timer.setTimeout(S,Off2);
    lcd.print(0,0, loopFlagO);
    lcd.print(1,0, loopFlagS);
    Blynk.setProperty(V10, "offLabel",(loopFlagO+loopFlagS));
    }
  else if((loopFlagS >= 2)&&(loopFlagO <= 2))
    {
    digitalWrite(LED,LOW);
    timer.setTimeout(O,Off3);
    lcd.print(0,0, loopFlagO);
    lcd.print(1,0, loopFlagS);
    Blynk.setProperty(V10, "offLabel", (loopFlagO+loopFlagS));
    
    }
  else if((loopFlagS <= 5)&&(loopFlagO == 3))
  {
    digitalWrite(LED,LOW);
    timer.setTimeout(S,Off2);
    lcd.print(0,0, loopFlagO);
    lcd.print(1,0, loopFlagS);
    Blynk.setProperty(V10, "offLabel", (loopFlagO+loopFlagS));
  }
  else{
    loopFlagS=0;
    loopFlagO=0;
    S3();
    }
}

void Off2()
{
  digitalWrite(LED,HIGH);
  loopFlagS++;
  timer.setTimeout(off,S1);
  Blynk.setProperty(V10, "offLabel", (loopFlagO+loopFlagS));
}

void Off3()
{
  digitalWrite(LED,HIGH);
  timer.setTimeout(off,S1);
  loopFlagO++;
}

void S3()
{
  lcd.print(0,0, "bucka");
  timer.setTimeout(3000L,clearLCD);
}

void clearLCD()
{
  lcd.clear();
  Blynk.notify("Done");
  Blynk.setProperty(V10, "offLabel", "Done");
}

void upTime() 
{
unsigned long runMillis = millis();
unsigned long allSeconds = millis()/1000;
int daysRemain = allSeconds/86400;
int runDays = daysRemain%86400;
int runHours = allSeconds/3600;
int secsRemaining = allSeconds%3600;
int runMinutes = secsRemaining/60;
int runSeconds = secsRemaining%60;

char buf[25];
sprintf(buf,"Runtime %02d:%02d:%02d:%02d",runDays,runHours,runMinutes,runSeconds);
Blynk.virtualWrite(V4,buf);
}

It’ll work if you add:

terminal1.flush();

after each of your terminal1.print or terminal1.println commands.

Serial.begin isn’t needed to enable termal.print to work.

There’s actually a neat trick that you can do…
You can send the serial output to the terminal widget, so if you do serial prints as part of your debugging, or to provide additional information when the code is running, once you disconnect the device from your PC you can still get the same data in the terminal widget. This can be very handy whne yopu’re uinsg OTA, as it’s normally impossible to get that data without plugging the board back in to your PC.

Thius is how you do it:

Short the Rx and Tx pins on your board together with a jumper.

Add this function to your code:

  void Send_Serial()
  {
    // Sends serial data to Blynk as well as the serial monitor
    //(handy for setups where the MCU isn't connected to serial because OTA is being used)
    // Note that a jumper is needed between Tx and Rx, which needs to be removed 
    // if doing a serial flash upload (but this is not necessary for OTA flash upload)
  
    if (terminal_output_enabled)
    {    
      String content = "";
      char character;
      while(Serial.available())
      {
        character = Serial.read();
        content.concat(character);
      }
      if (content != "")
      {
        Blynk.virtualWrite (Widget_Terminal, content);
      }
    } 
  } //end of void Send_Serial

Add this timer in void setup to call the function:

timer.setInterval(500L, Send_Serial);

I also found that I needed to add this line to void setup immediately after Serial.begin():

 Serial.setRxBufferSize(1024); // Increase the serial buffer size

Once you’ve done this , add a Boolean variable called terminal_output_enabled and set it to true, then anything printed to the serial monitor will echo to the terminal. You can add a switch widget to set terminal_output_enabled = false if you’ve decided you’ve had enough of it!

Pete.

I am trying the same thing. Two different devices posting to the same terminal (keep the interface uncluttered). I tested with one and it works if I set the source to that device. Then I set the source to both devices (see pic)


and it doesn’t work. Can someone tell me if this is supposed to work?