mcci-catena / arduino-lmic

LoraWAN-MAC-in-C library, adapted to run under the Arduino environment
https://forum.mcci.io/c/device-software/arduino-lmic/
MIT License
636 stars 207 forks source link

Defaults flags in `lmic_project_config.h` cannot be overwritten in PlatformIO setup #185

Closed frazar closed 5 years ago

frazar commented 5 years ago

I'm trying to use the arduino-lmic library within a PlatformIO project.

My platformio.ini looks like this:

[env:megaatmega2560]
platform = atmelavr
board = megaatmega2560
framework = arduino
lib_deps =
    MCCI LoRaWAN LMIC library=https://github.com/mcci-catena/arduino-lmic/archive/master.zip
build_flags =
    -D CFG_eu868=1
    -D LMIC_DEBUG_LEVEL=2
    -D LMIC_PRINTF_TO=Serial

The LMIC_DEBUG_LEVEL and LMIC_PRINTF_TO flags work as expected. However, the code fails to compile because the CFG_eu868 flag clashes with the CFG_us915 flag defined by lmic_project_config.h.

The complete error message is the following:

In file included from .piolibdeps/MCCI LoRaWAN LMIC library/src/aes/ideetron/../../lmic/oslmic.h:36:0,
from .piolibdeps/MCCI LoRaWAN LMIC library/src/aes/ideetron/AES-128_V10.cpp:44:
.piolibdeps/MCCI LoRaWAN LMIC library/src/aes/ideetron/../../lmic/config.h:25:3: error: #error You can define at most one of CFG_... variables
# error You can define at most one of CFG_... variables
^

I see a number of possible solutions:

  1. Leave everything as-is, and force the user to copy paste the library in the src dir of the project. However, this is tedious, error-prone and prevents the user from taking advantage of the extremely rich dependency management that is provided by PlatformIO.
  2. Prevent lmic_project_config.h from defining the CFG_us915 if other flag is already specified.
  3. Comment all the #defines from lmic_project_config.h, and expect the user uncomment the desired flags.
terrillmoore commented 5 years ago

Sorry, I don't support platformio -- I couldn't make it work at all for me. I know others like it, but... my focus in this platform is on the Arduino environment. I believe that @frankleonrose made PlatformIO work by doing all the -D's from the comand line. one will prevent the lmic_project_config.h from being included. But we can't change lmic_project_config.h at this time.

frazar commented 5 years ago

While investigating the problem, I found that the library already supports a ARDUINO_LMIC_PROJECT_CONFIG_H_SUPPRESS flag which prevents lmic_project_config.h from being included!

cyberman54 commented 5 years ago

@frazar With current version (2.3.1) you can set a build flag in platformio.ini pointing Platformio to a user specific lmic_project_config.h file:

build_flags = '-DARDUINO_LMIC_PROJECT_CONFIG_H=../../../src/lmic_config.h'

When using mcci lmic as a platformio library, the above path points to a lmic_config.h file which resides in /src directory of the project.

terrillmoore commented 5 years ago

Thanks for your comments. Please study the flag -D ARDUINO_LMIC_PROJECT_CONFIG_H_SUPPRESS, which is intended for use with PlatformIO, and which causes all definitions to come from the command line.