Terminal repeating...and lots of connecting to server messages

I can’t guarantee this will fix your “Terminal repeating” problem, however, I’m confident the result will be different using terminal.print() / terminal.println() vs Blynk.virtualWrite(Vx, content).

There are two parts to the Terminal widget. There’s the Blynk application part and the device firmware part,

WidgetTerminal terminal(Vx);

If you use Blynk.virtualWrite(Vx, content), you don’t even need to declare the WidgetTerminal terminal(Vx). Blynk.virtualWrite(Vx, content) will still write characters to the terminal widget on the Blynk app, however, I get the sense they’re missing certain “metadata”.

The notion of terminal.flush() is a function of the Terminal widget on the device. There’s “magic” underlying the terminal.print() / terminal.println() commands. For example,

class WidgetTerminal

    virtual size_t write(uint8_t byte) {
        mOutBuf[mOutQty++] = byte;
        if (mOutQty >= sizeof(mOutBuf)) {
            flush();
        }
        return 1;
    }

    virtual void flush() {
        if (mOutQty) {
            Blynk.virtualWriteBinary(mPin, mOutBuf, mOutQty);
            mOutQty = 0;
        }
    }

writes characters to a 64-character buffer (mOutBuf). If the number of characters written exceeds the size of the buffer, the buffer it automagically flushed. Of course, the terminal.flush() function flushes the buffer.

If you’re invoking Blynk.virtualWrite(Vx, content) directly, all of this logic is bypassed.

I vote we test terminal.print() and terminal.println() in conjunction with terminal.flush(), rather than Blynk.virtualWrite(). If that doesn’t solve the problem, we’ll go from there. But this is the way the Terminal widget was intended to be used.

1 Like