Skip to content

Instantly share code, notes, and snippets.

@ToeJamson
Created August 21, 2013 00:20
Show Gist options
  • Select an option

  • Save ToeJamson/6289007 to your computer and use it in GitHub Desktop.

Select an option

Save ToeJamson/6289007 to your computer and use it in GitHub Desktop.
Home Automation
void setup() {
Serial.begin(9600);
Ethernet.begin(mac);
PubNub.begin(pubkey, subkey);
}
void loop() {
/* Maintain DHCP lease. */
Ethernet.maintain();
/* Publish message. */
EthernetClient *pclient = PubNub.publish(pubchannel, "\"message\"");
if (pclient)
pclient->stop();
/* Wait for news. */
PubSubClient *sclient = PubNub.subscribe(subchannel);
if (!sclient) return; // error
char buffer[64]; size_t buflen = 0;
while (sclient->wait_for_data()) {
buffer[buflen++] = sclient->read();
}
buffer[buflen] = 0;
sclient->stop();
/* Print received message. You will want to look at it from
* your code instead. */
Serial.println(buffer);
delay(10000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment