Create a gist now

Instantly share code, notes, and snippets.

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;
}
@Yop1403

This comment has been minimized.

Show comment Hide comment
@Yop1403

Yop1403 Oct 23, 2015

It should be mentioned that the 1st line in "iotconnector.h" wants to include "pubnub.h".
It can be found here: https://github.com/pubnub/arduino

Yop1403 commented Oct 23, 2015

It should be mentioned that the 1st line in "iotconnector.h" wants to include "pubnub.h".
It can be found here: https://github.com/pubnub/arduino

@hafizmaster93

This comment has been minimized.

Show comment Hide comment
@hafizmaster93

hafizmaster93 Oct 25, 2015

I try to compile my code on Arduino IDE by using this library, however I got this error:-

Arduino: 1.6.5 (Windows 8.1), Board: "Arduino Nano, ATmega328"

In file included from testiot.ino:4:0:
In file included from testiot.ino:4:0:
C:\Users\Asus\Documents\Arduino\libraries\iotconnector/iotconnector.h: In member function 'String iotbridge::connect(const char_)':
C:\Users\Asus\Documents\Arduino\libraries\iotconnector/iotconnector.h: In member function 'String iotbridge::connect(const char_)':
C:\Users\Asus\Documents\Arduino\libraries\iotconnector/iotconnector.h:39:10: error: converting to 'String' from initializer list would use explicit constructor 'String::String(int, unsigned char)'
C:\Users\Asus\Documents\Arduino\libraries\iotconnector/iotconnector.h:39:10: error: converting to 'String' from initializer list would use explicit constructor 'String::String(int, unsigned char)'
return 0;
return 0;
^
^
Error compiling.
Error compiling.

This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.

can anyone give me some suggestion to fix this issue? thanks

I try to compile my code on Arduino IDE by using this library, however I got this error:-

Arduino: 1.6.5 (Windows 8.1), Board: "Arduino Nano, ATmega328"

In file included from testiot.ino:4:0:
In file included from testiot.ino:4:0:
C:\Users\Asus\Documents\Arduino\libraries\iotconnector/iotconnector.h: In member function 'String iotbridge::connect(const char_)':
C:\Users\Asus\Documents\Arduino\libraries\iotconnector/iotconnector.h: In member function 'String iotbridge::connect(const char_)':
C:\Users\Asus\Documents\Arduino\libraries\iotconnector/iotconnector.h:39:10: error: converting to 'String' from initializer list would use explicit constructor 'String::String(int, unsigned char)'
C:\Users\Asus\Documents\Arduino\libraries\iotconnector/iotconnector.h:39:10: error: converting to 'String' from initializer list would use explicit constructor 'String::String(int, unsigned char)'
return 0;
return 0;
^
^
Error compiling.
Error compiling.

This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.

can anyone give me some suggestion to fix this issue? thanks

@andriyudatama

This comment has been minimized.

Show comment Hide comment
@andriyudatama

andriyudatama Nov 28, 2015

I have the same problem with @hafizmaster93, can somebody help us?

I have the same problem with @hafizmaster93, can somebody help us?

@millesm

This comment has been minimized.

Show comment Hide comment
@millesm

millesm Aug 29, 2016

same problem....

In file included from C:\Arduino\pub_nub_test\sketch_aug29a\sketch_aug29a.ino:4:0:

C:\Arduino\libraries\PubNub/iotconnector.h: In member function 'String iotbridge::connect(const char*)':

C:\Arduino\libraries\PubNub/iotconnector.h:39:10: error: converting to 'String' from initializer list would use explicit constructor 'String::String(int, unsigned char)'

return 0;

      ^

exit status 1

Error compiling.

no idea what it actually means but cannot compile code.

millesm commented Aug 29, 2016

same problem....

In file included from C:\Arduino\pub_nub_test\sketch_aug29a\sketch_aug29a.ino:4:0:

C:\Arduino\libraries\PubNub/iotconnector.h: In member function 'String iotbridge::connect(const char*)':

C:\Arduino\libraries\PubNub/iotconnector.h:39:10: error: converting to 'String' from initializer list would use explicit constructor 'String::String(int, unsigned char)'

return 0;

      ^

exit status 1

Error compiling.

no idea what it actually means but cannot compile code.

@mskoczen

This comment has been minimized.

Show comment Hide comment
@mskoczen

mskoczen 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.

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