-
-
Save domadev812/a8f87fc275270d1ac14c19d4475dee42 to your computer and use it in GitHub Desktop.
Arduino To PubNub In Two Steps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SPI.h> | |
#include <Ethernet.h> | |
#include <Pubnub.h> | |
#include "string.h" | |
#include "iotconnector.h" | |
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; | |
char pubkey[] = "PUBLISH KEYS HERE";char subkey[] = "SUBSCRIBE KEYS HERE";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"); | |
PubNub.begin("demo", "demo"); | |
} | |
void do_something(String value){ | |
Serial.println("in the callback"); | |
Serial.println(value); | |
} | |
void setup() | |
{ | |
initialize(); | |
arduino.init( pubkey, subkey, uuid); | |
} | |
void loop() | |
{ | |
String returnmessage; | |
Ethernet.maintain(); | |
//Publish | |
arduino.send(channel,"\"Hey There\""); | |
//Subscribe | |
returnmessage = arduino.connect(channel); | |
//callback function of sorts, to work with the received message | |
do_something(returnmessage); | |
Serial.println(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bool iotbridge::send(const char *channel, const char *message){ | |
EthernetClient *client; | |
client = PubNub.publish(channel, message); | |
return client; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String iotbridge::connect(const char *channel){ | |
PubSubClient *pclient = PubNub.subscribe(channel); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment