golioth / golioth-firmware-sdk

Firmware SDK enabling any IoT device to connect to Golioth - the Universal Connector for IoT
https://golioth.io
Apache License 2.0
53 stars 11 forks source link

Adding Golioth to PlatformIO ESP-IDF/Arduino Project #524

Open atfox98 opened 1 week ago

atfox98 commented 1 week ago

Golioth Firmware SDK Commit Hash

bb11ba9bd2388f30215dd345b3061a946f69003c

Platform/OS

PlatformIO (framework = arduino, espidf). Appears to be ESP-IDF 4.4.6

Hardware Target

ESP32

What host OS are you using?

Windows 10

Current Behavior

Problems including golioth-firmware-sdk into PlatformIO project. Golioth settings show up in menuconfig but compilation fails. See repo @ https://github.com/atfox98/golioth-pio.

Expected Behavior

Successful build

Steps To Reproduce

Clone minimal example repository @ https://github.com/atfox98/golioth-pio

Logs, console output, or any kind of debug information

Compiling .pio\build\esp32dev\components\golioth-firmware-sdk\src\zcbor_utils.o
*** [.pio\build\esp32dev\.pio\build\esp32dev\isrgrootx1.der.o] Source `.pio\build\esp32dev\isrgrootx1.der.S' not found, needed by target `.pio\build\esp32dev\.pio\build\esp32dev\isrgrootx1.der.o'.
atfox98 commented 5 days ago

Found some advice on the espressif forums (buried on page 2) to add a build flag to the platformio configuration. I added the following to platformio.ini and am now getting a successful build:

build_flags = 
-DCOMPONENT_EMBED_TXTFILES=components/golioth-firmware-sdk/src/isrgrootx1.der

I really wonder why this was needed as golioth-firmware-sdk/port/esp_idf/components/golioth_sdk/CMakeLists.txt clearly has this in lines 50-51. I have pushed this changed into my minimal example repository. I plan to test a few of the golioth examples to make sure everything is working then close the issue.

MarkoPura commented 5 days ago

Hey @atfox98, great find, glad you can now build your application.

atfox98 commented 21 hours ago

I started having problems again when I adapted the golioth hello example. There were a ton of linker errors - undefined references to every golioth function I called. I inspected all the build artifacts and tried several things to fix this before finally posting on the PlatformIO forums.

Turns out the problem here was between C and C++. There are some changes you can make to the golioth header files to address this. maxgerhardt provides several links in his response to my forum post with more details.

In the meantime, I was able to fix the linker errors by throwing an extern "C" { } around the includes for the golioth headers.

MarkoPura commented 20 hours ago

I overlooked the fact that PlatformIO applications are written in C++. We do have a minimal example for ESP-IDF to verify that a C++ application can be used with Golioth. It also uses the extern "C" around the includes as your application. We'll take a look at adding changes to header files to address the issue.