Skip to main content
Version: 0.0.x

IoT Quick Start

The IoT SDK enables real-time audio conferencing by connecting devices directly to the VideoSDK server. Beyond data collection, IoT devices become interactive nodes—joining meetings, sharing media or sensor data, and subscribing to streams—transforming them into active participants within a connected ecosystem.

Prerequisites

Before you get started, ensure you have the following:

  • Python: Python version >= 3.11
  • Video SDK Developer Account (Not having one, follow Video SDK Dashboard)

Install VideoSDK's IoT component

Step 1: Setup for esp-idf

Install and configure the ESP-IDF environment on your system to prepare the toolchain, dependencies, and base project structure for development. For more information visit ESP-IDF

// Tools
brew install cmake ninja dfu-util ccache git wget flex bison gperf
brew install openssl libffi
// Create Project directory
mkdir esp
cd esp

//Now Clone esp-idf from the github
git clone -b v5.3 https://github.com/espressif/esp-idf.git
cd esp-idf

// Set Python env path and install ESP-IDF tools
./install.sh

//Export ESP-IDF environment variables
. ./export.sh
//or
source export.sh

// Create a esp-idf project
cd ~/esp
idf.py create-project your-project-name
cd your-project-name

Step 2: Add IoT SDK component

To integrate the IoT SDK component, create a file named idf_component.yml in your main folder and then clone the repository below.

git clone https://github.com/videosdk-live/IoTSdk

Once cloned, update your idf_component.yml file as shown below.

main/idf_component.yml
dependencies:
IoTSdk:
path: // Full local path of the component
mdns: '*'
espressif/esp_audio_codec: ~2.3.0
espressif/esp_codec_dev: ~1.3.4
espressif/esp_video_codec: ~0.5.2
espressif/esp_audio_effects: ~1.1.0
esp_lcd_ek79007:
version: ~1.0.2
rules:
- if: target in [esp32p4]
espressif/esp_lcd_ili9881c:
version: ~1.0.1
rules:
- if: target in [esp32p4]
protocol_examples_common:
path: ${IDF_PATH}/examples/common_components/protocol_examples_common
## Required IDF version
idf:
version: '>=4.1.0'
sepfy/srtp: ^2.3.0

Step 3: Update your CmakeLists.txt

This ensures that your project links correctly with the required IoT SDK and ESP-IDF components.Make sure to replace your project name with "your-project-name.c". For more information visit CMake

main/cmakelists.txt
idf_component_register(SRCS
"quick_start.c"
INCLUDE_DIRS "."
REQUIRES mbedtls REQUIRES json REQUIRES esp_netif REQUIRES fatfs REQUIRES vfs REQUIRES esp_common REQUIRES esp_timer REQUIRES esp_lcd REQUIRES nvs_flash
)

target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")

Step 4: Hardware configuration

Inside your project directory, create a file named kconfig.projbuild to select your microcontroller configuration. This configures hardware-specific options before compilation. For more information visit kconfig

main/kconfig.projbuild
menu "Set Microcontroller "

choice AUDIO_BOARD
prompt "Audio hardware board"
default ESP32S3_XIAO
help
Select an audio board to use

config ESP32_S3_KORVO_2_V3_0_BOARD
bool "ESP32-S3-Korvo-2"
depends on IDF_TARGET_ESP32S3
config ESP32S3_XIAO
bool "ESP32-S3-XIAO"
endchoice

endmenu

Step 5: Create Partitions Table

Create a file named partitions.csv in your project folder. This file includes the flash memory partitions for your device. Different boards need different partition layouts for firmware and storage. For more information visit Partitions Table

partitions.csv
# ESP-IDF Partition Table
# Name, Type, SubType, Offset, Size, Flags
nvs, data, nvs, 0x9000, 0x6000,
phy_init, data, phy, 0xf000, 0x1000,
factory, app, factory, 0x10000, 4M,

Step 6: Add board configurations

Create a file named sdkconfig.defaults in your project folder. This file includes default build and Wi-Fi configuration values and sets essential project parameters such as target chip, memory, and networking. For more information sdkconfig

sdkcongfig.defaults
CONFIG_IDF_TARGET="esp32s3"
CONFIG_APP_RETRIEVE_LEN_ELF_SHA=16
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
CONFIG_PARTITION_TABLE_CUSTOM=y
CONFIG_ESP32S3_XIAO_SENSE=y
CONFIG_EXAMPLE_WIFI_SSID="myssid"
CONFIG_EXAMPLE_WIFI_PASSWORD="mypassword"
CONFIG_EXAMPLE_CONNECT_IPV6=n
CONFIG_ESP_PHY_REDUCE_TX_POWER=y
CONFIG_SPIRAM=y
CONFIG_SPIRAM_MODE_OCT=y
CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_240=y
CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE=2048
CONFIG_ESP_MAIN_TASK_STACK_SIZE=4096
CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU1=n
CONFIG_ESP_IPC_TASK_STACK_SIZE=2048
CONFIG_ESP_WIFI_DYNAMIC_RX_BUFFER_NUM=16
CONFIG_ESP_WIFI_STATIC_TX_BUFFER_NUM=32
CONFIG_ESP_WIFI_CACHE_TX_BUFFER_NUM=64
CONFIG_LWIP_IPV6_AUTOCONFIG=y
CONFIG_LWIP_IPV6_DHCP6=y
CONFIG_LWIP_TCP_SND_BUF_DEFAULT=5744
CONFIG_LWIP_TCP_WND_DEFAULT=5744
CONFIG_MBEDTLS_EXTERNAL_MEM_ALLOC=y
CONFIG_MBEDTLS_SSL_PROTO_DTLS=y
CONFIG_PTHREAD_TASK_STACK_SIZE_DEFAULT=8192

Step 7: Update your-project-main.c

Write your project logic inside your-project-main.c. This is where you’ll add the actual logic of your project, initialize the IoT SDK, handle connections, and manage data flow.

main/your-project-main.c
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <sys/param.h>
#include <sys/time.h>
#include "esp_event.h"
#include "esp_log.h"
#include "esp_mac.h"
#include "esp_netif.h"
#include "esp_partition.h"
#include "esp_system.h"
#include "freertos/FreeRTOS.h"
#include "mdns.h"
#include "nvs_flash.h"
#include "protocol_examples_common.h"
#include "videosdk.h"

static const char *TAG = "VideoSDK"; // Logging tag
const char *token = "GENRERATED_TOKEN"; // Your VideoSDK Authentication token
const char *meetingId = "MEETING_ID" ;
// Task to create a meeting using the VideoSDK
static void meeting_task(void *pvParameters)
{


create_meeting_result_t result = create_meeting(token); // Create meeting using IoT SDK

if (result.room_id)
{
ESP_LOGI(TAG, "Created meeting roomId = %s", result.room_id);
meetingId = result.room_id; // Set global meetingId`
free(result.room_id); // Free allocated memory
}
else
{
ESP_LOGE(TAG, "Failed to create meeting");
}

ESP_LOGI(TAG, "meeting_task finished, deleting self");
vTaskDelete(NULL); // Delete task after completion
}

void app_main(void)
{
static char deviceid[32] = {0}; // Buffer to hold device ID
uint8_t mac[8] = {0}; // MAC address buffer

ESP_LOGI(TAG, "[APP] Startup..");
ESP_LOGI(TAG, "[APP] Free memory: %d bytes", esp_get_free_heap_size());
ESP_LOGI(TAG, "[APP] IDF version: %s", esp_get_idf_version());

// Configure logging levels
esp_log_level_set("*", ESP_LOG_INFO);
esp_log_level_set("esp-tls", ESP_LOG_VERBOSE);
esp_log_level_set("MQTT_CLIENT", ESP_LOG_VERBOSE);
esp_log_level_set("MQTT_EXAMPLE", ESP_LOG_VERBOSE);
esp_log_level_set("TRANSPORT_BASE", ESP_LOG_VERBOSE);
esp_log_level_set("TRANSPORT", ESP_LOG_VERBOSE);
esp_log_level_set("OUTBOX", ESP_LOG_VERBOSE);

// Initialize system components
ESP_ERROR_CHECK(nvs_flash_init());
ESP_ERROR_CHECK(esp_netif_init());
ESP_ERROR_CHECK(esp_event_loop_create_default());
ESP_ERROR_CHECK(example_connect());

// Generate unique device ID from MAC address of your esp
if (esp_read_mac(mac, ESP_MAC_WIFI_STA) == ESP_OK)
{
sprintf(deviceid, "esp32-%02x%02x%02x%02x%02x%02x",
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
ESP_LOGI(TAG, "Device ID: %s", deviceid);
}

// Create a task to handle meeting creation
BaseType_t ok = xTaskCreate(meeting_task, "meeting_task", 16384, (void *)token, 5, NULL);
if (ok != pdPASS)
{
ESP_LOGE(TAG, "Failed to create meeting_task");
}

// Initialize VideoSDK configuration
init_config_t init_cfg = {
.meetingID = meetingId,
.token = token,
.displayName = "ESP32_Device",
.audioCodec = AUDIO_CODEC_OPUS,
};

result_t init_result = init(&init_cfg); // Initialize SDK with config
printf("Result: %d\n", init_result);

// Start publishing audio stream
result_t result_publish = startPublishAudio("your-publisherId");

// Start subscribing to an audio stream
result_t result_susbcribe = startSubscribeAudio("your-subscriberId","your-subscriberToId");

// Keep the session active for a defined duration (adjust as per your application use case)
vTaskDelay(pdMS_TO_TICKS(100000));

// Leave the meeting
result_t result_leave = leave();
printf("Result:%d\n", result_susbcribe);

// Keep main loop alive
while (1)
{
vTaskDelay(pdMS_TO_TICKS(10));
}
}

Step 8: Build & Flash Project

Configure, build, and flash the firmware onto your ESP32 board. This compiles the code, applies the configurations, and uploads it to your device.

warning

Ensure you set the target board correctly; failure to do so may cause the project build to fail.

1. <!-- Run this command to set your board as the target-->
idf.py set-target esp32-s3

2. <!-- Run this command to do menuconfig -->

idf.py menuconfig

a. Inside the component config:
|
|———> mbedtls
| ——>Enable Support DTLS <!-- It enables 3 way handshake -->
| ——>Enable Support TLS <!-- It enables 3 way handshake -->
And click S to save and again enter

b. Inside Example Connection Configuration:
|
|———> WIFI SSID <!-- replace it with your WiFi name -->
|———> WIFI Password <!-- replace it with your WiFi password -->
And click S to save and again enter

c. Inside the Partition table :
|
|———> Partition table (custom partition table CSV)
|———> Enable Custom partition table CSV

d. Adjust the flash size inside Serial flasher config
(because some boards have limited flash memory)
| ——> flash size: 2MB (esp32s3 XIAO sense)
| ——> flash size: 4MB (esp32s3 qorvo2 v3.1)
And click S to save and again enter

e. Inside the Set Microcontroller :
| ——>**Audio hardware board (example : ESP32-S3-Korvo-2)**
| ——> Select your board name
|———> ESP32-S3-XIAO
|———> ESP32- ESP32-S3-Korvo
And click S to save and again enter

3. <!-- Run this command to build the project -->
idf.py build

4. <!-- Run this command to flash the project to your microcontroller -->
idf.py flash monitor

Step 9: Connecting with VideoSDK Client Applications

Integrate IoT devices with VideoSDK client applications. Ensure that both the IoT device and client apps connect to the same room for communication.

tip

You can checkout the complete quick start example here.

Got a Question? Ask us on discord