@@ -18,6 +18,7 @@ AdafruitIO_Feed::AdafruitIO_Feed(AdafruitIO *io, const char *n):AdafruitIO_MQTT(
18
18
name = n;
19
19
_sub = 0 ;
20
20
_pub = 0 ;
21
+ _get_pub = 0 ;
21
22
_dataCallback = 0 ;
22
23
23
24
_init ();
@@ -111,20 +112,6 @@ bool AdafruitIO_Feed::save(double value, double lat, double lon, double ele, int
111
112
112
113
bool AdafruitIO_Feed::get ()
113
114
{
114
- if (!_get_topic)
115
- {
116
- _get_topic = (char *) malloc (sizeof (char ) * (strlen (_io->_username ) + strlen (name) + 12 )); // 12 extra chars for /f/, /csv/get & null termination
117
- strcpy (_get_topic, _io->_username );
118
- strcat (_get_topic, " /f/" );
119
- strcat (_get_topic, name);
120
- strcat (_get_topic, " /csv/get" );
121
- }
122
-
123
- if (!_get_pub)
124
- {
125
- _get_pub = new Adafruit_MQTT_Publish (_io->_mqtt , _get_topic);
126
- }
127
-
128
115
return _get_pub->publish (" \0 " );
129
116
}
130
117
@@ -225,6 +212,7 @@ void AdafruitIO_Feed::_init()
225
212
226
213
// dynamically allocate memory for mqtt topic and REST URLs
227
214
_topic = (char *) malloc (sizeof (char ) * (strlen (_io->_username ) + strlen (name) + 8 )); // 8 extra chars for /f/, /csv & null termination
215
+ _get_topic = (char *) malloc (sizeof (char ) * (strlen (_io->_username ) + strlen (name) + 12 )); // 12 extra chars for /f/, /csv/get & null termination
228
216
_feed_url = (char *) malloc (sizeof (char ) * (strlen (_io->_username ) + strlen (name) + 16 )); // 16 extra for api path & null term
229
217
_create_url = (char *) malloc (sizeof (char ) * (strlen (_io->_username ) + 15 )); // 15 extra for api path & null term
230
218
@@ -250,9 +238,16 @@ void AdafruitIO_Feed::_init()
250
238
strcat (_create_url, _io->_username );
251
239
strcat (_create_url, " /feeds" );
252
240
241
+ // build /get topic string
242
+ strcpy (_get_topic, _io->_username );
243
+ strcat (_get_topic, " /f/" );
244
+ strcat (_get_topic, name);
245
+ strcat (_get_topic, " /csv/get" );
246
+
253
247
// setup subscription
254
248
_sub = new Adafruit_MQTT_Subscribe (_io->_mqtt , _topic);
255
249
_pub = new Adafruit_MQTT_Publish (_io->_mqtt , _topic);
250
+ _get_pub = new Adafruit_MQTT_Publish (_io->_mqtt , _get_topic);
256
251
_io->_mqtt ->subscribe (_sub);
257
252
258
253
_sub->setCallback (this , &AdafruitIO_MQTT::subCallback);
@@ -265,6 +260,7 @@ void AdafruitIO_Feed::_init()
265
260
_feed_url = 0 ;
266
261
_sub = 0 ;
267
262
_pub = 0 ;
263
+ _get_pub = 0 ;
268
264
data = 0 ;
269
265
270
266
}
0 commit comments