Skip to content

Commit a693c9e

Browse files
committed
adds board id util
1 parent 68b9c8d commit a693c9e

File tree

4 files changed

+98
-0
lines changed

4 files changed

+98
-0
lines changed

src/AdafruitIO.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,11 @@ aio_status_t AdafruitIO::status()
199199
return _status;
200200
}
201201

202+
char* AdafruitIO::id()
203+
{
204+
return AdafruitIO_Board::id();
205+
}
206+
202207
aio_status_t AdafruitIO::mqttStatus()
203208
{
204209
// if the connection failed,

src/AdafruitIO.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "AdafruitIO_Dashboard.h"
2020
#include "AdafruitIO_Data.h"
2121
#include "ArduinoHttpClient.h"
22+
#include "util/AdafruitIO_Board.h"
2223

2324
#ifndef ADAFRUIT_MQTT_VERSION_MAJOR
2425
#error "This sketch requires Adafruit MQTT Library v0.16.0 or higher. Please install or upgrade using the Library Manager."
@@ -52,6 +53,7 @@ class AdafruitIO {
5253

5354
aio_status_t status();
5455
virtual aio_status_t networkStatus() = 0;
56+
char* id();
5557
aio_status_t mqttStatus();
5658

5759
protected:

src/util/AdafruitIO_Board.cpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//
2+
// Adafruit invests time and resources providing this open source code.
3+
// Please support Adafruit and open source hardware by purchasing
4+
// products from Adafruit!
5+
//
6+
// Copyright (c) 2015-2016 Adafruit Industries
7+
// Authors: Todd Treece
8+
// Licensed under the MIT license.
9+
//
10+
// All text above must be included in any redistribution.
11+
//
12+
#include "AdafruitIO_Board.h"
13+
14+
char AdafruitIO_Board::_id[64] = "";
15+
16+
#if defined(ARDUINO_ARCH_SAMD)
17+
18+
char* AdafruitIO_Board::id()
19+
{
20+
volatile uint32_t val1, val2, val3, val4;
21+
volatile uint32_t *ptr1 = (volatile uint32_t *)0x0080A00C;
22+
val1 = *ptr1;
23+
volatile uint32_t *ptr = (volatile uint32_t *)0x0080A040;
24+
val2 = *ptr;
25+
ptr++;
26+
val3 = *ptr;
27+
ptr++;
28+
val4 = *ptr;
29+
30+
sprintf(AdafruitIO_Board::_id, "%8x%8x%8x%8x", val1, val2, val3, val4);
31+
32+
return AdafruitIO_Board::_id;
33+
}
34+
35+
#elif defined(ARDUINO_ARCH_AVR)
36+
37+
char* AdafruitIO_Board::id()
38+
{
39+
for(int i=0; i < 32; i++) {
40+
sprintf(&AdafruitIO_Board::_id[i*2],"%02x", boot_signature_byte_get(i));
41+
}
42+
return AdafruitIO_Board::_id;
43+
}
44+
45+
#elif defined(ESP8266)
46+
47+
char* AdafruitIO_Board::id()
48+
{
49+
sprintf(AdafruitIO_Board::_id, "%06x", ESP.getChipId());
50+
return AdafruitIO_Board::_id;
51+
}
52+
53+
#else
54+
55+
char* AdafruitIO_Board::id()
56+
{
57+
strcpy(AdafruitIO_Board::_id, "unknown");
58+
return AdafruitIO_Board::_id;
59+
}
60+
61+
#endif

src/util/AdafruitIO_Board.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//
2+
// Adafruit invests time and resources providing this open source code.
3+
// Please support Adafruit and open source hardware by purchasing
4+
// products from Adafruit!
5+
//
6+
// Copyright (c) 2015-2017 Adafruit Industries
7+
// Authors: Todd Treece
8+
// Licensed under the MIT license.
9+
//
10+
// All text above must be included in any redistribution.
11+
//
12+
#ifndef ADAFRUITIO_BOARD_H
13+
#define ADAFRUITIO_BOARD_H
14+
15+
#include "Arduino.h"
16+
17+
#if defined(ARDUINO_ARCH_AVR)
18+
#include <avr/boot.h>
19+
#endif
20+
21+
class AdafruitIO_Board {
22+
23+
public:
24+
25+
static char _id[64];
26+
static char* id();
27+
28+
};
29+
30+
#endif // ADAFRUITIO_BOARD_H

0 commit comments

Comments
 (0)