@@ -16,6 +16,7 @@ AdafruitIO_Group::AdafruitIO_Group(AdafruitIO *io, const char *n):AdafruitIO_MQT
1616{
1717 _io = io;
1818 name = n;
19+ owner = _io->_username ;
1920
2021 _init ();
2122}
@@ -28,12 +29,18 @@ AdafruitIO_Group::~AdafruitIO_Group()
2829 if (_pub)
2930 delete _pub;
3031
32+ if (_get_pub)
33+ delete _get_pub;
34+
3135 if (data)
3236 delete data;
3337
3438 if (_topic)
3539 free (_topic);
3640
41+ if (_get_topic)
42+ free (_get_topic);
43+
3744 if (_group_url)
3845 free (_group_url);
3946
@@ -121,6 +128,11 @@ bool AdafruitIO_Group::save()
121128
122129}
123130
131+ bool AdafruitIO_Group::get ()
132+ {
133+ return _get_pub->publish (" \0 " );
134+ }
135+
124136AdafruitIO_Data* AdafruitIO_Group::getFeed (const char *feed)
125137{
126138 // uint8_t i;
@@ -325,34 +337,42 @@ void AdafruitIO_Group::_init()
325337{
326338
327339 // dynamically allocate memory for mqtt topic and REST URLs
328- _topic = (char *) malloc (sizeof (char ) * (strlen (_io->_username ) + strlen (name) + 8 )); // 8 extra chars for /g/, /csv & null termination
329- _group_url = (char *) malloc (sizeof (char ) * (strlen (_io->_username ) + strlen (name) + 16 )); // 16 extra for api path & null term
330- _create_url = (char *) malloc (sizeof (char ) * (strlen (_io->_username ) + 15 )); // 15 extra for api path & null term
340+ _topic = (char *) malloc (sizeof (char ) * (strlen (owner) + strlen (name) + 8 )); // 8 extra chars for /g/, /csv & null termination
341+ _get_topic = (char *) malloc (sizeof (char ) * (strlen (owner) + strlen (name) + 12 )); // 12 extra chars for /f/, /csv/get & null termination
342+ _group_url = (char *) malloc (sizeof (char ) * (strlen (owner) + strlen (name) + 16 )); // 16 extra for api path & null term
343+ _create_url = (char *) malloc (sizeof (char ) * (strlen (owner) + 15 )); // 15 extra for api path & null term
331344
332345 data = 0 ;
333346
334347 if (_topic && _create_url && _group_url) {
335348
336349 // build topic string
337- strcpy (_topic, _io-> _username );
350+ strcpy (_topic, owner );
338351 strcat (_topic, " /g/" );
339352 strcat (_topic, name);
340353 strcat (_topic, " /csv" );
341354
342355 // build feed url string
343356 strcpy (_group_url, " /api/v2/" );
344- strcat (_group_url, _io-> _username );
357+ strcat (_group_url, owner );
345358 strcat (_group_url, " /groups/" );
346359 strcat (_group_url, name);
347360
348361 // build create url string
349362 strcpy (_create_url, " /api/v2/" );
350- strcat (_create_url, _io-> _username );
363+ strcat (_create_url, owner );
351364 strcat (_create_url, " /groups" );
352365
366+ // build /get topic string
367+ strcpy (_get_topic, owner);
368+ strcat (_get_topic, " /g/" );
369+ strcat (_get_topic, name);
370+ strcat (_get_topic, " /csv/get" );
371+
353372 // setup subscription
354373 _sub = new Adafruit_MQTT_Subscribe (_io->_mqtt , _topic);
355374 _pub = new Adafruit_MQTT_Publish (_io->_mqtt , _topic);
375+ _get_pub = new Adafruit_MQTT_Publish (_io->_mqtt , _get_topic);
356376 _io->_mqtt ->subscribe (_sub);
357377
358378 _sub->setCallback (this , &AdafruitIO_MQTT::subCallback);
@@ -361,10 +381,12 @@ void AdafruitIO_Group::_init()
361381
362382 // malloc failed
363383 _topic = 0 ;
384+ _get_topic = 0 ;
364385 _create_url = 0 ;
365386 _group_url = 0 ;
366387 _sub = 0 ;
367388 _pub = 0 ;
389+ _get_pub = 0 ;
368390
369391 }
370392
0 commit comments