Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added functionallity to control blinds that require a seperate up and down pin #12

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include <IS_DoorControl.h> //Implements an Interrupt Sensor (IS) and Executor to monitor the status of a digital input pin and control a digital output pin
#include <IS_Button.h> //Implements an Interrupt Sensor (IS) to monitor the status of a digital input pin for button presses
#include <EX_Switch.h> //Implements an Executor (EX) via a digital output to a relay
#include <EX_Blind.h> //Implements Executor (EX)as an Window Shade capability with seperate up and down pins
#include <EX_Alarm.h> //Implements Executor (EX)as an Alarm capability with Siren and Strobe via digital outputs to relays
#include <S_TimedRelay.h> //Implements a Sensor to control a digital output pin with timing/cycle repeat capabilities

Expand Down Expand Up @@ -145,6 +146,7 @@ void setup()

//Executors
static st::EX_Alarm executor1(F("alarm1"), PIN_ALARM_1, LOW, false);
//Example for using blinds: static st::EX_Blind executor1(F("blind1"), PIN_SWITCH_1, PIN_SWITCH_2, LOW, false);

//*****************************************************************************
// Configure debug print output from each main class
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
//******************************************************************************************
// File: ST_Anything_AlarmPanel_ESP8266WiFi.ino
// Authors: Dan G Ogorchock & Daniel J Ogorchock (Father and Son)
//
// Summary: This Arduino Sketch, along with the ST_Anything library and the revised SmartThings
// library, demonstrates the ability of one NodeMCU ESP8266 to
// implement a multi input/output custom device for integration into SmartThings.
// The ST_Anything library takes care of all of the work to schedule device updates
// as well as all communications with the NodeMCU ESP8266's WiFi.
//
// ST_Anything_AlarmPanel implements the following ST Capabilities as a demo of replacing an alarm panel with a single NodeMCU ESP8266
// - 7 x Contact Sensor devices (used to monitor magnetic door sensors)
// - 1 x Motion device (using simple digital input)
// - 1 x Smoke Detector devices (using simple digital input)
// - 1 x Alarm (Siren only) device (using a simple digital output attached to a relay)
//
// Change History:
//
// Date Who What
// ---- --- ----
// 2017-04-26 Dan Ogorchock Original Creation

//******************************************************************************************
//******************************************************************************************
// SmartThings Library for ESP8266WiFi
//******************************************************************************************
#include <SmartThingsESP8266WiFi.h>

//******************************************************************************************
// ST_Anything Library
//******************************************************************************************
#include <Constants.h> //Constants.h is designed to be modified by the end user to adjust behavior of the ST_Anything library
#include <Device.h> //Generic Device Class, inherited by Sensor and Executor classes
#include <Sensor.h> //Generic Sensor Class, typically provides data to ST Cloud (e.g. Temperature, Motion, etc...)
#include <Executor.h> //Generic Executor Class, typically receives data from ST Cloud (e.g. Switch)
#include <InterruptSensor.h> //Generic Interrupt "Sensor" Class, waits for change of state on digital input
#include <PollingSensor.h> //Generic Polling "Sensor" Class, polls Arduino pins periodically
#include <Everything.h> //Master Brain of ST_Anything library that ties everything together and performs ST Shield communications

#include <PS_Illuminance.h> //Implements a Polling Sensor (PS) to measure light levels via a photo resistor on an analog input pin
#include <PS_Voltage.h> //Implements a Polling Sensor (PS) to measure voltage on an analog input pin
#include <PS_TemperatureHumidity.h> //Implements a Polling Sensor (PS) to measure Temperature and Humidity via DHT library
#include <PS_Water.h> //Implements a Polling Sensor (PS) to measure presence of water (i.e. leak detector) on an analog input pin
#include <IS_Motion.h> //Implements an Interrupt Sensor (IS) to detect motion via a PIR sensor on a digital input pin
#include <IS_Contact.h> //Implements an Interrupt Sensor (IS) to monitor the status of a digital input pin
#include <IS_Smoke.h> //Implements an Interrupt Sensor (IS) to monitor the status of a digital input pin
#include <IS_CarbonMonoxide.h> //Implements an Interrupt Sensor (IS) to monitor the status of a digital input pin
#include <IS_DoorControl.h> //Implements an Interrupt Sensor (IS) and Executor to monitor the status of a digital input pin and control a digital output pin
#include <IS_Button.h> //Implements an Interrupt Sensor (IS) to monitor the status of a digital input pin for button presses
#include <EX_Switch.h> //Implements an Executor (EX) via a digital output to a relay
#include <EX_Alarm.h> //Implements Executor (EX)as an Alarm capability with Siren and Strobe via digital outputs to relays
#include <EX_Blind.h> //Implements Executor (EX)as an Blind capability
#include <S_TimedRelay.h> //Implements a Sensor to control a digital output pin with timing/cycle repeat capabilities

//*************************************************************************************************
//NodeMCU v1.0 ESP8266-12e Pin Definitions (makes it much easier as these match the board markings)
//*************************************************************************************************
#define LED_BUILTIN 16
#define BUILTIN_LED 16

#define D0 16 //no internal pullup resistor
#define D1 5
#define D2 4
#define D3 0 //must not be pulled low during power on/reset, toggles value during boot
#define D4 2 //must not be pulled low during power on/reset, toggles value during boot
#define D5 14
#define D6 12
#define D7 13
#define D8 15 //must not be pulled high during power on/reset

//******************************************************************************************
//Define which Arduino Pins will be used for each device
//******************************************************************************************


#define PIN_UP D6 //SmartThings Capabilty "Alarm"
#define PIN_DOWN D7 //
#define PIN_MY D5 //My Button
//#define PIN_CONTACT_1 D1 //SmartThings Capabilty "Contact Sensor"
//#define PIN_CONTACT_2 D2 //SmartThings Capabilty "Contact Sensor"
//#define PIN_CONTACT_3 D5 //SmartThings Capabilty "Contact Sensor"
//#define PIN_CONTACT_4 D6 //SmartThings Capabilty "Contact Sensor"
//#define PIN_CONTACT_5 D7 //SmartThings Capabilty "Contact Sensor"


//******************************************************************************************
//ESP8266 WiFi Information
//******************************************************************************************
String str_ssid = ""; // <---You must edit this line!
String str_password = ""; // <---You must edit this line!
IPAddress ip(192, 168, 3, 234); //Device IP Address // <---You must edit this line!
IPAddress gateway(192, 168, 3, 1); //Router gateway // <---You must edit this line!
IPAddress subnet(255, 255, 255, 0); //LAN subnet mask // <---You must edit this line!
IPAddress dnsserver(192, 168, 3, 1); //DNS server // <---You must edit this line!
const unsigned int serverPort = 8090; // port to run the http server on

// Smartthings Hub Information
IPAddress hubIp(192, 168, 3, 174); // smartthings hub ip // <---You must edit this line!
const unsigned int hubPort = 39500; // smartthings hub port

//******************************************************************************************
//st::Everything::callOnMsgSend() optional callback routine. This is a sniffer to monitor
// data being sent to ST. This allows a user to act on data changes locally within the
// Arduino sktech.
//******************************************************************************************
void callback(const String &msg)
{
// Serial.print(F("ST_Anything Callback: Sniffed data = "));
// Serial.println(msg);

//TODO: Add local logic here to take action when a device's value/state is changed

//Masquerade as the ThingShield to send data to the Arduino, as if from the ST Cloud (uncomment and edit following line)
//st::receiveSmartString("Put your command here!"); //use same strings that the Device Handler would send
}

//******************************************************************************************
//Arduino Setup() routine
//******************************************************************************************
void setup()
{
//******************************************************************************************
//Declare each Device that is attached to the Arduino
// Notes: - For each device, there is typically a corresponding "tile" defined in your
// SmartThings Device Hanlder Groovy code, except when using new COMPOSITE Device Handler
// - For details on each device's constructor arguments below, please refer to the
// corresponding header (.h) and program (.cpp) files.
// - The name assigned to each device (1st argument below) must match the Groovy
// Device Handler names. (Note: "temphumid" below is the exception to this rule
// as the DHT sensors produce both "temperature" and "humidity". Data from that
// particular sensor is sent to the ST Hub in two separate updates, one for
// "temperature" and one for "humidity")
// - The new Composite Device Handler is comprised of a Parent DH and various Child
// DH's. The names used below MUST not be changed for the Automatic Creation of
// child devices to work properly. Simply increment the number by +1 for each duplicate
// device (e.g. contact1, contact2, contact3, etc...) You can rename the Child Devices
// to match your specific use case in the ST Phone Application.
//******************************************************************************************
//Polling Sensors

//Interrupt Sensors
// static st::IS_Contact sensor1(F("contact1"), PIN_CONTACT_1, LOW, true, 500);
// static st::IS_Contact sensor2(F("contact2"), PIN_CONTACT_2, LOW, true, 500);
//static st::IS_Contact sensor3(F("contact3"), PIN_CONTACT_3, LOW, true, 500);
// static st::IS_Contact sensor4(F("contact4"), PIN_CONTACT_4, LOW, true, 500);
// static st::IS_Contact sensor5(F("contact5"), PIN_CONTACT_5, LOW, true, 500);


//Executors
static st::EX_Blind executor1(F("blind1"), PIN_UP, PIN_DOWN, LOW, false);

//*****************************************************************************
// Configure debug print output from each main class
// -Note: Set these to "false" if using Hardware Serial on pins 0 & 1
// to prevent communication conflicts with the ST Shield communications
//*****************************************************************************
st::Everything::debug=true;
st::Executor::debug=true;
st::Device::debug=true;
st::PollingSensor::debug=true;
st::InterruptSensor::debug=true;

//*****************************************************************************
//Initialize the "Everything" Class
//*****************************************************************************

//Initialize the optional local callback routine (safe to comment out if not desired)
st::Everything::callOnMsgSend = callback;

//Create the SmartThings ESP8266WiFi Communications Object
//STATIC IP Assignment - Recommended
st::Everything::SmartThing = new st::SmartThingsESP8266WiFi(str_ssid, str_password, ip, gateway, subnet, dnsserver, serverPort, hubIp, hubPort, st::receiveSmartString);

//DHCP IP Assigment - Must set your router's DHCP server to provice a static IP address for this device's MAC address
//st::Everything::SmartThing = new st::SmartThingsESP8266WiFi(str_ssid, str_password, serverPort, hubIp, hubPort, st::receiveSmartString);

//Run the Everything class' init() routine which establishes WiFi communications with SmartThings Hub
st::Everything::init();

//*****************************************************************************
//Add each sensor to the "Everything" Class
//*****************************************************************************
//st::Everything::addSensor(&sensor1);
//st::Everything::addSensor(&sensor2);
//st::Everything::addSensor(&sensor3);
//st::Everything::addSensor(&sensor4);
//st::Everything::addSensor(&sensor5);

//*****************************************************************************
//Add each executor to the "Everything" Class
//*****************************************************************************
st::Everything::addExecutor(&executor1);

//*****************************************************************************
//Initialize each of the devices which were added to the Everything Class
//*****************************************************************************
st::Everything::initDevices();

}

//******************************************************************************************
//Arduino Loop() routine
//******************************************************************************************
void loop()
{
//*****************************************************************************
//Execute the Everything run method which takes care of "Everything"
//*****************************************************************************
st::Everything::run();
}
120 changes: 120 additions & 0 deletions Arduino/libraries/ST_Anything/EX_Blind.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
//******************************************************************************************
// File: EX_Blind.cpp
// Authors: Dan G Ogorchock & Daniel J Ogorchock (Father and Son)
//
// Summary: EX_Blind is a class which implements the SmartThings "Switch" device capability.
// It inherits from the st::Executor class.
//
// Create an instance of this class in your sketch's global variable section
// For Example: st::EX_Blind executor1("switch", PIN_SWITCH, LOW, true);
//
// st::EX_Blind() constructor requires the following arguments
// - String &name - REQUIRED - the name of the object - must match the Groovy ST_Anything DeviceType tile name
// - byte pin - REQUIRED - the Arduino Pin to be used as a digital output
// - bool startingState - OPTIONAL - the value desired for the initial state of the switch. LOW = "off", HIGH = "on"
// - bool invertLogic - OPTIONAL - determines whether the Arduino Digital Output should use inverted logic
//
// Change History:
//
// Date Who What
// ---- --- ----
// 2015-01-03 Dan & Daniel Original Creation
//
//
//******************************************************************************************

#include "EX_Blind.h"

#include "Constants.h"
#include "Everything.h"

namespace st
{
//private
void EX_Blind::writeStateToPin()
{
if (m_bCurrentState == HIGH) {
if (st::Executor::debug) {Serial.println(F("EX_Blind::Going Up"));}
digitalWrite(m_nPin, m_bInvertLogic ? HIGH : LOW);
delay(500);
digitalWrite(m_nPin, m_bInvertLogic ? LOW : HIGH);
}
else
{
if (st::Executor::debug) {Serial.println(F("EX_Blind::Going Down"));}
digitalWrite(m_dPin, m_bInvertLogic ? HIGH : LOW);
delay(500);
digitalWrite(m_dPin, m_bInvertLogic ? LOW : HIGH);
}
}



//public
//constructor
EX_Blind::EX_Blind(const __FlashStringHelper *name, byte upin, byte dpin, bool startingState, bool invertLogic) :
Executor(name),
m_bCurrentState(startingState),
m_bInvertLogic(invertLogic)
{
setPin(upin, dpin);
}

//destructor
EX_Blind::~EX_Blind()
{

}

void EX_Blind::init()
{
Everything::sendSmartString(getName() + " " + (m_bCurrentState == HIGH ? F("open") : F("closed")));

}

void EX_Blind::beSmart(const String &str)
{
String s=str.substring(str.indexOf(' ')+1);
if (st::Executor::debug) {
Serial.print(F("EX_Blind::beSmart s = "));
Serial.println(s);
}
if(s==F("open"))
{
m_bCurrentState=HIGH;
}
else if(s==F("close"))
{
m_bCurrentState=LOW;
}
else if(s==F("stop"))
{
byte stop_pin = 14;
pinMode(stop_pin, OUTPUT);
if (st::Executor::debug) {Serial.println(F("EX_Blind::My"));}
digitalWrite(stop_pin, m_bInvertLogic ? HIGH : LOW);
delay(500);
digitalWrite(stop_pin, m_bInvertLogic ? LOW : HIGH);
return;
}

writeStateToPin();

Everything::sendSmartString(getName() + " " + (m_bCurrentState == HIGH?F("open"):F("closed")));
}

void EX_Blind::refresh()
{
Everything::sendSmartString(getName() + " " + (m_bCurrentState == HIGH?F("open"):F("closed")));
}

void EX_Blind::setPin(byte upin, byte dpin)
{
m_nPin=upin;
pinMode(m_nPin, OUTPUT);
digitalWrite(m_nPin, m_bInvertLogic ? LOW : HIGH);
m_dPin=dpin;
pinMode(m_dPin, OUTPUT);
digitalWrite(m_dPin, m_bInvertLogic ? LOW : HIGH);
}
}
Loading