ArduinoIoTCloud and HTTPClient (ESP32)

Hello,

I’m looking at a project (from a friend of mine), he’s stuck.
He wants to use ArduinoIoTCloud and do HTTP requests on an ESP32 (Wemos d1 mini32). But he is always getting the same error:

‘HTTPClient’ was not declared in this scope.

To narrow down the issue, I made an example with minimal code that only includes the ArduinoIoTCloud and the HTTPClient:

//#include <HTTPClient.h> adding or removing this line does not influence the error, it stays
#include <Arduino.h>
#include <WiFi.h>
#include <ArduinoIoTCloud.h>

void setup() {
  Serial.begin(115200);
  delay(1000);

  HTTPClient http;  // If this line fails, it’s NOT a conflict — it's core-level missing
  Serial.println("HTTPClient works!");
}

void loop() {
}

With following ini:

; PlatformIO Project Configuration File
;
;   Build options: build flags, source filter
;   Upload options: custom upload port, speed and extra flags
;   Library options: dependencies, extra library storages
;   Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[env:wemos_d1_mini32]
platform = espressif32
board = wemos_d1_mini32
framework = arduino
lib_deps = 
    arduino-libraries/ArduinoIoTCloud@^2.7.0
lib_ldf_mode = deep+
lib_ignore = WiFiNINA ;Exclude to avoid the PinStatus error ('PinStatus' does not name a type)
;lib_ignore = ArduinoHttpClient does exclude this library but causes errors within ArduinoIoTCloud (OTA for example needs it)

Gives following error:

src/main.cpp: In function 'void setup()':
src/main.cpp:10:3: error: 'HTTPClient' was not declared in this scope

Any ideas?
I already gave him the feedback that he might just need to refactor and use the ArduinoHttpClient (if possible) for requests. Looking at his project all of the request are made to a local webserver, so MQTT would also be a solution. Both of these recommendations are only sidestepping the issue, of course.

What’s your source that a HTTPClient class exists in the context of the ArduinoIoTCloud library? I only see HttpClient for example here.

Ah. It’s the classical bullshit.

The Arduino-ESP32 core exposes a HTTPClient.h header with the HTTPClient class:

https://github.com/espressif/arduino-esp32/blob/master/libraries/HTTPClient/src/HTTPClient.h

While the ArduinoHttpClient library exposes HttpClient.h and the corresponding class.

https://github.com/arduino-libraries/ArduinoHttpClient/blob/master/src/HttpClient.h

If you have a case-insensitive filesystem, like the defaults on Windows or Mac, it cannot differentiate HTTPClient.h and HttpClient.h, since they just differ in the upper/lower casing.

So, if you write a firmware using these libraries, it depends on the order of the include (-I) flags whether the Arduino core library is first of the ArduinoHttpClient library is first, and it’ll take that “HttpClient.h” file.

My recommendation: Stick to one library only. Since the ArduinoIoTCloud library hard depends on the ArduinoHttpClient library, you could e.g. lib_ignore = HTTPClient (source) and only ever ever use the HttpClient.h and class in your firmware.

The only other reliable way is to literally use Linux (or WSL on Windows or a VM on Windows/Mac) with a case-sensitive file system, so that it can differentiate a #include "HttpClient.h" from a #include "HTTPClient.h". Then you can have both libraries in the project.

1 Like

Thank you so much, now I know why.