-
Notifications
You must be signed in to change notification settings - Fork 0
/
WH_ST_Anything_Doors_Windows.ino
177 lines (161 loc) · 10.5 KB
/
WH_ST_Anything_Doors_Windows.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
//******************************************************************************************
// File: ST_Anything_Doors_Windows.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 Arduino + SmartThings Shield 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 SmartThings Shield.
//
// ST_Anything_Doors_Example implements the following:
// - 13 x Contact Sensor devices (used to monitor magnetic door/windows sensors)
// - 1 x Motion device (used to detect motion)
//
// During the development of this re-usable library, it became apparent that the
// Arduino UNO R3's very limited 2K of SRAM was very limiting in the number of
// devices that could be implemented simultaneously. A tremendous amount of effort
// has gone into reducing the SRAM usage, including siginificant improvements to
// the SmartThings Arduino library. The SmartThings library was also modified to
// include support for using Hardware Serial port(s) on the UNO, MEGA, and Leonardo.
// During testing, it was determined that the Hardware Serial ports provide much
// better performance and reliability versus the SoftwareSerial library. Also, the
// MEGA 2560's 8K of SRAM is well worth the few extra dollars to save your sanity
// versus always running out of SRAM on the UNO R3. The MEGA 2560 also has 4 Hardware
// serial ports (i.e. UARTS) which makes it very easy to use Hardware Serial instead
// of SoftwareSerial, while still being able to see debug data on the USB serial
// console port (pins 0 & 1).
//
// Note: We did not have a Leonardo for testing, but did fully test on UNO R3 and
// MEGA 2560 using both SoftwareSerial and Hardware Serial communications to the
// Thing Shield.
//
// Change History:
//
// Date Who What
// ---- --- ----
// 2015-01-03 Dan & Daniel Original Creation
// 2015-01-07 Dan Ogorchock Modified for Door Monitoring and Garage Door Control
// 2015-03-28 Dan Ogorchock Removed RCSwitch #include now that the libraries are split up
// 2015-03-31 Daniel O. Memory optimizations utilizing progmem
// 2015-10-31 Dan Ogorchock Revised for a specific user request
//
//******************************************************************************************
//******************************************************************************************
// SmartThings Library for Arduino Shield
//******************************************************************************************
#include <SoftwareSerial.h> //Arduino UNO/Leonardo uses SoftwareSerial for the SmartThings Library
#include <SmartThings.h> //Library to provide API to the SmartThings Shield
#include <avr/pgmspace.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 <InterruptSensor.h> //Generic Interrupt "Sensor" Class, waits for change of state on digital input
#include <Everything.h> //Master Brain of ST_Anything library that ties everything together and performs ST Shield communications
//#include <IS_Motion.h> //Implements an Interrupt Sensor (IS) to detect motion via a PIR sensor
#include <IS_Contact.h> //Implements an Interrupt Sensor (IS) to monitor the status of a digital input pin
//******************************************************************************************
//Define which Arduino Pins will be used for each device
// Notes: -Serial Communications Pins are defined in Constants.h (avoid pins 0,1,2,3
// for inputs and output devices below as they may be used for communications)
// -Always avoid Pin 6 as it is reserved by the SmartThings Shield
//
//******************************************************************************************
//"RESERVED" pins for SmartThings ThingShield - best to avoid
#define PIN_O_RESERVED 0 //reserved by ThingShield for Serial communications OR USB Serial Monitor
#define PIN_1_RESERVED 1 //reserved by ThingShield for Serial communications OR USB Serial Monitor
#define PIN_2_RESERVED 2 //reserved by ThingShield for Serial communications
#define PIN_3_RESERVED 3 //reserved by ThingShield for Serial communications
#define PIN_6_RESERVED 6 //reserved by ThingShield (possible future use?)
//Window Pins
//#define PIN_CONTACT_LIVINGROOM_WINDOW 4
#define PIN_CONTACT_BFSTNOOK_WINDOW 5
#define PIN_CONTACT_DININGROOM_WINDOW 7
#define PIN_CONTACT_MASTER_WINDOW1 8
#define PIN_CONTACT_MASTER_WINDOW2 9
#define PIN_CONTACT_MASTERBATH_WINDOW 10
//#define PIN_CONTACT_OFFICE_WINDOW2 11
//#define PIN_CONTACT_GUEST_WINDOW1 12
//#define PIN_CONTACT_GUEST_WINDOW2 13
//House Door Pins
//#define PIN_CONTACT_FRONT_DOOR A1
//#define PIN_CONTACT_KITCHEN_DOOR A2
//#define PIN_CONTACT_GARAGE_DOOR A3
//#define PIN_CONTACT_BEDROOM_DOOR A4
//motion pins
//#define PIN_MOTION A5
//******************************************************************************************
//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 DeviceType Groovy code
// - 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
// DeviceType Tile name.
//******************************************************************************************
// static st::IS_Motion sensor1(F("motion"), PIN_MOTION, HIGH, false);
// static st::IS_Contact sensor1(F("livingRoomWindow"), PIN_CONTACT_LIVINGROOM_WINDOW, LOW, true, 500);
static st::IS_Contact sensor2(F("bfstNookWindow"), PIN_CONTACT_BFSTNOOK_WINDOW, LOW, true, 500);
static st::IS_Contact sensor3(F("diningRoomWindow"), PIN_CONTACT_DININGROOM_WINDOW, LOW, true, 500);
static st::IS_Contact sensor4(F("masterWindow1"), PIN_CONTACT_MASTER_WINDOW1, LOW, true, 500);
static st::IS_Contact sensor5(F("masterWindow2"), PIN_CONTACT_MASTER_WINDOW2, LOW, true, 500);
static st::IS_Contact sensor6(F("masterBathWindow"), PIN_CONTACT_MASTERBATH_WINDOW, LOW, true, 500);
// static st::IS_Contact sensor8(F("officeWindow2"), PIN_CONTACT_OFFICE_WINDOW2, LOW, true, 500);
// static st::IS_Contact sensor9(F("guestWindow1"), PIN_CONTACT_GUEST_WINDOW1, LOW, true, 500);
// static st::IS_Contact sensor10(F("guestWindow2"), PIN_CONTACT_GUEST_WINDOW2, LOW, true, 500);
// static st::IS_Contact sensor11(F("frontDoor"), PIN_CONTACT_FRONT_DOOR, LOW, true, 500);
// static st::IS_Contact sensor12(F("kitchenDoor"), PIN_CONTACT_KITCHEN_DOOR, LOW, true, 500);
// static st::IS_Contact sensor13(F("garageDoor"), PIN_CONTACT_GARAGE_DOOR, LOW, true, 500);
// static st::IS_Contact sensor14(F("bedroomDoor"), PIN_CONTACT_BEDROOM_DOOR, LOW, true, 500);
//*****************************************************************************
// 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::Device::debug=true;
st::InterruptSensor::debug=true;
//*****************************************************************************
//Initialize the "Everything" Class
//*****************************************************************************
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);
st::Everything::addSensor(&sensor6);
// st::Everything::addSensor(&sensor7);
// st::Everything::addSensor(&sensor8);
// st::Everything::addSensor(&sensor9);
// st::Everything::addSensor(&sensor10);
// st::Everything::addSensor(&sensor11);
// st::Everything::addSensor(&sensor12);
// st::Everything::addSensor(&sensor13);
// st::Everything::addSensor(&sensor14);
//*****************************************************************************
//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();
}