bblanchon / ArduinoStreamUtils

💪 Power-ups for Arduino streams
MIT License
257 stars 21 forks source link

Error trying ot log while deserializing #8

Closed weshouman closed 3 years ago

weshouman commented 3 years ago

When trying to follow this example to log a string while deserializing it I get either of the following errors (when using either a String or char * input)

error: no matching function for call to 'StreamUtils::ReadLoggingStream::ReadLoggingStream(String&, HardwareSerial&)
error: no matching function for call to 'StreamUtils::ReadLoggingStream::ReadLoggingStream(char*&, HardwareSerial&)

Sample code

  String text = extractContent(*filename);
  // char *textchar = extractContentChar(*filename);

  ReadLoggingStream loggingStream(text, Serial);
  // ReadLoggingStream loggingStream(textChar, Serial);
  DeserializationError error = deserializeJson(ds, loggingStream);
bblanchon commented 3 years ago

Hi @weshouman,

Indeed this library, StreamUtils, only works with streams. Your program doesn't use streams but strings.

If you want to see the content of the string, simply call Serial.print():

String text = extractContent(*filename);
Serial.println(text);
DeserializationError error = deserializeJson(ds, text);

BTW, as a best practice, I recommend that you let deserializeJson() read from the File directly. See JsonConfigFile.ino for an example.

Lastly, if for some reason, you absolutely need to build a ReadLoggingStream on top of a String, you need to create a StringStream first:

StringStream stream = extractContent(*filename);
ReadLoggingStream loggingStream(stream, Serial);
DeserializationError error = deserializeJson(ds, loggingStream);

Best regards, Benoit

weshouman commented 3 years ago

Thanks a lot ^_^