bertmelis/espMqttClient

[BUG] error: 'millis' was not declared in this scope

Closed this issue · 5 comments

I get a compiler error using the lib with TLS, esp8266 and PlatformIO.

#include <espMqttClient.h>
espMqttClientSecure mqttClient;

Compile output

Processing upstream_develop (platform: espressif8266; board: shelly1; framework: arduino)
---------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif8266/shelly1.html
PLATFORM: Espressif 8266 (4.2.1) > Shelly1
HARDWARE: ESP8266 80MHz, 80KB RAM, 2MB Flash
PACKAGES: 
 - framework-arduinoespressif8266 @ 3.2.0-dev+sha.de1029f 
 - tool-esptool @ 1.413.0 (4.13) 
 - tool-esptoolpy @ 1.30000.201119 (3.0.0) 
 - toolchain-xtensa @ 2.100300.220621 (10.3.0)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ deep+, Compatibility ~ soft
Found 47 compatible libraries
Scanning dependencies...
Dependency Graph
|-- arduino-sht @ 1.2.3
|-- ArduinoJson @ 6.21.5
|-- StreamUtils @ 1.8.0
|-- espMqttClient @ 1.5.0+sha.885e631
|-- mr-common @ 1.0.0+sha.b2d7ae3
|-- ESP_WiFiManager_Lite @ 1.11.0-wip+sha.36d3c02
|-- ArduinoOTA @ 1.0
|-- ESP8266WiFi @ 1.0
|-- ESP8266httpUpdate @ 1.3
|-- ESP8266HTTPClient @ 1.2
|-- LittleFS @ 0.1.0
|-- Wire @ 1.0
|-- EEPROM @ 1.0
|-- Ticker @ 1.0
|-- ESP8266WebServer @ 1.0
|-- DNSServer @ 1.1.1
|-- ESP_MultiResetDetector @ 1.3.2
|-- common
Building in release mode
Compiling .pio/build/upstream_develop/src/rhts-arduino.cpp.o
Compiling .pio/build/upstream_develop/lib18e/espMqttClient/Transport/ClientAsync.cpp.o
Compiling .pio/build/upstream_develop/lib18e/espMqttClient/espMqttClientAsync.cpp.o
Compiling .pio/build/upstream_develop/libba5/mr-common/common.cpp.o
In file included from include/ESP_WiFiManager_Lite_defines.h:147,
                 from src/rhts-arduino.cpp:63:
.pio/libdeps/upstream_develop/ESP_WiFiManager_Lite/src/ESP_WiFiManager_Lite.h:99:6: warning: #warning Using EEPROM in ESP_WiFiManager_Lite.h [-Wcpp]
   99 |     #warning Using EEPROM in ESP_WiFiManager_Lite.h
      |      ^~~~~~~
In file included from .pio/libdeps/upstream_develop/ESPAsyncTCP/src/async_config.h:26,
                 from .pio/libdeps/upstream_develop/ESPAsyncTCP/src/ESPAsyncTCP.h:25,
                 from .pio/libdeps/upstream_develop/espMqttClient/src/Transport/ClientAsync.h:17,
                 from .pio/libdeps/upstream_develop/espMqttClient/src/Transport/ClientAsync.cpp:11:
.pio/libdeps/upstream_develop/ESPAsyncTCP/src/DebugPrintMacros.h: In function '_DEBUG_TIME_STAMP debugTimeStamp()':
.pio/libdeps/upstream_develop/ESPAsyncTCP/src/DebugPrintMacros.h:23:18: error: 'millis' was not declared in this scope
   23 |   unsigned now = millis() % 1000000000;
      |                  ^~~~~~
In file included from .pio/libdeps/upstream_develop/ESPAsyncTCP/src/async_config.h:26,
                 from .pio/libdeps/upstream_develop/ESPAsyncTCP/src/ESPAsyncTCP.h:25,
                 from .pio/libdeps/upstream_develop/espMqttClient/src/Transport/ClientAsync.h:17,
                 from .pio/libdeps/upstream_develop/espMqttClient/src/espMqttClientAsync.h:16,
                 from .pio/libdeps/upstream_develop/espMqttClient/src/espMqttClientAsync.cpp:11:
.pio/libdeps/upstream_develop/ESPAsyncTCP/src/DebugPrintMacros.h: In function '_DEBUG_TIME_STAMP debugTimeStamp()':
.pio/libdeps/upstream_develop/ESPAsyncTCP/src/DebugPrintMacros.h:23:18: error: 'millis' was not declared in this scope
   23 |   unsigned now = millis() % 1000000000;
      |                  ^~~~~~

Expected behaviour
Of course no error. ;-)
I can fix this by adding

diff --git a/src/Transport/ClientAsync.h b/src/Transport/ClientAsync.h
index c3ddd03..7e89828 100644
--- a/src/Transport/ClientAsync.h
+++ b/src/Transport/ClientAsync.h
@@ -14,6 +14,7 @@ the LICENSE file.
   #include "freertos/FreeRTOS.h"
   #include <AsyncTCP.h>
 #elif defined(ARDUINO_ARCH_ESP8266)
+  #include <Arduino.h>
   #include <ESPAsyncTCP.h>
 #endif

Don't know why this happen to me. Others seem to have no issue. Strange ...

I assume you are using Platformio?

The error is in the async TCP library. It doesn't include Arduino.h.

Yep. I use PlatformIO (first line in my post).
And yes. It's a problem of ESPAsyncTCP. But as me-no-dev does no further development we are in a dead lock. Maybe it's fixed in ESPAsyncTCP-esphome. Is there any chance to get this #142 working in the next time?

Surely it is possible to use another lib. The PR you prefer to is definitely a contender.

I'll take a look tomorrow.

The problem obviously originates from the dependency and I cannot solve this myself.

As a workaround I suggest to download the alternative library and point to the directory in platformio.ini (See https://docs.platformio.org/en/latest/projectconf/sections/env/options/library/lib_extra_dirs.html#lib-extra-dirs)

You should raise this issue in the dependency repo: https://github.com/esphome/ESPAsyncTCP