Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /************************ Adafruit IO Configuration *******************************/
- // visit io.adafruit.com if you need to create an account,
- // or if you need your Adafruit IO key.
- #define IO_USERNAME "yayanoktaviani"
- #define IO_KEY "8f00030d8dd84d70928134dfd2009113"
- /******************************* WIFI Configuration **************************************/
- #define WIFI_SSID "smarthome"
- #define WIFI_PASS "smarthomeproject"
- #include "AdafruitIO_WiFi.h"
- AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
- /************************ Main Program Starts Here *******************************/
- #include <ESP8266WiFi.h>
- #include <AdafruitIO.h>
- #include <Adafruit_MQTT.h>
- #include <ArduinoHttpClient.h>
- #define RELAY1 0
- // button state
- int current = 0;
- int last = 0;
- // set up the 'command' feed
- AdafruitIO_Feed *command = io.feed("lights");
- void setup() {
- pinMode(RELAY1, OUTPUT);
- // start the serial connection
- Serial.begin(115200);
- // connect to io.adafruit.com
- Serial.print("Connecting to Adafruit IO");
- io.connect();
- command->onMessage(handleMessage);
- // wait for a connection
- while(io.status() < AIO_CONNECTED) {
- Serial.print(".");
- delay(500);
- }
- // we are connected
- Serial.println();
- Serial.println(io.statusText());
- digitalWrite(RELAY1, LOW);
- }
- void loop() {
- io.run();
- }
- void handleMessage(AdafruitIO_Data *data) {
- int command = data->toInt();
- if (command == 1){ //light up the LED
- Serial.print("received <- ");
- Serial.println(command);
- digitalWrite(RELAY1, HIGH);
- } else {
- Serial.print("received <- ");
- Serial.println(command);
- digitalWrite(RELAY1, LOW);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement