PlatformIO Community

Can't use class member from task, why?

#include <tasksConfig.h>
#include <connectRadio.h>
#include <stdint.h>     // for uint8_t

void populateMusicQueue(void *param)
{    
    UBaseType_t uxHighWaterMark;
    uxHighWaterMark = uxTaskGetStackHighWaterMark(NULL);
    Serial.printf("\n1. HighWater: %d\n", uxHighWaterMark);

    ConnectRadio cRadio;    // Tested and works flawless

    for (;;)
    {
        if (cRadio.wClient.available())
        {
            // ... code commented out 
        } else {
            Serial.printf("wClient NOT available!\n");
        }
        vTaskDelay(4000 / portTICK_PERIOD_MS);
        uxHighWaterMark = uxTaskGetStackHighWaterMark(NULL);
        Serial.printf("\n2. HighWater: %d\n", uxHighWaterMark);
    }   // end for-loop()

}   // end populateMusicQueue()

The output is:

Free heap: 330476

Connect to SSID: H369AAF9760
.....
========================================
WiFi connected to IPaddress: 192.168.2.60


Connecting to host: icecast.omroep.nl
Connect to host: "icecast.omroep.nl" at port: "80" OK!

Requested path: /radio1-bb-mp3
Send the request to the server: 

Wait for the connection to establish:
...........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................

Permanently read the stream from the server

1. HighWater: 724
wClient NOT available!

2. HighWater: 149
wClient NOT available!

2. HighWater: 149
wClient NOT available!
class ConnectRadio
{
  public:
    ConnectRadio(); ~ConnectRadio();

    WiFiClient wClient;      

    void connectToWiFi();
    void connectRadioStation(uint8_t sIndex);
    
};  // end class ConnectRadio

Oeps! I created an other instance of class ConnectRadio in my task and that’s not going to work. I’ll try creating a pointer to that class and pass this pointer via *pvParam.