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
629 stars 207 forks source link

How to set region without touching project_config/lmic_project_config.h #884

Closed jpwsutton closed 2 years ago

jpwsutton commented 2 years ago

I'm building a pipeline that uses arduino-cli and the sketch.yaml project definition to build my code. However, I'm in europe and so need to use the LMIC_REGION_eu868 region. In the readme it states that you can use -D CFG_eu868 build property to change it, but when you do that, the compiler gives the error: # error You can define at most one of CFG_... variables.

The arduino-cli argument I'm using is:

arduino-cli compile --profile lora_sensor --build-property "build.extra_flags=\"-D CFG_eu868\""

So it seems that the only way to correctly set the region would be to edit project_config/lmic_project_config.h, which isn't ideal in a pipeline situation.

Am I doing something obviously wrong here? Or is this an issue with the documentation / library?

Environment

This information is very important; it's hard to help without a complete set of answers.

terrillmoore commented 2 years ago

Check how it's done in the CI scripts. More detailed answer later if I get a spare moment.

jpwsutton commented 2 years ago

Ah, thanks. I've found what I think you were talking about:

-D ARDUINO_LMIC_PROJECT_CONFIG_H_SUPPRESS

For reference to any others seeing a similar issue, it looks like the arduino-cli build.extra_flags property will override whatever is in your boards.txt See this issue, so I've had to copy the flags from my boards.txt into the command so that I get everything all in one go:

arduino-cli compile --profile lora_sensor --build-property build.extra_flags="-DARDUINO_SAMD_ZERO -DARM_MATH_CM0PLUS -DADAFRUIT_FEATHER_M0 -D__SAMD21G18A__ {build.usb_flags} -D CFG_eu868 -D ARDUINO_LMIC_PROJECT_CONFIG_H_SUPPRESS"

Thanks for your help!