PlatformIO Community

Use Google Cloud IoT SDK with platformio

Hy,
I am quite new to developing with esp-idf and platformio. I have a project, which should connect to the google cloud iot core and publish sensor datas.
Previous I used the arduino platform to program the esp32 and the connection to the google cloud iot core worked already. However, with the arduino platform, i did not get the required performance, so I want to switch to the esp-idf.

I´ve already implemented all functionalities (measuring sensor data, etc.) up to connecting and publishing data to the google cloud iot core. To manage this, I´d like to use the following cloud framework: https://github.com/espressif/esp-google-iot

But I do not have any idea how to include this into platformio…

(Probably there is also an easier way, to enable the required functionality ?)
Any help is appreciated

Many thanks in advance
Thomas

As you can see from the included component.mk, just follow the PlatformIO documentation on adding a component to the project.

An example project which uses ESP-IDF components is the espidf-aws-iot project which is also mentioned in the docs.

Thanks a lot for your fast response @maxgerhardt
I tried to include the component, as mentioned in the documentation, but somehow, something is not working correctly…

As you can see in the following picture, I´ve the project “Test_EspIdf”. In this project, I´ve created the components folder and there I´ve included the whole esp-google-iot-master project (just downloaded from the branch)

image

then I have included the component in the CMakeList.txt of the project:

cmake_minimum_required(VERSION 3.16.0)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
list(APPEND EXTRA_COMPONENT_DIRS esp-google-iot-master)
project(Test_EspIdf)

Finally I added the private_key in the certs folder of my sourcefolder and edited the component.mk & the cmakelist:

component.mk:

COMPONENT_EMBED_TXTFILES := certs/private_key.pem

ifndef IDF_CI_BUILD

    $(COMPONENT_PATH)/certs/private_key.pem:
@echo "Missing PEM file $@. This file identifies the ESP32 to Google Cloud IoT Core for the example."

    exit 1

else

$(COMPONENT_PATH)/certs/private_key.pem:

    @echo "Dummy certificate data for continuous integration" > $@

endif

CMakeList.txt:

# The commented lines has been the previous content:

# FILE(GLOB_RECURSE app_sources ${CMAKE_SOURCE_DIR}/src/*.*)

# idf_component_register(SRCS ${app_sources})

set(COMPONENT_SRCS "main.c")

set(COMPONENT_ADD_INCLUDEDIRS ".")

register_component()

if(IDF_CI_BUILD)

     add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/certs/private_key.pem

                         COMMAND echo "Dummy certificate data for continuous integration" >

                                 certs/private_key.pem

                         WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}

                         VERBATIM)

     add_custom_target(example_certificates DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/certs/private_key.pem)

     add_dependencies(${COMPONENT_TARGET} example_certificates)

     target_add_binary_data(${COMPONENT_TARGET} "${CMAKE_CURRENT_BINARY_DIR}/certs/private_key.pem" TEXT)

 else()

    target_add_binary_data(${COMPONENT_TARGET} "certs/private_key.pem" TEXT)

 endif()

In my src/main.c where the current program is running, I just included some example methods (just copied from the example “smart outlet” from the branch to see if it is working).

If I try to build, I always get following error:

*** [.pio\build\esp32dev\esp-idf.pio\build\esp32dev\private_key.pem.S.o] Source .pio\build\esp32dev\private_key.pem.S' not found, needed by target .pio\build\esp32dev\esp-idf.pio\build\esp32dev\private_key.pem.S.o’.

Thanks a lot for the help

how about adding this line to platformio.ini file

board_build.embed_txtfiles =
   src/certs/private_key.pem

and remove if(IDF_CI_BUILD) … from the CMakeList.txt,
for me at least it builds smart_outlet.c , haven’t tested yet

Did you manage to port the project?