Help: Serial.printf to lcd.print

Hi mates, I tried to figure out myself, for me it's really complicated, I always stop on an error during compiling.
I've tried to create a buffer and then print it butI'm not able to manage strings chars and array of chars. I've tried with String(), strcpy(), .toString(), I surrender.

My goal is to change Serial.printf with lcd.print of the following code

Serial.printf("WebSocket client #%u connected from %s\n", client->id(), client->remoteIP().toString().c_str());

I would also save the string as static, because this cose is inside a routine and I want to keep the string also on the loop, how can I? Thank you

Is creating a function that receives all the arguments then formats the output not feasible?

I moved your topic to an appropriate forum category @GiovanniG11.

In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.

This is an important part of responsible forum usage, as explained in the "How to get the best out of this forum" guide. The guide contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

1 Like

From which platform does that code come from ?
Which Arduino board do you use ?

There are maybe 10 ways to print that on the LCD display, but it depends on the Arduino board.

Hi, thanks everybody for your kind answers.
sorry pert m I was thinking to have selected exactly what you suggested, maybe something went wrong, I'll be more careful

The board is ESP8266, the library is LiquidCrystal_I2C 1.1.2.

lcd.print("WebSocket client #");
lcd.print(client->id());
lcd.print(" connected from ");
lcd.println(client->remoteIP().toString());

Yes, it works thanks, I would also like to export this alues with a static variable and print them in another part of program, how could I store a string that I don't know how long it is? (IP address)
Can you kindly write a simple example, with variable declarations, thank you!

My goal is to save the output string performed in this routine on a static string/array and use it after in the main loop. I don't know how to manage these values, I always get compiling errors. In particular I don't know:

  1. Ho many chars it will result, how then to define an array
  2. How to convert thise vaues to a text, if they are numbers for example
  3. How to keep this "storage" available for the main loop.
    My you kindly write a code for it? Thank you

For example

static char buffer [I don't know what to put here];

void thisroutinehappens {
buffer= strcpy("WebSocket client ", client->id(), "connected from", client->remoteIP().toString().c_str());
}
void setup() {
}

void loop() {
lcd.print(buffer);
}
char buffer[13]; // buffer size
int base = 10; // base counting system
itoa(val, buffer, base); // store val, base 10, in buffer