Page 1 of 1

Assignment of String into StreamString?

Posted: Sun Mar 24, 2019 4:34 pm
by u063096
I could not find a way to assign a String object to a StreamString object - I am getting a HTTP response from a HTTPClient.getString() call that is supposed to go into a StreamString object. I tried several variants, but I always will receive the "error: conversion from 'String' to non-scalar type 'StreamString' requested" error. The code snippet below shows the offending line ("StreamString owmdata..."):

Code: Select all

owm.begin(OWM_URL);
  int HTTPrc = owm.GET();
  if(HTTPrc)
  {
    StreamString owmdata = owm.getString();
    Serial.printf("HTTP status: %d\n", HTTPrc);
StreamString does inherit both the String and Stream classes, and any String=String assignment will work, so why does this fail?

Re: Assignment of String into StreamString?

Posted: Sun Mar 24, 2019 5:13 pm
by u063096
Found it myself - sort of...

This construction works, if ugly. The writeToStream() method of HTTPClient copies the collected data into a StreamString object:

Code: Select all

  owm.begin(OWM_URL);
  int HTTPrc = owm.GET();
  if(HTTPrc)
  {
    StreamString owmret;
    owm.writeToStream(&owmret);
    Serial.printf("HTTP status: %d\n", HTTPrc);