Close

Code

A project log for Ventil-IoT-ion

Fighting moisture with the IoT

peroPero 11/21/2017 at 22:450 Comments

Complete code so far:

// Adafruit IO Digital Output Example
// Tutorial Link: https://learn.adafruit.com/adafruit-io-basics-digital-output
//
// Adafruit invests time and resources providing this open source code.
// Please support Adafruit and open source hardware by purchasing
// products from Adafruit!
//
// Written by Todd Treece for Adafruit Industries
// Copyright (c) 2016 Adafruit Industries
// Licensed under the MIT license.
//
// All text above must be included in any redistribution.

/************************** Configuration ***********************************/

// edit the config.h tab and enter your Adafruit IO credentials
// and any additional configuration needed for WiFi, cellular,
// or ethernet clients.
#include "config.h"

/************************ Example Starts Here *******************************/

// digital pin 5
#define LED_PIN 0
#define ventilator 5

// set up the 'digital' feed
AdafruitIO_Feed *digital = io.feed("xxxxx");
AdafruitIO_Feed *state = io.feed("yyyyy");

void setup() {

  // set led pin as a digital output
  pinMode(LED_PIN, OUTPUT);
  pinMode(ventilator, OUTPUT);

  // connect to io.adafruit.com
  io.connect();

  // set up a message handler for the 'digital' feed.
  // the handleMessage function (defined below)
  // will be called whenever a message is
  // received from adafruit io.
  digital->onMessage(handleMessage);
  // wait for a connection
  while (io.status() < AIO_CONNECTED) {
   digitalWrite(LED_PIN, LOW);  // toggle LED during connecting phase
   delay(500);
   digitalWrite(LED_PIN, HIGH);
   delay(500);   
  }

  // we are connected
   digitalWrite(LED_PIN, LOW);
   delay(3000);
   digitalWrite(LED_PIN, HIGH);
   state->save("Active");
}

void loop() {

  // io.run(); is required for all sketches.
  // it should always be present at the top of your loop
  // function. it keeps the client connected to
  // io.adafruit.com, and processes any incoming data.
  io.run();

}

// this function is called whenever an 'digital' feed message
// is received from Adafruit IO. it was attached to
// the 'digital' feed in the setup() function above.
void handleMessage(AdafruitIO_Data *data) {

  // write the current state to the led
  digitalWrite(ventilator, data->toPinLevel());

}

Discussions