-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathiotconnector.h
51 lines (38 loc) · 1.02 KB
/
iotconnector.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "PubNub.h"
#include <SPI.h>
#include <Ethernet.h>
class iotbridge{
public:
const char *publish_key;
const char *subscribe_key;
const char *uuid;
const char *channel;
const char *message;
bool init(const char *publish_key, const char *subscribe_key, const char *uuid);
bool send(const char *channel, const char *message);
String connect(const char *channel);
};
bool iotbridge::init(const char *publish_key, const char *subscribe_key, const char *uuid){
PubNub.begin(publish_key,subscribe_key);
PubNub.set_uuid(uuid);
}
bool iotbridge::send(const char *channel, const char *message){
EthernetClient *client;
client = PubNub.publish(channel,message);
return client;
}
String iotbridge::connect(const char *channel){
String message = "";
int i = 0;
PubSubClient *pclient = PubNub.subscribe(channel);
if (!pclient) {
return;
}
while (pclient->wait_for_data()) {
char c = pclient->read();
message += c;
}
pclient->stop();
Serial.println();
return message;
}