Created
August 21, 2013 00:20
-
-
Save ToeJamson/6289007 to your computer and use it in GitHub Desktop.
Home Automation
This file contains hidden or 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
| 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