This project offers a example on developing a gRPC client application designed to dispatch unary gRPC calls to a gRPC server, utilizing HTTP/2 as the underlying protocol.
The project incorporates the following building blocks:
-
ESP-IDF - ESP-32 Development Framework
-
nghttp2 - integrated with esp-idf extra components
-
nanopb - compilation of protobufs, encoding/decoding of messages and responses into binary wire format
-
kuksa.val Databroker - protobuf definitions for communicating via gRPC
Note that this is a simplistic illustration of interacting with the Kuksa Databroker. For more detailed message exchanges, consider starting with encoder.c
or decoder.c
. These files contain the protobuf-specific implementations necessary for the exchange. See grpc.c
for the HTTP/2 gRPC implementation.
An application scenario would be conceivable in which the ESP32 represents a microcontroller that sends sensor values such as the current speed of the vehicle to the Kuksa Databroker via GRPC.
- A development board with ESP32/ESP32-S2/ESP32-C3 SoC (e.g., ESP32-DevKitC, ESP-WROVER-KIT, etc.)
- A USB cable for power supply and programming
- Install the esp-idf toolchain as shown in the esp-idf docs.
idf.py menuconfig
- Incorporate nanopb specific header files
chmod +x install_nanopb.sh
./install_nanopb.sh
- Compile Protobufs
- Activate the esp-idf development toolchain and environment with
. ./export.sh
inside your toolchain installation directory (typically under~/esp/...
) - execute shell script
compile_proto.sh
📝 Sometimes nanopb will give you a warning, that some dependencies are not installed. Install them with
pip install protobuf grpcio-tools
- Install expra components In the project root, execute the command below to add the nghttp2 lib to the project.
idf.py add-dependency "espressif/nghttp^1.58.0"
- Open the project configuration menu (
idf.py menuconfig
) to configure Wi-Fi or Ethernet.
Refer to the main.c
file to modify the message type and set the target URL with a kuksa Databroker running. To send a request for retrieving information, such as the vehicle's current speed, utilize the get section of the code, which is already uncommented. If you wish to set a value in the broker, uncomment the set section and employ the defined constants for set.
Build the project and flash it to the board, then run monitor tool to view serial output:
idf.py flash monitor
(To exit the serial monitor, type Ctrl-]
or Ctrl-TX
on Mac.)
See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.