BLYNK_DEBUG print to terminal

My display output is straight from the example in the Sketch Builder… you should request your code be substituted in :wink:

Now this code monkey is activating copy/paste mode :stuck_out_tongue_winking_eye: Although, in my defense, I was actualy reading up on something simular in the Time library examples:

And to keep this topic… well, on topic :wink:

After much complicated coding, involving detecting “\n”, buffering strings and inputString += inChar bla bla bla; I realised that keeping it stupid simple worked just as well…

This assumes #define BLYNK_PRINT Serial1 running on a MEGA’s 2nd hardware serial port:

//===== Terminal Widget - Debug Redirect =====
void serialEvent1() {  // Check for data on 2nd serial port
  while (Serial1.available()) {
    terminal.print((char); // Fires data back out to terminal
}  // END serialEvent1 loop

As for getting the logo to fully display… I have given up on that with my current USB link setup, as I think that just adds another layer of serial conversion and lag, resulting in only a partial logo, while basic messages are usually clear.

But as I mentioned waaaayyy back… having device debug errors redirected to an app that probably can’t receive the debug errors, due to broken connection, is really a catch 22 situation. But it was fun to play around with.

1 Like

PS, in case anyone else wants a nice Blynk Logo on their terminal at bootup, I cleaned up my origional (based on copy/paste of the image on my PC terminal) into this (using the proper way Blynk uses in their library files):

Each “line” is separated by the enter/return key, and auto format makes it look this way.

Blynk.virtualWrite(V1, "\n"
                     "    ___  __          __\n"
                     "   / _ )/ /_ _____  / /__\n"
                     "  / _  / / // / _ \\/  '_/\n"
                     " /____/_/\\_, /_//_/_/\\_\\\n"
                     "        /___/ v" BLYNK_VERSION " on " BLYNK_INFO_DEVICE "\n");
  if (size_t ram = BlynkFreeRam()) {
    Blynk.virtualWrite(V1, "             Free RAM: ", ram);

why is this line needed?
why you can’t just Blynk.virtualWrite(V1, " Free RAM: ", BlynkFreeRam());


@wanek also would need to have been == not =

Old code I guess… The free RAM part was pulled directly from one of the Blynk library files… and I guess it worked that way?? (as evidenced by the screenshot), but eventually I apparently changed it :stuck_out_tongue_winking_eye:

This is currently running fine…

void TermIntro() // Automaticly runs at Mega bootup
  Blynk.virtualWrite(V1, "\n"
                     "   ___  __          __\n"
                     "  / _ )/ /_ _____  / /__\n"
                     " / _  / / // / _ \\/  '_/\n"
                     "/____/_/\\_, /_//_/_/\\_\\\n"
                     "       /___/ v." BLYNK_VERSION " on\n            " BLYNK_INFO_DEVICE "\n");
  size_t ram = BlynkFreeRam();
  Blynk.virtualWrite(V1, "\n Free RAM: ", ram);
  Blynk.virtualWrite(V1, "\n ", currentTime, " ", currentDate);
 }  // END TermIntro Loop



Actually the error in the if statement is actually the assignment you are now using.

if i try it like this:

Blynk.virtualWrite(V1, " Free RAM: ", BlynkFreeRam());

it gives me compilation error:

In file included from C:\Users\wanek\AppData\Local\Temp\arduino_build_504181\sketch\header.h:24:0,

                 from C:\ARDUINO\PROJECTS\sonoff core\sonoff_core_02\sonoff_core_02.ino:9:

C:\ARDUINO\libraries\Sonoff/SonoffCore.h: In function 'void checkFirstRun()':

C:\ARDUINO\libraries\Sonoff/SonoffCore.h:641:49: error: call of overloaded 'println(const char [11], size_t)' is ambiguous

    terminal.println("free RAM: ", BlynkFreeRam());


C:\ARDUINO\libraries\Sonoff/SonoffCore.h:641:49: note: candidates are:

In file included from C:\Users\wanek\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0-rc2\cores\esp8266/Stream.h:26:0,

                 from C:\Users\wanek\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0-rc2\cores\esp8266/HardwareSerial.h:31,

                 from C:\Users\wanek\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0-rc2\cores\esp8266/Arduino.h:245,

                 from C:\Users\wanek\AppData\Local\Temp\arduino_build_504181\sketch\sonoff_core_02.ino.cpp:1:

C:\Users\wanek\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0-rc2\cores\esp8266/Print.h:84:16: note: size_t Print::println(unsigned char, int) <near match>

         size_t println(unsigned char, int = DEC);


C:\Users\wanek\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0-rc2\cores\esp8266/Print.h:84:16: note:   no known conversion for argument 1 from 'const char [11]' to 'unsigned char'

C:\Users\wanek\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0-rc2\cores\esp8266/Print.h:85:16: note: size_t Print::println(int, int) <near match>

         size_t println(int, int = DEC);


C:\Users\wanek\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0-rc2\cores\esp8266/Print.h:85:16: note:   no known conversion for argument 1 from 'const char [11]' to 'int'

C:\Users\wanek\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0-rc2\cores\esp8266/Print.h:86:16: note: size_t Print::println(unsigned int, int) <near match>

         size_t println(unsigned int, int = DEC);


C:\Users\wanek\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0-rc2\cores\esp8266/Print.h:86:16: note:   no known conversion for argument 1 from 'const char [11]' to 'unsigned int'

C:\Users\wanek\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0-rc2\cores\esp8266/Print.h:87:16: note: size_t Print::println(long int, int) <near match>

         size_t println(long, int = DEC);


C:\Users\wanek\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0-rc2\cores\esp8266/Print.h:87:16: note:   no known conversion for argument 1 from 'const char [11]' to 'long int'

C:\Users\wanek\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0-rc2\cores\esp8266/Print.h:88:16: note: size_t Print::println(long unsigned int, int) <near match>

         size_t println(unsigned long, int = DEC);


C:\Users\wanek\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0-rc2\cores\esp8266/Print.h:88:16: note:   no known conversion for argument 1 from 'const char [11]' to 'long unsigned int'

Using library Sonoff at version 2.4.0-rc2-51 in folder: C:\ARDUINO\libraries\Sonoff

Then do it like @Gunner :slight_smile:

I am unsure what the size_t does (haven’t Googled it yet :stuck_out_tongue_winking_eye: ) but I think it is required.

  size_t ram = BlynkFreeRam();
  Blynk.virtualWrite(V1, "\n Free RAM: ", ram);

As per Google…

Unsigned integral type
Alias of one of the fundamental unsigned integer types.

It is a type able to represent the size of any object in bytes: size_t is the type returned by the sizeof operator and is widely used in the standard library to represent sizes and counts.

In , it is used as the type of the parameter num in the functions memchr, memcmp, memcpy, memmove, memset, strncat, strncmp, strncpy and strxfrm, which in all cases it is used to specify the maximum number of bytes or characters the function has to affect.

It is also used as the return type for strcspn, strlen, strspn and strxfrm to return sizes and lengths.

Yup… totally clear now… not :stuck_out_tongue_winking_eye:

But I think it basically runs that get RAM function and fits the resulting number into that variable

probably. for me it is not clear too…
i’ve looked in the blynk lib, and there the function it is declared to return size_t

I pulled the logo and whatnot from the BlynkProtocol.h file in my IDE Libraries folder. A few different options are available, like a pseudo 3D version.

If you just want a single line use:

Blynk.virtualWrite(V1, "\n Free RAM: ", ESP.getFreeHeap());


Blynk.virtualWrite(V1, "\n Free RAM: " + String(ESP.getFreeHeap()) + "\n");


but anyway, i still can’t make this debug to terminal magic work…
if i understand correctly form the above topic:

  1. i have enabled #define BLYNK_PRINT Serial

  2. have this in setup:

  Serial.println("serial ready");
  1. have this function set in the blynk timer with a 800 ms interval:
void serialEvent()                        // terminal widget - debug redirect
  while (Serial.available()) {            // check for data on serial port
    terminal.print((char);  // fires data back out to terminal

all i got are constant resets after startup… it resets for 4-5 times, after that it remains connected, but no debug data.

the hw is a bare esp8266 module.

i’m missing something?

Well, a lot of what I was experimenting with was on a Arduino MEGA with multiple Serial ports…

But my next direction to take this will be based on my more recent post and vhymanskyy’s reference to the console object and class redirections, etc… I just haven’t been clearheaded enough to pursue it yet.

1 Like

aha! now, this is interesting stuff. apparently, i totally missed that topic… thanks!

1 Like

It would be quite hard (and dangerous a little bit) to output Blynk logs via Blynk, mostly because it introduces a circular dependency.

Black holes… interdimensional shifting… cool… Blynk powered time traveling app :smile:

1 Like

@Gunner Large Virtual Pin Collider. Soon.
(And I’m not kidding!)

1 Like

yes, i’m fully aware of that :slight_smile:
i mainly would like to do just for fun / learning / experimenting

i have lots of sonoff units installed in all kind if remote places (100km), and in those situations every bit of plus info can be useful in case i have to debug or monitor something.

recently, i had a project where ~14 units were installed in a big production facility. as it lately turned out, all the building is made from metal sandwich construction, and the sonoff units were installed on those metal “walls”. thus, the wifi antennas are just ~10mm away from a metal sheet. this causes all kinds of strange disconnections and other anomalies. causing me lots of headache…

it is really strange: the wifi signal on all units is between -70 and - 45 dbm, it seems apparently ok. but there are frequent disconnections, and when a unit is disconnected it can’t reconnect for several minutes.

i’m not sure what is causing this. or the metal walls causing rf interference, or choppy routers? will have to investigate soon.

however, i’m sure the firmware is all right, because i have wrote a core firmware for sonoff, and i use that on all units. in all locations they are working flawlessly, only this place gives me trouble.