Skip to content

Commit e887f5f

Browse files
committed
Merge branch 'master' of github.com:adafruit/Adafruit_IO_Arduino into groups
2 parents fa12494 + ef4bead commit e887f5f

14 files changed

+199
-0
lines changed

src/AdafruitIO.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ AdafruitIO::AdafruitIO(const char *user, const char *key)
2222
_err_sub = 0;
2323
_throttle_sub = 0;
2424
_packetread_timeout = 100;
25+
_user_agent = 0;
2526

2627
_init();
2728
}
@@ -184,6 +185,37 @@ aio_status_t AdafruitIO::status()
184185
return _status;
185186
}
186187

188+
char* AdafruitIO::boardID()
189+
{
190+
return AdafruitIO_Board::id();
191+
}
192+
193+
const char* AdafruitIO::boardType()
194+
{
195+
return AdafruitIO_Board::type();
196+
}
197+
198+
char* AdafruitIO::version()
199+
{
200+
sprintf(_version, "%d.%d.%d", ADAFRUITIO_VERSION_MAJOR, ADAFRUITIO_VERSION_MINOR, ADAFRUITIO_VERSION_PATCH);
201+
return _version;
202+
}
203+
204+
char* AdafruitIO::userAgent()
205+
{
206+
if(!_user_agent) {
207+
_user_agent = (char *)malloc(sizeof(char) * (strlen(version()) + strlen(boardType()) + strlen(connectionType()) + 24));
208+
strcpy(_user_agent, "AdafruitIO-Arduino/");
209+
strcat(_user_agent, version());
210+
strcat(_user_agent, " (");
211+
strcat(_user_agent, boardType());
212+
strcat(_user_agent, "-");
213+
strcat(_user_agent, connectionType());
214+
strcat(_user_agent, ")");
215+
}
216+
return _user_agent;
217+
}
218+
187219
aio_status_t AdafruitIO::mqttStatus()
188220
{
189221
// if the connection failed,

src/AdafruitIO.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "AdafruitIO_Dashboard.h"
2121
#include "AdafruitIO_Data.h"
2222
#include "ArduinoHttpClient.h"
23+
#include "util/AdafruitIO_Board.h"
2324

2425
#ifndef ADAFRUIT_MQTT_VERSION_MAJOR
2526
#error "This sketch requires Adafruit MQTT Library v0.17.0 or higher. Please install or upgrade using the Library Manager."
@@ -54,6 +55,12 @@ 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+
char* userAgent();
62+
virtual const char* connectionType() = 0;
63+
5764
protected:
5865
virtual void _connect() = 0;
5966
aio_status_t _status = AIO_IDLE;
@@ -62,6 +69,8 @@ class AdafruitIO {
6269
Adafruit_MQTT *_mqtt;
6370
HttpClient *_http;
6471

72+
char _version[10];
73+
6574
const char *_host = "io.adafruit.com";
6675
uint16_t _mqtt_port = 8883;
6776
uint16_t _http_port = 443;
@@ -73,6 +82,7 @@ class AdafruitIO {
7382

7483
char *_err_topic;
7584
char *_throttle_topic;
85+
char *_user_agent;
7686

7787
Adafruit_MQTT_Subscribe *_err_sub;
7888
Adafruit_MQTT_Subscribe *_throttle_sub;

src/AdafruitIO_Ethernet.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ class AdafruitIO_Ethernet : public AdafruitIO {
4444
return _status;
4545
}
4646

47+
const char* connectionType()
48+
{
49+
return "ethernet_wing";
50+
}
51+
4752
protected:
4853
byte _mac[6] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
4954
uint16_t _port = 1883;

src/AdafruitIO_FONA.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ class AdafruitIO_FONA : public AdafruitIO {
6060
return AIO_NET_CONNECTED;
6161
}
6262

63+
const char* connectionType()
64+
{
65+
return "fona";
66+
}
67+
6368
protected:
6469
uint16_t _mqtt_port = 1883;
6570

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
@@ -56,4 +56,9 @@ aio_status_t AdafruitIO_ESP8266::networkStatus()
5656

5757
}
5858

59+
const char* AdafruitIO_ESP8266::connectionType()
60+
{
61+
return "wifi";
62+
}
63+
5964
#endif // ESP8266

src/wifi/AdafruitIO_ESP8266.h

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

3030
aio_status_t networkStatus();
31+
const char* connectionType();
3132

3233
protected:
3334
void _connect();

src/wifi/AdafruitIO_MKR1000.cpp

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

5959
}
6060

61+
const char* AdafruitIO_MKR1000::connectionType()
62+
{
63+
return "wifi";
64+
}
65+
6166
#endif // ARDUINO_ARCH_SAMD

src/wifi/AdafruitIO_MKR1000.h

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

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

3334
protected:
3435
void _connect();

0 commit comments

Comments
 (0)