Step 3: Scaffold the firmware
Create an ESP-IDF C++ project:
idf.py create-project device
cd device
Add the RelayX Device SDK for C++ to device/main/idf_component.yml:
dependencies:
relay/device-cpp: "^0.3.0"
idf: ">=5.0"
Create device/main/app_shared.h. This header holds the config constants and shared globals used across the tutorial:
#pragma once
#include <atomic>
#include <cstdint>
#include "freertos/FreeRTOS.h"
#include "freertos/event_groups.h"
#include "driver/gpio.h"
#include "relay/device.h"
#define WIFI_SSID ""
#define WIFI_PASS ""
#define I2C_SDA_GPIO GPIO_NUM_21
#define I2C_SCL_GPIO GPIO_NUM_22
#define INA219_I2C_ADDR 0x40
#define RELAY_GPIO GPIO_NUM_26
#define RELAY_ACTIVE_HIGH 0
#define RPC_SET_STATE "state"
#define RPC_UPDATE_RATE "updateSampleRate"
#define TELEMETRY_POWER "power"
#define TELEMETRY_CURRENT "current"
#define TELEMETRY_VOLT "volt"
constexpr uint32_t SAMPLE_RATE_MIN_MS = 100;
constexpr uint32_t SAMPLE_RATE_MAX_MS = 600000;
constexpr uint32_t SAMPLE_RATE_DEFAULT_MS = 10000;
extern std::atomic<uint32_t> g_sample_rate_ms;
extern RelayDevice *g_device;
extern EventGroupHandle_t g_state_events;
constexpr EventBits_t DEVICE_READY_BIT = BIT0;
extern const relay_device_config_t device_config;
Fill in your WiFi credentials. The RelayX credentials are defined in the next step, inside app_shared.cpp.