Skip to content

Instantly share code, notes, and snippets.

@banasrini
Last active April 3, 2018 20:29
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
#include <SPI.h>
#include <Ethernet.h>
#include "string.h"
#include "iotconnector.h"
// Some Ethernet shields have a MAC address printed on a sticker on the shield;
// fill in that address here, or choose your own at random:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
char pubkey[] = "demo";
char subkey[] = "demo";
char channel[] = "iotchannel";
char uuid[] = "Arduino";
iotbridge arduino;
void initialize(){
Serial.begin(9600);
Serial.println("Serial set up");
while (!Ethernet.begin(mac)) {
Serial.println("Ethernet setup error");
delay(1000);
}
Serial.println("Ethernet set up");
}
void do_something(String value){
Serial.println("in the callback");
Serial.println(value);
}
void setup()
{
initialize();
arduino.init( pubkey, subkey, uuid);
Serial.println("PubNub set up");
}
void loop()
{
String returnmessage;
Ethernet.maintain();
//Publish
Serial.println("publishing a message");
arduino.send(channel,"\"Hey There\"");
//Subscribe
Serial.println("waiting for a message");
returnmessage = arduino.connect(channel);
// callback function of sorts, to work with the received message
do_something(returnmessage);
Serial.println();
}
#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 0;
}
while (pclient->wait_for_data()) {
char c = pclient->read();
message += c;
}
pclient->stop();
Serial.println();
return message;
}
@mskoczen
Copy link

mskoczen commented Apr 3, 2018

You are attempting to return an integer in a function with a return type of String.
It should compile if you change line 39 of iotconnector.h to return "";

NOTE: I have not looked at the rest of the code to verify that this will not cause other problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment