Skip to content

Commit 77a0d49

Browse files
committed
use new mqtt class for io callbacks
1 parent af1efcf commit 77a0d49

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

src/AdafruitIO_Feed.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,12 @@
1212
#include "AdafruitIO_Feed.h"
1313
#include "AdafruitIO.h"
1414

15-
AdafruitIO_Feed::AdafruitIO_Feed(AdafruitIO *io, const char *n)
15+
AdafruitIO_Feed::AdafruitIO_Feed(AdafruitIO *io, const char *n):AdafruitIO_MQTT()
1616
{
1717
_io = io;
1818
name = n;
1919
_sub = 0;
2020
_pub = 0;
21-
_dataCallback = 0;
2221

2322
_init();
2423
}
@@ -179,7 +178,7 @@ void AdafruitIO_Feed::_init()
179178
_pub = new Adafruit_MQTT_Publish(_io->_mqtt, _topic);
180179
_io->_mqtt->subscribe(_sub);
181180

182-
_sub->setCallback(this, &AdafruitIO_Feed::subCallback);
181+
_sub->setCallback(this, &AdafruitIO_MQTT::subCallback);
183182

184183
} else {
185184

src/AdafruitIO_Feed.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,17 @@
1616
#include "Adafruit_MQTT.h"
1717
#include "AdafruitIO_Definitions.h"
1818
#include "AdafruitIO_Data.h"
19+
#include "AdafruitIO_MQTT.h"
1920

2021
// forward declaration
2122
class AdafruitIO;
2223

23-
class AdafruitIO_Feed {
24+
class AdafruitIO_Feed : public AdafruitIO_MQTT {
2425

2526
public:
2627
AdafruitIO_Feed(AdafruitIO *io, const char *name);
2728
~AdafruitIO_Feed();
2829

29-
void onMessage(AdafruitIODataCallbackType cb);
30-
3130
bool save(char *value, double lat=0, double lon=0, double ele=0);
3231
bool save(bool value, double lat=0, double lon=0, double ele=0);
3332
bool save(String value, double lat=0, double lon=0, double ele=0);
@@ -43,12 +42,16 @@ class AdafruitIO_Feed {
4342

4443
void setLocation(double lat, double lon, double ele=0);
4544

45+
void onMessage(AdafruitIODataCallbackType cb);
4646
void subCallback(char *val, uint16_t len);
47+
4748
const char *name;
4849

4950
AdafruitIO_Data *data;
5051

5152
private:
53+
AdafruitIODataCallbackType _dataCallback;
54+
5255
void _init();
5356

5457
char *_topic;
@@ -60,7 +63,6 @@ class AdafruitIO_Feed {
6063

6164
AdafruitIO *_io;
6265
AdafruitIO_Data *_data;
63-
AdafruitIODataCallbackType _dataCallback;
6466

6567
};
6668

src/AdafruitIO_MQTT.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
#ifndef ADAFRUITIO_MQTT_H
13+
#define ADAFRUITIO_MQTT_H
14+
15+
#include "Arduino.h"
16+
17+
class AdafruitIO_MQTT {
18+
19+
public:
20+
AdafruitIO_MQTT() {}
21+
virtual void subCallback(char *val, uint16_t len) = 0;
22+
23+
};
24+
25+
#endif // ADAFRUITIO_MQTT_H

0 commit comments

Comments
 (0)