Assignment of String into StreamString?

u063096
Posts: 34
Joined: Wed Feb 13, 2019 3:27 pm

Assignment of String into StreamString?

Postby u063096 » Sun Mar 24, 2019 4:34 pm

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?

u063096
Posts: 34
Joined: Wed Feb 13, 2019 3:27 pm

Re: Assignment of String into StreamString?

Postby u063096 » Sun Mar 24, 2019 5:13 pm

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);

Who is online

Users browsing this forum: Google [Bot] and 30 guests