Skip to content

Commit 4bb7395

Browse files
committed
add /get MQTT publish method to trigger feed data resending
1 parent 80ac0bc commit 4bb7395

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/AdafruitIO_Feed.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,18 @@ AdafruitIO_Feed::~AdafruitIO_Feed()
3131
if(_pub)
3232
delete _pub;
3333

34+
if(_get_pub)
35+
delete _pub;
36+
3437
if(data)
3538
delete data;
3639

3740
if(_topic)
3841
free(_topic);
3942

43+
if (_get_topic)
44+
free(_get_topic);
45+
4046
if(_feed_url)
4147
free(_feed_url);
4248

@@ -103,6 +109,22 @@ bool AdafruitIO_Feed::save(double value, double lat, double lon, double ele, int
103109
return _pub->publish(data->toCSV());
104110
}
105111

112+
bool AdafruitIO_Feed::get()
113+
{
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+
_get_pub = new Adafruit_MQTT_Publish(_io->_mqtt, _topic);
123+
}
124+
125+
return _get_pub->publish('\0');
126+
}
127+
106128
bool AdafruitIO_Feed::exists()
107129
{
108130
_io->_http->beginRequest();

src/AdafruitIO_Feed.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ class AdafruitIO_Feed : public AdafruitIO_MQTT {
3737
bool save(float value, double lat=0, double lon=0, double ele=0, int precision=6);
3838
bool save(double value, double lat=0, double lon=0, double ele=0, int precision=6);
3939

40+
bool get();
41+
4042
bool exists();
4143
bool create();
4244

@@ -56,11 +58,13 @@ class AdafruitIO_Feed : public AdafruitIO_MQTT {
5658
void _init();
5759

5860
char *_topic;
61+
char *_get_topic;
5962
char *_create_url;
6063
char *_feed_url;
6164

6265
Adafruit_MQTT_Subscribe *_sub;
6366
Adafruit_MQTT_Publish *_pub;
67+
Adafruit_MQTT_Publish *_get_pub;
6468

6569
AdafruitIO *_io;
6670
AdafruitIO_Data *_data;

0 commit comments

Comments
 (0)