Skip to main content

Prerequisites

Before beginning to use this SDK, ensure that your system has the following prerequisites.

1. ESP-IDF:

  • This SDK is built with and for projects that use the ESP-IDF v4.4.4.
  • You can refer to Espressif's official installation guides which you can find here.
  • Remember to choose the version v4.4.4 during installation.

2. Cloning the repository:

  • Click here to go to our ESP32 SDK.
  • Create a folder called components in your source directory. You can do this by running the following in your command line.
mkdir components
  • Through your shell, go to the components directory.
  • run
git clone --recursive https://github.com/golain-io/golain-esp-sdk.git

3. Cloning Nanopb:

One of the dependancies for our SDK is nanopb. :

  • Navigate to the the component folder through your shell by running.
cd components
  • Run
git clone https://github.com/golain-io/nanopb.git

4. Nanopb:

  • Install prerequisites for nanopb by running the following shell script:
    python3 -m pip install grpcio protobuf
  • You can get nanopb from here. The repo has the tools required to compile .proto files as well as he source and header files required to use the nanopb component.
  • You can compile your protobuf files into any folder by moving to your folder and then running: {relative path for nanopb}/generator/nanopb_generator.py {name of your protobuf}.proto

Example: The following will compile your proto file into your main folder.

   cd main

../components/golain-esp-sdk/nanopb/generator/nanopb_generator.py shadow.proto

You can run the following in the root folder of our example to compile the protos in the main/protos folder:

make -C main/protos build-protos
note

This will work only if shadow.proto is in your main folder.

  • You can find additional documentation for nanopb here.

5. CMakeLists.txt changes:

  • We have to make to major changes to two CMakeLists.txt files.

  • The root CMakeLists.txt file needs to be changed in order to allow the compiler to include all files in the "components" folder during compilation.

    • This is what a typical project direcory will look like:
          Project directory
      - build
      - components
      - main
      - CMakeLists.txt <-- This file needs to be altered
      - sdkconfig
    • In this file, add the following line above include($ENV{IDF_PATH}/tools/cmake/project.cmake) :
          set(EXTRA_COMPONENT_DIRS components)
  • The next file that needs to be changed is the CMakeLists.txt file inside the main directory:

    •     Project directory
      - build
      - components
      - main
      - main.c
      - CMakeLists.txt <-- This file needs to be altered
      - CMakeLists.txt
      - sdkconfig
    • This is what you should see when you first open your file:

          idf_component_register(SRCS "main.c" 
      INCLUDE_DIRS ".")
    • Alter that to:

          idf_component_register(SRCS "main.c" "{relative path for your device shadow protobuf}/{name of your device shadow protobuf}.pb.c" "{relative path for your device data protobuf}/{name of your device data protobuf}.pb.c"
      INCLUDE_DIRS "."
      REQUIRES nanopb nvs_flash golain-esp-sdk)
      # Add all compiled protobuf you are using here. This includes Device Shadow and Data Points.
      # This currently only includes golain sdks and a few pther esp-idf components required to make our components work.
      # Add any other components you may have installed or plan to use here.

Additional notes before using this component:

  • The following components are needed for the mqtt service to operate:

  • The following are things that should be initialised before mqtt is started:

    • nvs-flash
    • wifi