Problems using <Streaming.h> and <ESP8266HTTPClient.h> in own class

Hey everybody, I am building a larger program in which I divide my code into several classes. Today I wanted to add a new class named WiFiServer. This class should handle everything which is related to manipulating my data and send it (via post-request) to my own server.

Since today, I had a few classes:

  • class Battery
  • class WriterReader
  • class FileSystem

I was using the <Streaming.h> file inside the files. In addition, I added the <Streaming.h> file into the main file (batteryCharger.ino). Everything worked fine. However, if I add the <ESP8266HTTPClient.h> into the header file of the new class (WiFiServer). I suddenly get problems.

To solve the problem I need to remove the include directive from the *.ino file and from the WiFiServer.cpp file. However, I would like to keep the Serial output in the way we do it in c++.

If I include the <Streaming.h> file into the WiFiServer.cpp file, I get the following error:

In file included from /home/shorty/DIY/Arduino/DIY-BatteryCharger/DIYCharger/src/wifiServer/wifiServer.cpp:14:
/home/shorty/.arduino15/packages/esp8266/hardware/esp8266/3.0.2/cores/esp8266/StreamString.h: In member function 'virtual int S2Stream::read(uint8_t*, size_t)':
/home/shorty/DIY/Arduino/libraries/Streaming/src/Streaming.h:74:18: error: expected unqualified-id before '(' token
   74 | #define min(a,b) ((a)<(b)?(a):(b))
      |                  ^
/home/shorty/.arduino15/packages/esp8266/hardware/esp8266/3.0.2/cores/esp8266/StreamString.h:89:29: note: in expansion of macro 'min'
   89 |             size_t l = std::min(len, (size_t)string->length());
      |                             ^~~
/home/shorty/DIY/Arduino/libraries/Streaming/src/Streaming.h:74:18: error: expected unqualified-id before '(' token
   74 | #define min(a,b) ((a)<(b)?(a):(b))
      |                  ^
/home/shorty/.arduino15/packages/esp8266/hardware/esp8266/3.0.2/cores/esp8266/StreamString.h:101:25: note: in expansion of macro 'min'
  101 |         size_t l = std::min(len, (size_t)(string->length() - peekPointer));
      |                         ^~~
/home/shorty/.arduino15/packages/esp8266/hardware/esp8266/3.0.2/cores/esp8266/StreamString.h: In member function 'virtual void S2Stream::peekConsume(size_t)':
/home/shorty/DIY/Arduino/libraries/Streaming/src/Streaming.h:74:18: error: expected unqualified-id before '(' token
   74 | #define min(a,b) ((a)<(b)?(a):(b))
      |                  ^
/home/shorty/.arduino15/packages/esp8266/hardware/esp8266/3.0.2/cores/esp8266/StreamString.h:183:32: note: in expansion of macro 'min'
  183 |             peekPointer = std::min((size_t)string->length(), peekPointer + consume);
      |                                ^~~

As an example. The WiFiServer header file looks as follows:

/*---------------------------------------------------------------------------*\
    =====\\  || \\    //  |
    ||    \\ ||  \\  //   | Project: BatteryCharger using D1 Wemos
    ||    || ||   \\//    | Webiste: https://Holzmann-cfd.com
    ||    // ||    ||     | Copyright (C) 2022 Tobias Holzmann
    =====//  ||    ||     |
-------------------------------------------------------------------------------
License
    This file is part of the BatteryCharger DIY project and is distributed
    under the terms of the GNU General Public License version 3

Description
    This class inherits all functions that are used to send the measeurement
    data to the DIY.holzmann-cfd.com websever which stores the data on a
    mySQL database.

SourceFiles
    wifiServer.cpp

\*---------------------------------------------------------------------------*/

#ifndef wifiServer_h
#define wifiServer_h

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //


/*---------------------------------------------------------------------------*\
                           Class WifiServer Declaration
\*---------------------------------------------------------------------------*/

class WifiServer
{
    // Private class data

        // WiFi SSID
        const String SSID_;

        // WiFi password
        const String password_;

        // Url to which we want to connect
        const String URL_{"https://DIY.Holzmann-cfd.com"};


public:

    // Constructor
    WifiServer(const String, const String);

    // Destroctor
    ~WifiServer();


    // Public Setter Functions


    // Public Return Functions


    // Public Member Functions

        // Connect to WiFi
        bool connect() const;

        // Disconnect the WiFi
        bool disconnect() const;


private:

    // Private Member Functions

};

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

#endif

// ************************************************************************* //

And the source file:

/*---------------------------------------------------------------------------*\
    =====\\  || \\    //  |
    ||    \\ ||  \\  //   | Project: BatteryCharger using D1 Wemos
    ||    || ||   \\//    | Webiste: https://Holzmann-cfd.com
    ||    // ||    ||     | Copyright (C) 2022 Tobias Holzmann
    =====//  ||    ||     |
-------------------------------------------------------------------------------
License
    This file is part of the BatteryCharger DIY project and is distributed
    under the terms of the GNU General Public License version 3

\*---------------------------------------------------------------------------*/

#include <Streaming.h>
#include "wifiServer.h"

// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * ///

WifiServer::WifiServer(const String SSID, const String password)
:
    SSID_(SSID),
    password_(password)
{}


WifiServer::~WifiServer()
{}


// * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * * * //

bool WifiServer::connect() const
{
    WiFi.begin(SSID_, password_);

    // Try 5 times
    int n = 0;

    while (WiFi.status() != WL_CONNECTED)
    {
        delay(1000);

        Serial.println("Waiting for WiFi to be connected");

        n++;

        if (n == 5)
        {
            break;
        }
    }

    if (WiFi.status() != WL_CONNECTED)
    {
        return false;
    }
    else
    {
        return true;
    }
}


bool WifiServer::disconnect() const
{
    return false;
}


// * * * * * * * * * * * * Private Return Functions  * * * * * * * * * * * * //


// ************************************************************************* //

Okay, one solution is to avoid the <Streaming.h> inclusion. Anyhow, I was expecting that I am implementing the different libraries (header files) correctly.

Tobi

PS: Project is given here (but not with the latest branch I am working on):

Okay, I solved it out of the box myself, after writing this post. I simply have to change the order in the WiFiServer.cpp file to be:

// First the Streaming and then the header file of the class solves the problem
#include <Streaming.h>
#include "wifiServer.h"

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.