Hello,
I’m trying to use MegunoLink with my Arduino Nano IoT. After I installed the library and just compile my code I get a arror as such:
I do not understand this I have used MegunoLink before with an ESP32 and Mega2560 without any issue. This library should work with the Nano, but maybe I need to take an extra step with Platform IO.
Note that even when I do not include the lib in my code and do not call methinds from the lib I still get this message. I wonder why, is there anybody who can help me with this?
Thanks in advance
Well some errors are understandable.
For example, I get
.pio\libdeps\nano33ble\MegunoLink\src\ArduinoTimer.cpp:3:1: error: reference to ‘ArduinoTimer’ is
ambiguous
which is since the library
directly conflicts with a class created in the core
So that’s a kaboom and they’d need to use different names.
The first kaboom in the Formatting.h class is due to the class doing
#include "Print.h"
#if !defined(typeof)
#define typeof(x) __typeof__(x)
#endif
#define AsHex(x) AsHexWrapper<typeof(x)>(x)
#define WithPrecision(x, p) WithPrecisionWrapper<typeof(x)>(x, p)
template<typename TValue>
class AsHexWrapper : public Printable
{
private:
TValue m_Value;
public:
AsHexWrapper(TValue Value)
: m_Value(Value)
{
This file has been truncated. show original
it attempts to be minimal by only including Print.h
to get the Print
and Printable
classes, however, in the Arduino core used for the Nano 33 BLE, this is wrong because including only that header declares those classes in the arduino
namespace, which means the referenced class would have to be written as arduino::Printable
. The easiest way to solve this is to just #include <Arduino.h>
instead, because this activates a using namespace arduino;
in the header and so the referencable name is again Printable
.
I’ve correct all these compile errors through this .
In your platformio.ini
, replace your previous
lib_deps =
megunolink/MegunoLink@^1.41
with
lib_deps =
https://github.com/maxgerhardt/MLP/archive/refs/heads/master.zip
Tracked in
opened 11:43AM - 07 May 23 UTC
closed 08:55AM - 18 May 23 UTC
bug
Includes Nano 33 BLE, Raspberry Pi Pico, Portenta H7 and more.
This is becaus… e:
1. The `ArduinoTimer` class defined in this library directly conflicts with `ArduinoTimer` from the core. (Should have used a unique name)
https://github.com/Megunolink/MLP/blob/dec47782f92a470376f8a28b1fc6fcc85e96f0d6/src/ArduinoTimer.h#L15-L19
vs
https://github.com/arduino/ArduinoCore-mbed/blob/80310080316bee7d0ff5c72392554dbaa29a7f11/cores/arduino/timer.h#L13-L15
2. The `Formatting.h` file doing a `#include "Print.h"` to get `Print` and `Printable` class declarations is wrong because in ArduinoCore-mbed, when including this header directly, these classes are scoped in the `arduino` namespace, but the `Formatting.h` doesn't have `using namespace arduino;` in it. (Should have just used `#include <Arduino.h>`)
https://github.com/Megunolink/MLP/blob/dec47782f92a470376f8a28b1fc6fcc85e96f0d6/src/Formatting.h#L6
This results in a wall of compiler errors for the user, such as [happened here](https://community.platformio.org/t/i-get-errors-after-installing-megunolink-library/33642?u=maxgerhardt).
```
In file included from lib\MLP\src\Formatting.cpp:6:
lib\MLP\src\Formatting.h:17:1: error: expected class-name before '{' token
{
^
lib\MLP\src\Formatting.h:36:1: error: expected class-name before '{' token
{
^
*** [.pio\build\nano33ble\libd56\MLP\Formatting.cpp.o] Error 1
lib\MLP\src\ArduinoTimer.cpp:3:1: error: reference to 'ArduinoTimer' is ambiguous
ArduinoTimer::ArduinoTimer()
^~~~~~~~~~~~
In file included from C:\Users\Max\.platformio\packages\framework-arduino-mbed@3.1.1\cores\arduino/Arduino.h:103,
from lib\MLP\src\ArduinoTimer.h:15,
from lib\MLP\src\ArduinoTimer.cpp:1:
C:\Users\Max\.platformio\packages\framework-arduino-mbed@3.1.1\cores\arduino/timer.h:15:9: note: candidates are: 'class arduino::ArduinoTimer'
class ArduinoTimer {
^~~~~~~~~~~~
In file included from lib\MLP\src\ArduinoTimer.cpp:1:
lib\MLP\src\ArduinoTimer.h:17:7: note: 'class ArduinoTimer'
class ArduinoTimer
^~~~~~~~~~~~
lib\MLP\src\ArduinoTimer.cpp:8:6: error: reference to 'ArduinoTimer' is ambiguous
bool ArduinoTimer::TimePassed_Milliseconds(uint32_t uPeriod, bool bAutoReset)
^~~~~~~~~~~~
In file included from C:\Users\Max\.platformio\packages\framework-arduino-mbed@3.1.1\cores\arduino/Arduino.h:103,
from lib\MLP\src\ArduinoTimer.h:15,
from lib\MLP\src\ArduinoTimer.cpp:1:
C:\Users\Max\.platformio\packages\framework-arduino-mbed@3.1.1\cores\arduino/timer.h:15:9: note: candidates are: 'class arduino::ArduinoTimer'
class ArduinoTimer {
^~~~~~~~~~~~
In file included from lib\MLP\src\ArduinoTimer.cpp:1:
lib\MLP\src\ArduinoTimer.h:17:7: note: 'class ArduinoTimer'
class ArduinoTimer
^~~~~~~~~~~~
lib\MLP\src\ArduinoTimer.cpp: In function 'bool TimePassed_Milliseconds(uint32_t, bool)':
lib\MLP\src\ArduinoTimer.cpp:13:14: error: 'm_uStartTime' was not declared in this scope
if (uNow - m_uStartTime >= uPeriod)
^~~~~~~~~~~~
lib\MLP\src\ArduinoTimer.cpp: At global scope:
lib\MLP\src\ArduinoTimer.cpp:23:6: error: reference to 'ArduinoTimer' is ambiguous
bool ArduinoTimer::TimePassed_Seconds(uint16_t uPeriod, bool bAutoReset)
^~~~~~~~~~~~
In file included from C:\Users\Max\.platformio\packages\framework-arduino-mbed@3.1.1\cores\arduino/Arduino.h:103,
from lib\MLP\src\ArduinoTimer.h:15,
from lib\MLP\src\ArduinoTimer.cpp:1:
C:\Users\Max\.platformio\packages\framework-arduino-mbed@3.1.1\cores\arduino/timer.h:15:9: note: candidates are: 'class arduino::ArduinoTimer'
class ArduinoTimer {
^~~~~~~~~~~~
In file included from lib\MLP\src\ArduinoTimer.cpp:1:
lib\MLP\src\ArduinoTimer.h:17:7: note: 'class ArduinoTimer'
class ArduinoTimer
^~~~~~~~~~~~
lib\MLP\src\ArduinoTimer.cpp: In function 'bool TimePassed_Seconds(uint16_t, bool)':
lib\MLP\src\ArduinoTimer.cpp:28:15: error: 'm_uStartTime' was not declared in this scope
if ((uNow - m_uStartTime)/1000 >= uPeriod)
^~~~~~~~~~~~
lib\MLP\src\ArduinoTimer.cpp: At global scope:
lib\MLP\src\ArduinoTimer.cpp:38:6: error: reference to 'ArduinoTimer' is ambiguous
bool ArduinoTimer::TimePassed_Minutes(uint16_t uPeriod, bool bAutoReset)
^~~~~~~~~~~~
In file included from C:\Users\Max\.platformio\packages\framework-arduino-mbed@3.1.1\cores\arduino/Arduino.h:103,
from lib\MLP\src\ArduinoTimer.h:15,
from lib\MLP\src\ArduinoTimer.cpp:1:
C:\Users\Max\.platformio\packages\framework-arduino-mbed@3.1.1\cores\arduino/timer.h:15:9: note: candidates are: 'class arduino::ArduinoTimer'
class ArduinoTimer {
^~~~~~~~~~~~
In file included from lib\MLP\src\ArduinoTimer.cpp:1:
lib\MLP\src\ArduinoTimer.h:17:7: note: 'class ArduinoTimer'
class ArduinoTimer
^~~~~~~~~~~~
lib\MLP\src\ArduinoTimer.cpp: In function 'bool TimePassed_Minutes(uint16_t, bool)':
lib\MLP\src\ArduinoTimer.cpp:44:19: error: 'm_uStartTime' was not declared in this scope
uDelta = uNow - m_uStartTime;
^~~~~~~~~~~~
lib\MLP\src\ArduinoTimer.cpp: At global scope:
lib\MLP\src\ArduinoTimer.cpp:56:6: error: reference to 'ArduinoTimer' is ambiguous
bool ArduinoTimer::TimePassed_Hours( uint16_t uPeriod, bool bAutoReset /*= true*/ )
^~~~~~~~~~~~
In file included from C:\Users\Max\.platformio\packages\framework-arduino-mbed@3.1.1\cores\arduino/Arduino.h:103,
from lib\MLP\src\ArduinoTimer.h:15,
from lib\MLP\src\ArduinoTimer.cpp:1:
C:\Users\Max\.platformio\packages\framework-arduino-mbed@3.1.1\cores\arduino/timer.h:15:9: note: candidates are: 'class arduino::ArduinoTimer'
class ArduinoTimer {
^~~~~~~~~~~~
In file included from lib\MLP\src\ArduinoTimer.cpp:1:
lib\MLP\src\ArduinoTimer.h:17:7: note: 'class ArduinoTimer'
class ArduinoTimer
^~~~~~~~~~~~
lib\MLP\src\ArduinoTimer.cpp: In function 'bool TimePassed_Hours(uint16_t, bool)':
lib\MLP\src\ArduinoTimer.cpp:62:19: error: 'm_uStartTime' was not declared in this scope
uDelta = uNow - m_uStartTime;
^~~~~~~~~~~~
*** [.pio\build\nano33ble\libd56\MLP\ArduinoTimer.cpp.o] Error 1
In file included from lib\MLP\src\UdpParser.cpp:1:
lib\MLP\src\UdpParser.h:27:5: error: reference to 'ArduinoTimer' is ambiguous
ArduinoTimer m_tmrPacketCheck;
^~~~~~~~~~~~
In file included from C:\Users\Max\.platformio\packages\framework-arduino-mbed@3.1.1\cores\arduino/Arduino.h:103,
from lib\MLP\src\CommandDispatcherBase.h:2,
from lib\MLP\src\UdpParser.h:3,
from lib\MLP\src\UdpParser.cpp:1:
C:\Users\Max\.platformio\packages\framework-arduino-mbed@3.1.1\cores\arduino/timer.h:15:9: note: candidates are: 'class arduino::ArduinoTimer'
class ArduinoTimer {
^~~~~~~~~~~~
In file included from lib\MLP\src\UdpParser.h:5,
from lib\MLP\src\UdpParser.cpp:1:
lib\MLP\src\ArduinoTimer.h:17:7: note: 'class ArduinoTimer'
class ArduinoTimer
^~~~~~~~~~~~
lib\MLP\src\UdpParser.cpp: In member function 'void MLP::UdpParser::Process()':
lib\MLP\src\UdpParser.cpp:14:7: error: 'm_tmrPacketCheck' was not declared in this scope
if (m_tmrPacketCheck.TimePassed_Milliseconds(PacketCheckInterval))
^~~~~~~~~~~~~~~~
*** [.pio\build\nano33ble\libd56\MLP\UdpParser.cpp.o] Error 1
======================================================================== [FAILED] Took 7.76 seconds ========================================================================
```
and fixed
Megunolink:master
← maxgerhardt:master
opened 11:44AM - 07 May 23 UTC
Fix #12 by
1. renaming `ArduinoTimer` class and files to `MegunoArduinoTimer`
…
2. `#include <Arduino.h>` instead of `#include "Print.h"` in `Formatting.h`
if they chose to accept it.
Thanks for this clear information I’ll have a look into it, much appreciated