Skip to content

Commit 8ae1a05

Browse files
authored
Merge pull request #8 from adafruit/board_id
Board Metadata Utilities
2 parents 68b9c8d + 566e404 commit 8ae1a05

14 files changed

+181
-0
lines changed

src/AdafruitIO.cpp

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

202+
char* AdafruitIO::boardID()
203+
{
204+
return AdafruitIO_Board::id();
205+
}
206+
207+
const char* AdafruitIO::boardType()
208+
{
209+
return AdafruitIO_Board::type();
210+
}
211+
212+
char* AdafruitIO::version()
213+
{
214+
sprintf(_version, "%d.%d.%d", ADAFRUITIO_VERSION_MAJOR, ADAFRUITIO_VERSION_MINOR, ADAFRUITIO_VERSION_PATCH);
215+
return _version;
216+
}
217+
202218
aio_status_t AdafruitIO::mqttStatus()
203219
{
204220
// if the connection failed,

src/AdafruitIO.h

Lines changed: 8 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."
@@ -54,6 +55,11 @@ class AdafruitIO {
5455
virtual aio_status_t networkStatus() = 0;
5556
aio_status_t mqttStatus();
5657

58+
char* boardID();
59+
const char* boardType();
60+
char* version();
61+
virtual const char* connectionType() = 0;
62+
5763
protected:
5864
virtual void _connect() = 0;
5965
aio_status_t _status = AIO_IDLE;
@@ -62,6 +68,8 @@ class AdafruitIO {
6268
Adafruit_MQTT *_mqtt;
6369
HttpClient *_http;
6470

71+
char _version[10];
72+
6573
const char *_host = "io.adafruit.com";
6674
uint16_t _mqtt_port = 8883;
6775
uint16_t _http_port = 443;

src/AdafruitIO_Ethernet.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ class AdafruitIO_Ethernet : public AdafruitIO {
5151
return _status;
5252
}
5353

54+
const char* connectionType()
55+
{
56+
return "ethernet_wing";
57+
}
58+
5459
protected:
5560
byte _mac[6] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
5661
uint16_t _port = 1883;

src/AdafruitIO_FONA.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ class AdafruitIO_FONA : public AdafruitIO {
6868
return AIO_NET_CONNECTED;
6969
}
7070

71+
const char* connectionType()
72+
{
73+
return "fona";
74+
}
75+
7176
protected:
7277
uint16_t _mqtt_port = 1883;
7378

src/util/AdafruitIO_Board.cpp

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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_SAMD_MKR1000)
17+
const char AdafruitIO_Board::_type[] = "mkr1000";
18+
#elif defined(ARDUINO_SAMD_FEATHER_M0)
19+
const char AdafruitIO_Board::_type[] = "feather_m0";
20+
#elif defined(ARDUINO_AVR_FEATHER32U4)
21+
const char AdafruitIO_Board::_type[] = "feather_32u4";
22+
#elif defined(ARDUINO_STM32_FEATHER)
23+
const char AdafruitIO_Board::_type[] = "feather_wiced";
24+
#elif defined(ESP8266)
25+
const char AdafruitIO_Board::_type[] = "esp8266";
26+
#else
27+
const char AdafruitIO_Board::_type[] = "unknown";
28+
#endif
29+
30+
const char* AdafruitIO_Board::type()
31+
{
32+
return AdafruitIO_Board::_type;
33+
}
34+
35+
#if defined(ARDUINO_ARCH_SAMD)
36+
37+
char* AdafruitIO_Board::id()
38+
{
39+
volatile uint32_t val1, val2, val3, val4;
40+
volatile uint32_t *ptr1 = (volatile uint32_t *)0x0080A00C;
41+
val1 = *ptr1;
42+
volatile uint32_t *ptr = (volatile uint32_t *)0x0080A040;
43+
val2 = *ptr;
44+
ptr++;
45+
val3 = *ptr;
46+
ptr++;
47+
val4 = *ptr;
48+
49+
sprintf(AdafruitIO_Board::_id, "%8x%8x%8x%8x", val1, val2, val3, val4);
50+
51+
return AdafruitIO_Board::_id;
52+
}
53+
54+
#elif defined(ARDUINO_ARCH_AVR)
55+
56+
char* AdafruitIO_Board::id()
57+
{
58+
for(int i=0; i < 32; i++) {
59+
sprintf(&AdafruitIO_Board::_id[i*2],"%02x", boot_signature_byte_get(i));
60+
}
61+
return AdafruitIO_Board::_id;
62+
}
63+
64+
#elif defined(ESP8266)
65+
66+
char* AdafruitIO_Board::id()
67+
{
68+
sprintf(AdafruitIO_Board::_id, "%06x", ESP.getChipId());
69+
return AdafruitIO_Board::_id;
70+
}
71+
72+
#elif defined(ARDUINO_STM32_FEATHER)
73+
74+
char* AdafruitIO_Board::id()
75+
{
76+
uint32_t* p_unique_id = (uint32_t*) (0x1FFF7A10);
77+
sprintf(AdafruitIO_Board::_id, "%08lX%08lX%08lX", p_unique_id[2], p_unique_id[1], p_unique_id[0]);
78+
return AdafruitIO_Board::_id;
79+
}
80+
81+
#else
82+
83+
char* AdafruitIO_Board::id()
84+
{
85+
strcpy(AdafruitIO_Board::_id, "unknown");
86+
return AdafruitIO_Board::_id;
87+
}
88+
89+
#endif

src/util/AdafruitIO_Board.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
static const char _type[];
29+
static const char* type();
30+
31+
32+
};
33+
34+
#endif // ADAFRUITIO_BOARD_H

src/wifi/AdafruitIO_ESP8266.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,9 @@ aio_status_t AdafruitIO_ESP8266::networkStatus()
6565

6666
}
6767

68+
const char* AdafruitIO_ESP8266::connectionType()
69+
{
70+
return "wifi";
71+
}
72+
6873
#endif // ESP8266

src/wifi/AdafruitIO_ESP8266.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class AdafruitIO_ESP8266 : public AdafruitIO {
2929
~AdafruitIO_ESP8266();
3030

3131
aio_status_t networkStatus();
32+
const char* connectionType();
3233

3334
protected:
3435
void _connect();

src/wifi/AdafruitIO_MKR1000.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,9 @@ aio_status_t AdafruitIO_MKR1000::networkStatus()
6767

6868
}
6969

70+
const char* AdafruitIO_MKR1000::connectionType()
71+
{
72+
return "wifi";
73+
}
74+
7075
#endif // ARDUINO_ARCH_SAMD

src/wifi/AdafruitIO_MKR1000.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class AdafruitIO_MKR1000 : public AdafruitIO {
3030
~AdafruitIO_MKR1000();
3131

3232
aio_status_t networkStatus();
33+
const char* connectionType();
3334

3435
protected:
3536
void _connect();

0 commit comments

Comments
 (0)