Last active
September 28, 2017 02:54
-
-
Save j15e/2a91c09f8e4a0a12a187e32fee770615 to your computer and use it in GitHub Desktop.
group feeds issue
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
#define WIFI_SSID "" | |
#define WIFI_PASS "" | |
#define IO_USERNAME "" | |
#define IO_KEY "" | |
#define SET_PIN 14 | |
#define UNSET_PIN 12 | |
#include "SPI.h" | |
#include "AdafruitIO_WiFi.h" | |
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS); | |
AdafruitIO_Group *garden = io.group("garden"); | |
void setup() { | |
// Start the serial connection | |
Serial.begin(115200); | |
// wait for serial monitor to open | |
while(! Serial); | |
Serial.print("Connecting to Adafruit IO"); | |
// connect to io.adafruit.com | |
io.connect(); | |
// set up a message handler for the count feed. | |
// the handleMessage function (defined below) | |
// will be called whenever a message is | |
// received from adafruit io. | |
garden->onMessage("pump", handlePump); | |
// wait for a connection | |
while(io.status() < AIO_CONNECTED) { | |
Serial.print("."); | |
delay(500); | |
} | |
garden->set("pump", "hello world"); | |
// we are connected | |
Serial.println(); | |
Serial.println("WiFi connected"); | |
} | |
void loop() { | |
io.run(); | |
} | |
void handlePump(AdafruitIO_Data *data) { | |
Serial.print("received <- "); | |
Serial.println(data->value()); | |
if(data->toBool()) { | |
openRelay(); | |
} else { | |
closeRelay(); | |
} | |
Serial.println(""); | |
} | |
void openRelay() { | |
digitalWrite(SET_PIN, HIGH); | |
delay(10); | |
digitalWrite(SET_PIN, LOW); | |
} | |
void closeRelay() { | |
digitalWrite(UNSET_PIN, HIGH); | |
delay(10); | |
digitalWrite(UNSET_PIN, LOW); | |
} |
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
#define WIFI_SSID "" | |
#define WIFI_PASS "" | |
#define IO_USERNAME "" | |
#define IO_KEY "" | |
#define SET_PIN 14 | |
#define UNSET_PIN 12 | |
#include "SPI.h" | |
#include "AdafruitIO_WiFi.h" | |
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS); | |
// Single feed not grouped | |
AdafruitIO_Feed *pump = io.feed("pump"); | |
bool booted = false; | |
void setup() { | |
// Start the serial connection | |
Serial.begin(115200); | |
// wait for serial monitor to open | |
while(! Serial); | |
Serial.print("Connecting to Adafruit IO"); | |
// connect to io.adafruit.com | |
io.connect(); | |
// set up a message handler for the count feed. | |
// the handleMessage function (defined below) | |
// will be called whenever a message is | |
// received from adafruit io. | |
pump->onMessage(handlePump); | |
// wait for a connection | |
while(io.status() < AIO_CONNECTED) { | |
Serial.print("."); | |
delay(500); | |
} | |
// we are connected | |
Serial.println(); | |
Serial.println("WiFi connected"); | |
} | |
void loop() { | |
// At boot | |
if(!booted) { | |
closeRelay(); | |
booted = true; | |
} | |
io.run(); | |
} | |
void handlePump(AdafruitIO_Data *data) { | |
Serial.print("received <- "); | |
Serial.println(data->value()); | |
if(data->toBool()) { | |
openRelay(); | |
} else { | |
closeRelay(); | |
} | |
Serial.println(""); | |
} | |
void openRelay() { | |
digitalWrite(SET_PIN, HIGH); | |
delay(10); | |
digitalWrite(SET_PIN, LOW); | |
} | |
void closeRelay() { | |
digitalWrite(UNSET_PIN, HIGH); | |
delay(10); | |
digitalWrite(UNSET_PIN, LOW); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment