Advertisement
LukacikPavel

UUID

Apr 1st, 2020
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.82 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. #include "freertos/FreeRTOS.h"
  4.  
  5. #include "freertos/task.h"
  6.  
  7. #include "esp_system.h"
  8.  
  9. #include "esp_spi_flash.h"
  10.  
  11. #include "driver/gpio.h"
  12.  
  13.  
  14.  
  15. char *get_device_id()  
  16.  
  17. {  
  18.  
  19.     uint8_t mac_addr[6];  
  20.  
  21.     char *id = (char*)malloc((sizeof(char)*(6*2))+1);  
  22.  
  23.     if (id == NULL) return NULL;  
  24.  
  25.  
  26.  
  27.     esp_read_mac(mac_addr, ESP_MAC_WIFI_STA);  
  28.  
  29.  
  30.  
  31.     for (int i=0; i<6; i++) {  
  32.  
  33.         snprintf(id+(i*2), 3, "%02X", mac_addr[i]);  
  34.  
  35.     }  
  36.  
  37.  
  38.  
  39.     return id;  
  40.  
  41. }  
  42.  
  43.  
  44.  
  45. void app_main()
  46.  
  47. {
  48.  
  49.     printf("Program: Unikatny identifikator cipu ESP8266\n");
  50.  
  51.      
  52.  
  53.     char *uuid = get_device_id();
  54.  
  55.     printf("UUID: %s \n", uuid);
  56.  
  57.     free(uuid);
  58.  
  59.  
  60.  
  61.     while (1) {
  62.  
  63.         vTaskDelay(1000 / portTICK_PERIOD_MS);
  64.  
  65.     }
  66.  
  67.  
  68.  
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement