SensESP 3.0.1
Universal Signal K sensor toolkit ESP32
Loading...
Searching...
No Matches
uuid.cpp
Go to the documentation of this file.
1#include "uuid.h"
2
3namespace sensesp {
4
5String generate_uuid4() {
6 // implementation copied from https://github.com/protohaus/ESP_UUID
7 // to avoid additional external dependencies.
8 uint8_t buffer_[16];
9 String uuid_str;
10
11 // Generate 16 random bytes. On ESP32, these are actually random if the
12 // radio is enabled.
13 for (int i = 0; i < 16; i += 4) {
14 uint32_t random = esp_random();
15 memcpy(&buffer_[i], &random, 4);
16 }
17
18 uuid_str.reserve(36 + 1); // Include NULL / terminator byte
19
20 for (int i = 0; i < 16; i++) {
21 if (i == 4 || i == 6 || i == 8 || i == 10) {
22 uuid_str += "-";
23 }
24 uuid_str += String(buffer_[i] >> 4, HEX);
25 uuid_str += String(buffer_[i] & 0x0F, HEX);
26 }
27 return uuid_str;
28}
29
30} // namespace sensesp
String generate_uuid4()
Generate a random UUIDv4 string.
Definition uuid.cpp:5