Ghost duplicate text lines in Terminal on Android

Adafruit ESP 8266
Samsung Note 8
Android Version 8.0.0
Kernel Version: 4.4.78-14375742
Build Number:R16NW.N950USQS5CRJ3
Carrier: T-Mobile
Connection: Local WiFi Router
Blynk Server v0.5.4

This is a real head scratcher since the repeating lines appear and then magically disappear, but I can assure you that it is totally reproducible and has virtually nothing to do with the Arduino code and everything to do with the widget itself on my Note 8. Can’t say anything about other Androids or IoS.

The code doesn’t matter so I just built a sample using the standard Blynk terminal example from Arduino IDE. Only change was from standard was the switch from ethernet to WiFi, since the card only supports WiFi. Here is the code, my auth is included since I built that app with one object only…a Terminal.

I added the millis() time hacks to convince myself that I wasn’t crazy since you need to do this test carefully. Look once and the problem is there…look again and it isn’t!

Here is what happens. When you start the 8266 and the app on the note, all text lines are repeated.

My test code:

/*************************************************************
  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
 *************************************************************/

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <BlynkSimpleEsp8266.h>
//Auth token
char auth[] = "3eeb292da21f4b448625ec7cd81c7b5a";
// Attach virtual serial terminal to Virtual Pin V1
WidgetTerminal terminal(V1);
BLYNK_WRITE(V1)
{
terminal.print("[");
terminal.print(millis());
terminal.println("] ");
  // if you type "Marco" into Terminal Widget - it will respond: "Polo:"
  if (String("Marco") == param.asStr()) {
terminal.print("[");
terminal.print(millis());
terminal.print("] ");
terminal.println("You said: 'Marco'") ;
terminal.print("[");
terminal.print(millis());
terminal.print("] ");
terminal.println("I said: 'Polo'") ;
  } else {
// Send it back
terminal.print("[");
terminal.print(millis());
terminal.print("] ");
terminal.print("You said:");
terminal.write(param.getBuffer(), param.getLength());
terminal.println();
  }
  // Ensure everything is sent
  terminal.flush();
}
void setup()
{
  // Debug console
  Serial.begin(9600);
  //reconnect to previous ESP WiFi connection
  Blynk.begin(auth, "","");
  // Clear the terminal content
  terminal.clear();

  // 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();
}

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

To reproduce the problem, follow these steps:

When the app first runs, and you enter some text, the terminal widget looks like this:

Then press the “minimize” or whatever the left hand button is officially called that shows all running apps:

Then re-maximize the Blynk app and magically, all is as it should be and the repeats are gone:

You can continue the action and the first round still looks good, but the second round again has repeating lines:

Minimize again and re-maximize…and again the duplicates disappear!!!:

This seems to have nothing to do with the ESP code since it happens on my custom code as well as with the Blynk terminal sample in the Arduino IDE.

Of course you can switch to another app or stop and start the app and the duplicate lines also disappear. It appears to have something to do with screen paint on MY ANDROID. Don’t know about any others. I am new to Blynk, but not to software development.

Sorry, I posted the wrong image for the beginning of the second round. Here is the correct one:

Hard to keep the images straight.

I think your problem with timer

Well, thought that might be the case as my actual project has a timer, however, the Serial.print lines never duplicated…and this test project that I sent doesn’t have a timer!!! That is what the “[millis()]” are for. If you notice the time hack is the same for the duplicates…can’t be the timer.

I remain convinced that it is the terminal widget on android…

Not sure if terminal.print() has any issues or not, but I long ago stopped using the terminal.print("Random blatherings") command and simply use Blynk.virtualWrite(vPin, "Random blatherings")… it works perfectly and doesn’t need the terminal.flush() command either.

And if I want a line return, I use Blynk.virtualWrite(vPin, "Random blatherings\n")

Maybe, but I use it bi-directionally with status coming up and commands going down. Commands like a new SSID and password. All of my units, or selected units then respond and redirect. Not sure I can cobble up the same functionality with Virtualwrite, especially to have a multi line display, rolling display from multiple sources in the app.

A functional Terminal widget is perfect, if it works on Android.
All else being equal, I’ll take a look…thanks

It is the exact same result… just a different (and seemingly less problematic) command for sending the data to the terminal.

As for receiving terminal input, that is still done the same as any other input widget using the BLYNK_WRITE(vPin) and inputValue=param.asStr() process… the terminal input is not special in that sense… just not as clearly documented.

So, if I understand correctly, you are suggesting still attaching the Terminal Widget to the same virtual pin, but accessing it using Blynk.virtualWrite syntax rather than via the Terminal.print(). Same virtual pin and the hardware actions on Terminal data sent back are the same. I will give that a try and see if the Android paint function problem goes away.

As I said, I am new to Blynk syntax, but that seems logical and might help. Thanks

Your previously posted test sketch using the standard Blynk.virtualWrite() commands…

/*************************************************************
  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
 *************************************************************/

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <BlynkSimpleEsp8266.h>
//Auth token
char auth[] = "xxxxxxxxxx";
// Attach virtual serial terminal to Virtual Pin V1
//WidgetTerminal terminal(V1);
BLYNK_WRITE(V1)
{
Blynk.virtualWrite(V1,"[");
Blynk.virtualWrite(V1,millis());
Blynk.virtualWrite(V1,"] \n");
  // if you type "Marco" into Terminal Widget - it will respond: "Polo:"
  if (String("Marco") == param.asStr()) {
Blynk.virtualWrite(V1,"[");
Blynk.virtualWrite(V1,millis());
Blynk.virtualWrite(V1,"] ");
Blynk.virtualWrite(V1,"You said: 'Marco'\n") ;
Blynk.virtualWrite(V1,"[");
Blynk.virtualWrite(V1,millis());
Blynk.virtualWrite(V1,"] ");
Blynk.virtualWrite(V1,"I said: 'Polo'\n") ;
  } else {
// Send it back
Blynk.virtualWrite(V1,"[");
Blynk.virtualWrite(V1,millis());
Blynk.virtualWrite(V1,"] ");
Blynk.virtualWrite(V1,"You said:");
Blynk.virtualWrite(V1,param.asStr());
Blynk.virtualWrite(V1,"\n");
  }
  // Ensure everything is sent
  //terminal.flush();
}
void setup()
{
  // Debug console
  Serial.begin(9600);
  //reconnect to previous ESP WiFi connection
  Blynk.begin(auth, "<SSID>","<PASSWORD>","blynk-cloud.com", 80);
  // Clear the terminal content
  Blynk.virtualWrite(V1,"clr");
  //terminal.clear();

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

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

Hey, thanks. Works…but it certainly points out the issue with the terminal widget. I get this:

Which, after minimize, becomes this…

Nice idea, but the problem is with the widget…clearly. Totally reproducible.

Thanks for the quick re-code. That would have taken me a while. Obviously it works on your device…

Using the code you posted above? (and I modified). If not, then you need to provide the code that does reproduce the issue for us to look at and see if there might be another reason.

What version App?

I still see normal operation, even on my Android 8.0.0 phone, using Cloud Server, Library 0.5.4 and even Beta App 2.27.1 ( previous screenshot above was the App running on an emulator)

Version 2.27.0 of the app. Version 0.5.4 of the library.

For a moment I had a eureka as I had developer options turned on. Turned them off, re-booted and no change. Same as before.

Shouldn’t have any effect on the App.

I have noticed that when using the terminal.print() method, all the [millis] timeframes for each line are exactly the same… indicating how the device sends the data to the terminal all in one rush with the terminal.flush() command… this might be relevant to your duplication.

Using the Blynk.virtualWrite() method shows discreet [millis] timestamps for each line… indicating each line is individually sent, so no buffering and potential duplication.

Well, the only identical millis values are after the terminal sends to the cpu and it echos and responds…immediately. I presume that this response is interrupt driven. It’s all slaved to some polling interval on the CPU library side and we don’t know what that is but two adjacent lines of code, happening in a single millisecond is reasonable. A milli is really kind of a long time with a modern cpu.

Either way, still have the problem and minimize eliminates it with a terminal re-paint. That hasn’t changed.

Thanks for the code at least it confirms it isn’t in my code. We will have to wait and see if anyone has a fix.

:stuck_out_tongue: No, no… nothing so fansnazy as interrupts and polling timers, etc… the [millis] are simply the time since boot, printed out by command…

My point was that with the terminal.print() they are all showing the same time… thus a buffered dump to the terminal and the likely cause of potential duplication

terminal.print("[");
terminal.print(millis());
terminal.print("] ");
terminal.println("You said: 'Marco'") ;
terminal.print("[");
terminal.print(millis());
terminal.print("] ");
terminal.println("I said: 'Polo'") ;

Versus the Blynk.virtualPrint() which sends immediately and thus not buffered…

Blynk.virtualWrite(V1,"[");
Blynk.virtualWrite(V1,millis());
Blynk.virtualWrite(V1,"] ");
Blynk.virtualWrite(V1,"You said: 'Marco'\n") ;
Blynk.virtualWrite(V1,"[");
Blynk.virtualWrite(V1,millis());
Blynk.virtualWrite(V1,"] ");
Blynk.virtualWrite(V1,"I said: 'Polo'\n") ;

Therefore, I suspect if there is any App issue with terminal duplication, it is only when using the terminal.print() terminal.flush() commands.

So if the developers can confirm, then they can fix… meanwhile you can wait… :stuck_out_tongue_winking_eye:

Otherwise, just use the same Blynk.virtualWrite() command as with all other Widgets, and let it work as it is supposed to (at least I have not seen any duplication in any of my projects using the Terminal Widget this way).

You misunderstand. The alternate method doesn’t solve my problem anyway…I may use it but really am not sure. In my case the repeats were really somewhat worse with the virtualwrites…than with the terminal.print. Obviously with terminal.print there is buffering or there would be no need of a “flush” command. I don’t see how buffering could make it worse anyway.

I either case, they are way to predictable for me from either method. I may just minimize a lot when they bother me.

Then you probably have something goofy in your code.

In theory, a buffered data stream could be printed multiple times due a glitch in the App from a single “send” process on the device…

But again, unless you can conclusively show some code that causes the issue, so that the developers can then track the issue… or even send the developers logs showing such, then we can only go around in circles. But I am leaving this merry-go-round :stuck_out_tongue: so perhaps someone else will join.

Hey there, not so fast. I thought that you were actually reading my posts rather that just assuming you know the right solution and I was just mistaken in my implementation. I used YOUR code as well. Just because it doesn’t show the problem on your CPU or your phone doesn’t mean it isn’t there. Resorting to the old saw of saying I don’t know what I am doing or that I have bad code is frankly absurd when the code that you sent fails as well.

I have run development organizations in all kinds of languages at all levels. Good developers want reproducible bugs so that they can find the issue and fix it. Bad developers scoff and chalk it up to operator error…and the bug remains and fails after release!

Which are you?

2 Likes

Neither… I am a just another Blynk user who saw your issue, pointed out some facts based on my own past experience with this widget and years of using Blynk, and did my best to keep your topic flowing in case someone else who might be experiencing the same issue joined in, or the the actual Blynk developers took notice and recognised a real issue. FYI, here have been references to similar repetitions in the past… but usually the same, limited case or hard to reproduce or prove issues, as I can recall.

But unlike your apparent terminal issue, I don’t wish to keep repeating myself :wink: And since I have tested what code you did provide, and am actively running various terminal stuff on multiple emulators, phones, tablets and projects… all working fine BTW… I have nothing more to add, so I am going to sit back and watch. That’s all I ment, and I do hope it works out for you.

Thanks…appreciate your help and efforts. I know these are hard to find and based on my searches this is not the first time it has happened. I am going to post my, much simpler, latest code that fails as a bug report and see what the developers have to say.

Sorry if I misjudged you.

1 Like