Skip to content

Commit

Permalink
Merge pull request #8 from d8adrvn/reconfigure-hardware
Browse files Browse the repository at this point in the history
Reconfigure hardware
  • Loading branch information
d8adrvn committed May 28, 2015
2 parents ce78430 + 1826805 commit 09fc659
Show file tree
Hide file tree
Showing 22 changed files with 6,189 additions and 658 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

/**
* AD2SmartThings v2.0
* AD2SmartThings v3.0.0
* Couple your Ademco/Honeywell Alarm to your SmartThings Graph using an AD2PI, an Arduino and a ThingShield
* The Arduino passes all your alarm messages to your SmartThings Graph where they can be processed by the Device Type
* Use the Device Type to control your alarm or use SmartApps to integrate with other events in your home graph
Expand All @@ -11,8 +11,9 @@
* Timer library was created by Simon Monk as modified by JChristensen https://github.com/JChristensen/Timer. Note: if you
* download the library from the source, you must rename the zip file to "Timer" before importing into the Arduino IDE.
*
* Arduino Mega Library for SmartThings SmartShield can be found at:
* https://github.com/vassilisv/DSCAlarmSmartThings/tree/master/Arduino/libraries/SmartThingsMega
* An enhanced SmartThings Library was created by Dan G Ogorchock & Daniel J Ogorchock and their version is required for this implementation.
* Their enhanced library can found at:
* https://github.com/DanielOgorchock/ST_Anything/tree/master/Arduino/libraries/SmartThings
*
* SoftwareSerial library was default library provided with Arduino IDE
*
Expand All @@ -30,23 +31,28 @@
* Pin Configuration for Arduino Mega to ThingSheild
* Use standard jumper wires to connect:
* Jumper Mega ThingShield
* RX 17 0
* TX 16 1
* TX 14 2
* RX 15 3
*
*
*
* Credit: thanks to github contributor vassilisv for the intial idea and to AlarmDecoder.com for suggesting to use
* serial out feature of the AD2Pi to connect to the Arduino card. This project also benefitted imenseley from code
* shared by SmartThings contributor @craig
*
* Thanks to Dan G Ogorchock & Daniel J Ogorchock for the updated SmartThings library. This library is required for the ThingShield
* to use the hardware serial port on the Mega and for general performance enhancements.
*/

#include <SmartThingsMega.h> //special library for Arduino Mega card
#include <SoftwareSerial.h>
#include <SmartThings.h> //be sure you are using the library from ST_ANYTHING which has support for hardware serial on the Arduino Mega
#include <Timer.h>
#define PIN_LED 13


#define BUFFER_SIZE 300 // max message length from ADT

SmartThingsCallout_t messageCallout; // call out function forward decalaration
SmartThingsMega smartthing(&Serial2, messageCallout); // constructor

SmartThings smartthing(HW_SERIAL3, messageCallout); //constructor for hardware serial port with ST_Anything Library

// set global variables
char buffer[BUFFER_SIZE]; //stores characters in AD2Pi to build up a message
Expand Down Expand Up @@ -198,3 +204,4 @@ void sendUpdate()
previousStr="";
}


1 change: 1 addition & 0 deletions Arduino/libraries/SmartThings/.svn/entries
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
12
1 change: 1 addition & 0 deletions Arduino/libraries/SmartThings/.svn/format
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
12

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
//*****************************************************************************
/// @file
/// @brief
/// Arduino SmartThings Shield LED Example with Network Status
/// @note
/// ______________
/// | |
/// | SW[] |
/// |[]RST |
/// | AREF |--
/// | GND |--
/// | 13 |--X LED
/// | 12 |--
/// | 11 |--
/// --| 3.3V 10 |--
/// --| 5V 9 |--
/// --| GND 8 |--
/// --| GND |
/// --| Vin 7 |--
/// | 6 |--
/// --| A0 5 |--
/// --| A1 ( ) 4 |--
/// --| A2 3 |--X THING_RX
/// --| A3 ____ 2 |--X THING_TX
/// --| A4 | | 1 |--
/// --| A5 | | 0 |--
/// |____| |____|
/// |____|
///
//*****************************************************************************
#include <SoftwareSerial.h> //TODO need to set due to some weird wire language linker, should we absorb this whole library into smartthings
#include <SmartThings.h>

//*****************************************************************************
// Pin Definitions | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
// V V V V V V V V V V V V V V V V V V V V V V V V V V V V V
//*****************************************************************************
#define PIN_LED 13
#define PIN_THING_RX 3
#define PIN_THING_TX 2

//*****************************************************************************
// Global Variables | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
// V V V V V V V V V V V V V V V V V V V V V V V V V V V V V
//*****************************************************************************
SmartThingsCallout_t messageCallout; // call out function forward decalaration
SmartThings smartthing(PIN_THING_RX, PIN_THING_TX, messageCallout); // constructor

bool isDebugEnabled; // enable or disable debug in this example
int stateLED; // state to track last set value of LED
int stateNetwork; // state of the network

//*****************************************************************************
// Local Functions | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
// V V V V V V V V V V V V V V V V V V V V V V V V V V V V V V
//*****************************************************************************
void on()
{
stateLED = 1; // save state as 1 (on)
digitalWrite(PIN_LED, HIGH); // turn LED on
smartthing.shieldSetLED(0, 0, 2);
smartthing.send("on"); // send message to cloud
}

//*****************************************************************************
void off()
{
stateLED = 0; // set state to 0 (off)
digitalWrite(PIN_LED, LOW); // turn LED off
smartthing.shieldSetLED(0, 0, 0);
smartthing.send("off"); // send message to cloud
}

//*****************************************************************************
void setNetworkStateLED()
{
SmartThingsNetworkState_t tempState = smartthing.shieldGetLastNetworkState();
if (tempState != stateNetwork)
{
switch (tempState)
{
case STATE_NO_NETWORK:
if (isDebugEnabled) Serial.println("NO_NETWORK");
smartthing.shieldSetLED(2, 0, 0); // red
break;
case STATE_JOINING:
if (isDebugEnabled) Serial.println("JOINING");
smartthing.shieldSetLED(2, 0, 0); // red
break;
case STATE_JOINED:
if (isDebugEnabled) Serial.println("JOINED");
smartthing.shieldSetLED(0, 0, 0); // off
break;
case STATE_JOINED_NOPARENT:
if (isDebugEnabled) Serial.println("JOINED_NOPARENT");
smartthing.shieldSetLED(2, 0, 2); // purple
break;
case STATE_LEAVING:
if (isDebugEnabled) Serial.println("LEAVING");
smartthing.shieldSetLED(2, 0, 0); // red
break;
default:
case STATE_UNKNOWN:
if (isDebugEnabled) Serial.println("UNKNOWN");
smartthing.shieldSetLED(0, 2, 0); // green
break;
}
stateNetwork = tempState;
}
}

//*****************************************************************************
// API Functions | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
// V V V V V V V V V V V V V V V V V V V V V V V V V V V V V V
//*****************************************************************************
void setup()
{
// setup default state of global variables
isDebugEnabled = true;
stateLED = 0; // matches state of hardware pin set below
stateNetwork = STATE_JOINED; // set to joined to keep state off if off

// setup hardware pins
pinMode(PIN_LED, OUTPUT); // define PIN_LED as an output
digitalWrite(PIN_LED, LOW); // set value to LOW (off) to match stateLED=0

if (isDebugEnabled)
{ // setup debug serial port
Serial.begin(9600); // setup serial with a baud rate of 9600
Serial.println("setup.."); // print out 'setup..' on start
}
}

//*****************************************************************************
void loop()
{
// run smartthing logic
smartthing.run();
setNetworkStateLED();
}

//*****************************************************************************
void messageCallout(String message)
{
// if debug is enabled print out the received message
if (isDebugEnabled)
{
Serial.print("Received message: '");
Serial.print(message);
Serial.println("' ");
}

// if message contents equals to 'on' then call on() function
// else if message contents equals to 'off' then call off() function
if (message.equals("on"))
{
on();
}
else if (message.equals("off"))
{
off();
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
--------------------------------------------------------------------------------------------------
| Setup Instructions |
--------------------------------------------------------------------------------------------------
1) Copy the entire SmartThings directory into the 'libraries' directory in your sketchbook location.
Windows: 'My Documents\Arduino\libraries\SmartThings'
OSX: '~/Documents/Arduino/libraries/SmartThings'

--------------------------------------------------------------------------------------------------
| Notes |
--------------------------------------------------------------------------------------------------


--------------------------------------------------------------------------------------------------
| ChangeLog: |
--------------------------------------------------------------------------------------------------
01/11/2015 (v0.0.6) do + Added Hardware Serial Constructor
+ Added support for Leonardo and MEGA
~ Performance improvements
~ Significant SRAM memory optimizations (minimum ~175 bytes, up to 430 bytes)
02/11/2012 (v0.0.5) db + shieldGetLastNetworkStatus to public Class
+ example/stLEDwithNetworkStatus
~ renamed SmartThingsLED to stLED
+ ascii diagram for each example documenting pins & usage
02/08/2012 (v0.0.4) db + Add docs/Doxygen
+ Begin Framework for working on Leonardo (incomplete)
~ Minor format cleanup
02/08/2012 (v0.0.3) db ! Fixed regression in last commit with rgb
02/07/2012 (v0.0.2) db ! Fixed typo in send functions
! Changed write to print for maximal compatibility with serial code
dm ! Point Library to Absolute Path, Add documentation
02/06/2012 (v0.0.1) db ! Lowered Baud to 2400 due to softwareSerial rxBuffer size issue
+ Add shield Commands(SetLED, Leave, Find, NetworkStatus)
+ Updated Example to also SetLED with on/off control
+ Add Doxygen comments & Version to Lib
02/04/2012 (unversioned) db + Initial Commit (currently depends on SoftwareSerial)

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#######################################
# Data Types
#######################################
SmartThings KEYWORD1
SmartThingsCallout_t KEYWORD1
SmartThingsNetworkState_t KEYWORD1
SmartThingsSerialType_t KEYWORD1

#######################################
# Public Methods / Functions
#######################################
run KEYWORD2
send KEYWORD2
shieldSetLED KEYWORD2
shieldFindNetwork KEYWORD2
shieldLeaveNetwork KEYWORD2
shieldGetLastNetworkState KEYWORD2
shieldGetNetworkState KEYWORD2
Loading

0 comments on commit 09fc659

Please sign in to comment.