/arduino.ino
| #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; | |
| } | |
This comment has been minimized.
This comment has been minimized.
hafizmaster93
commented
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: This report would have more information with can anyone give me some suggestion to fix this issue? thanks |
This comment has been minimized.
This comment has been minimized.
andriyudatama
commented
Nov 28, 2015
|
I have the same problem with @hafizmaster93, can somebody help us? |
This comment has been minimized.
This comment has been minimized.
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. |
This comment has been minimized.
This comment has been minimized.
mskoczen
commented
Apr 3, 2018
•
|
You are attempting to return an integer in a function with a return type of String. NOTE: I have not looked at the rest of the code to verify that this will not cause other problems. |
This comment has been minimized.
Yop1403 commentedOct 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