SinricPro Library
Loading...
Searching...
No Matches
SinricProMessageid.h
1/*
2 * Copyright (c) 2019 Sinric. All rights reserved.
3 * Licensed under Creative Commons Attribution-Share Alike (CC BY-SA)
4 *
5 * This file is part of the Sinric Pro (https://github.com/sinricpro/)
6 */
7
8#pragma once
9
10#include "SinricProNamespace.h"
11namespace SINRICPRO_NAMESPACE {
12
13class MessageID {
14public:
15 MessageID();
16 const String& getID() { return _id; }
17private:
18 String _id;
19};
20
21MessageID::MessageID() {
22 _id = "";
23 for (byte i=0; i<16; i++) {
24 byte rnd = random(255);
25 if (i==4) _id += "-";
26 if (i==6) { _id += "-"; rnd = 0x40 | (0x0F & rnd); } // 0100xxxx to set version 4
27 if (i==8) { _id += "-"; rnd = 0x80 | (0x3F & rnd); } // 10xxxxxx to set reserved bits
28 if (i==10) _id += "-";
29 byte high_nibble = rnd >> 4;
30 byte low_nibble = rnd & 0x0f;
31 _id += "0123456789abcdef"[high_nibble];
32 _id += "0123456789abcdef"[low_nibble];
33 }
34}
35
36} // SINRICPRO_NAMESPACE