How to create 16-bit UUID's ?

rzodkiew
Posts: 2
Joined: Wed Nov 10, 2021 10:43 am

How to create 16-bit UUID's ?

Postby rzodkiew » Wed Nov 10, 2021 11:00 am

Hello ,

I use 'gatts_server_service_table' example as base in my project, I want to make uuid's and characteristic with 16-bit UUID. I tried many solutions I found on this forum, but always UUID is 128-bit (many cases 16-bit inside base_uuid - {0xFB,0x34...})

How i can make 16-bit uuid service?

Thanks, SO
PL
Last edited by rzodkiew on Fri Nov 12, 2021 11:33 am, edited 1 time in total.

User avatar
rudi ;-)
Posts: 1727
Joined: Fri Nov 13, 2015 3:25 pm

Re: How to create 16-bit UUID's ?

Postby rudi ;-) » Thu Nov 11, 2021 3:47 am

many ways to rome
outside of ESP-IDF a few examples
not a complete list, there are many more

online:
https://www.uuidgenerator.net/

github:
https://github.com/typester/esp32-uuid

python 2 and 3

Code: Select all

import uuid

uuid.uuid4()
UUID('xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx')
pythUUID.jpg
pythUUID.jpg (44.52 KiB) Viewed 7261 times
the generation is standard.
uuid1 use time and mac of the pc example, uuid4 use random number

If you want a 16-bit UUID, you have to use a base-uuid, which is fix

more about 16 bit UUIDs example here

for history attached
16-bit UUID Numbers Document.pdf
(472.71 KiB) Downloaded 557 times
and also here more info

did you look for this one?

or more this, (I don't think so, a completely different topic, but you can combine it with uuid1/uuid4) github: short UUID

edit: add links, attached file
-------------------------------------
love it, change it or leave it.
-------------------------------------
問候飛出去的朋友遍全球魯迪

vanBassum
Posts: 68
Joined: Sun Jan 17, 2021 11:59 am

Re: How to create 16-bit UUID's ?

Postby vanBassum » Thu Nov 11, 2021 7:17 am

Hello,

This is how I solved it using the esp_fill_random(guid.raw, 16) function.

Code: Select all

/*
 * Guid.h
 *
 *  Created on: 9 Sep 2020
 *      Author: Bas
 */

#ifndef COMPONENTS_CPP_LIB_MISC_GUID_H_
#define COMPONENTS_CPP_LIB_MISC_GUID_H_

#include <stdint.h>
#include <esp_system.h>

class Guid
{
public:
	uint8_t raw[16];

	Guid()
	{
		memset(raw, 0, 16);
	}


	Guid(uint8_t *data)
	{
		memcpy(raw, data, 16);
	}


	bool IsEmpty()
	{
		bool zero = true;
		for(int i=0; i<sizeof(raw); i++)
			zero &= raw[i] == 0;
		return zero;
	}

	uint32_t ToArray(uint8_t *data)
	{
		if(data != NULL)
		{
			memcpy(data, raw, 16);
		}
		return 16;
	}

	static Guid NewGuid()
	{
		Guid guid;
		esp_fill_random(guid.raw, 16);
		return guid;
	}

	std::string ToString()
	{
		char buff[64];
		sprintf(buff, "%x%x%x%x-%x%x-%x%x-%x%x-%x%x%x%x%x%x", raw[0], raw[1], raw[2], raw[3], raw[4], raw[5], raw[6], raw[7], raw[8], raw[9], raw[10], raw[11], raw[12], raw[13], raw[14], raw[15]);
		return buff;
	}

};


inline bool operator==(Guid const &lhs, Guid const &rhs) { return memcmp(lhs.raw, rhs.raw, sizeof(lhs.raw)) == 0; }


#endif /* COMPONENTS_CPP_LIB_MISC_GUID_H_ */

rzodkiew
Posts: 2
Joined: Wed Nov 10, 2021 10:43 am

Re: How to create 16-bit UUID's ?

Postby rzodkiew » Fri Nov 12, 2021 1:33 pm


Who is online

Users browsing this forum: No registered users and 87 guests