# ESP-IDF UUID Generator
[](/LICENSE)
[](https://visualstudio.microsoft.com)
[](https://platformio.org/)
[](https://registry.platformio.org/libraries/k0i05/esp_uuid)
[](https://components.espressif.com/components/k0i05/esp_uuid)
This ESP32 espressif IoT development framework (esp-idf) RFC-4122 UUID generator component. Information on features and functionality are documented and can be found in the `uuid.h` header file.
## Repository
The component is hosted on github and is located here: <https://github.com/K0I05/ESP32-S3_ESP-IDF_COMPONENTS/tree/main/components/utilities/esp_uuid>
## General Usage
To get started, simply copy the component to your project's `components` folder and reference the `uuid.h` header file as an include. The component includes documentation for the peripheral such as the datasheet, application notes, and/or user manual where applicable.
```text
components
└── esp_uuid
├── CMakeLists.txt
├── README.md
├── LICENSE
├── idf_component.yml
├── library.json
├── documentation
│ └── datasheets, etc.
├── include
│ └── uuid_version.h
│ └── uuid.h
└── uuid.c
```
## Basic Example
Once the component is referenced as an include, the functions should be visible and available for usage. The below example demonstrates variant-4 and random UUID generation with processing time-span results printed to the serial console.
```c
#include <uuid.h>
void utils_uuid_task( void *pvParameters ) {
TickType_t last_wake_time = xTaskGetTickCount ();
uuid_init();
// task loop entry point
for ( ;; ) {
ESP_LOGI(APP_TAG, "######################## UUID - START #########################");
uint64_t start_time = esp_timer_get_time();
uuid_set_mode(UUID_MODE_VARIANT4);
const char* uuid_var = uuid_generate();
uint64_t stop_time = esp_timer_get_time();
uint32_t time_diff = stop_time - start_time;
ESP_LOGI(APP_TAG, "Variant4 UUID (%lu-us): %s", time_diff, uuid_var);
start_time = esp_timer_get_time();
uuid_set_mode(UUID_MODE_RANDOM);
const char* uuid_ran = uuid_generate();
stop_time = esp_timer_get_time();
time_diff = stop_time - start_time;
ESP_LOGI(APP_TAG, "Random UUID (%lu-us): %s", time_diff, uuid_ran);
uint32_t seed1 = random();
uint32_t seed2 = random();
start_time = esp_timer_get_time();
uuid_seed(seed1, seed2);
stop_time = esp_timer_get_time();
time_diff = stop_time - start_time;
ESP_LOGI(APP_TAG, "Seed Time: %lu-us", time_diff);
start_time = esp_timer_get_time();
uuid_set_mode(UUID_MODE_VARIANT4);
const char* uuid_seed = uuid_generate();
stop_time = esp_timer_get_time();
time_diff = stop_time - start_time;
ESP_LOGI(APP_TAG, "Variant4 UUID (%lu-us): %s", time_diff, uuid_seed);
ESP_LOGI(APP_TAG, "######################## UUID - END ###########################");
// pause the task per defined wait period
vTaskDelaySecUntil( &last_wake_time, UTILS_TASK_SAMPLING_RATE );
}
// free resources
vTaskDelete( NULL );
}
```
The results of the UUID generation printed to the serial console are shown below.
```text
I (31627) ESP-IDF COMPONENTS [APP]: ######################## UUID - START #########################
I (31627) ESP-IDF COMPONENTS [APP]: Variant4 UUID (5-us): 053031da-e5cf-4de1-8429-285b0dba59d5
I (31637) ESP-IDF COMPONENTS [APP]: Random UUID (5-us): d29b226d-04b5-e3ae-cd63-e6ec0d5611ab
I (31647) ESP-IDF COMPONENTS [APP]: Seed Time: 1-us
I (31647) ESP-IDF COMPONENTS [APP]: Variant4 UUID (5-us): 3d9d78de-071d-4901-bde4-ded767d8deb8
I (31657) ESP-IDF COMPONENTS [APP]: ######################## UUID - END ###########################
```
## References
Information referenced for this component are outlined as follows:
- RFC-4122 specification: <https://datatracker.ietf.org/doc/html/rfc4122>
- C++ UUID generator (original source): <https://github.com/RobTillaart/UUID/blob/master/README.md>
Copyright (c) 2024 Eric Gionet (<gionet.c.eric@gmail.com>)
idf.py add-dependency "k0i05/esp_uuid^1.2.5"