Esphome raw print to console

Hi!

I’m hoping there’s a simple answer to this… After extensive searching, both in the formal homeassistant.io documentation and here in the community, as well as elsewhere, I haven’t found anything…

Is there a way to print “raw” to the log/console/output, without the Time/Level/Log info at the beginning?

In other words, I would like a “raw” string like
Raw:1,2,3
to appear on its own line, i.e. beginning with the string “Raw:”, as opposed to something like:
[8:10:01][I][main:241]: Raw:1,2,3

One more thing, if I may: I’d like to “format” it, using lambda or the like, to include variables, something like this:
- lambda: |-
ESP_LOGI(“main”, “Raw:%.0d,%.0d,%.0d,”, id(x),id(y),id(z);
(of course, this produces the undesired Time/Level/Log string at the beginning, as above, so doesn’t meet my need.)

I’ve researched logger.log, ESP_LOGx, printf, and more…

I saw something about using “system_log.write”, but because my application will be very chatty, I don’t want to “pollute” the “real” system log with this, as its size is limited.

Thanks in advance!

Addendum: The reason I need this is that I have an application that reads directly from the ‘log output’ (via the COM port), and expects a delimited line beginning with the string “Raw:”.

Just a guess/hack but maybe a newline before “Raw:” in the format string would do what you need.

ESP_LOGI(“main”, “\nRaw:%.0d,%.0d,%.0d,”, id(x),id(y),id(z);

OMG, @mulcmu, that’s BRILLIANT! And, so simple! I’m flagging your answer as a “Solution”, even though I’d arrived at a different one, as I’ll explain below. Thank you!
The only thing I needed to add was a /r (CR) as /n (LF) wasn’t enough, because my Windows expects CRLF, as opposed to 'Nix systems, which are happy with just LF. So:
ESP_LOGI(“main”, “\n\rRaw:%.0d,%.0d,%.0d,”, id(x),id(y),id(z);

For the benefit of others who may fall upon this thread, I found a way to post to the UART pins (RX/TX), which I was able to read with a separate USB/TTL cable. The code snippet is as follows:


uart:
  tx_pin: GPIO43
  rx_pin: GPIO44
  baud_rate: 9600

interval:
 - interval: 500ms
   then:
     - uart.write: !lambda  
        char buf[128];
        sprintf(buf, "Raw:0,0,0,0,0,0,%.0d,%.0d,%.0d\n\r", int(id(hmc5883l_x).state)*10, int(id(hmc5883l_y).state)*10, int(id(hmc5883l_z).state)*10);
        std::string s = buf;
        return std::vector<unsigned char>( s.begin(), s.end() );
     - uart.write: !lambda  
        char buf[128];
        sprintf(buf, "Uni:0,0,0,0,0,0,0,0,0\n\r");
        std::string s = buf;
        return std::vector<unsigned char>( s.begin(), s.end() );

(I don’t really need the string that starts with “Uni:”, but the external app expects its, so…)

1 Like