Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ef4bead

Browse files
committed
add missing user agent method from stash
1 parent 8ae1a05 commit ef4bead

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/AdafruitIO.cpp

Lines changed: 17 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
}
@@ -37,6 +38,7 @@ AdafruitIO::AdafruitIO(const __FlashStringHelper *user, const __FlashStringHelpe
3738
_err_sub = 0;
3839
_throttle_sub = 0;
3940
_packetread_timeout = 100;
41+
_user_agent = 0;
4042

4143
_init();
4244
}
@@ -215,6 +217,21 @@ char* AdafruitIO::version()
215217
return _version;
216218
}
217219

220+
char* AdafruitIO::userAgent()
221+
{
222+
if(!_user_agent) {
223+
_user_agent = (char *)malloc(sizeof(char) * (strlen(version()) + strlen(boardType()) + strlen(connectionType()) + 24));
224+
strcpy(_user_agent, "AdafruitIO-Arduino/");
225+
strcat(_user_agent, version());
226+
strcat(_user_agent, " (");
227+
strcat(_user_agent, boardType());
228+
strcat(_user_agent, "-");
229+
strcat(_user_agent, connectionType());
230+
strcat(_user_agent, ")");
231+
}
232+
return _user_agent;
233+
}
234+
218235
aio_status_t AdafruitIO::mqttStatus()
219236
{
220237
// if the connection failed,

src/AdafruitIO.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class AdafruitIO {
5858
char* boardID();
5959
const char* boardType();
6060
char* version();
61+
char* userAgent();
6162
virtual const char* connectionType() = 0;
6263

6364
protected:
@@ -81,6 +82,7 @@ class AdafruitIO {
8182

8283
char *_err_topic;
8384
char *_throttle_topic;
85+
char *_user_agent;
8486

8587
Adafruit_MQTT_Subscribe *_err_sub;
8688
Adafruit_MQTT_Subscribe *_throttle_sub;

0 commit comments

Comments
 (0)