@jparent14 I took a few minutes to modify Bruce’s old Arduino sketch to work with my newer SmartThings… libraries. Be sure to download all of the new “SmartThings…” library folders from my GitHub repo to your local C:\Users\your_username\Documents\Arduino\libraries folder. Remove any old “SmartThings” library folder you might have to avoid any conflicts.
Here is the sketch, modified to work with a W5100 shield. Again, you’ve got some significant rework to do on the Groovy Device Handler side. You could user my ST_Anything_Parent_Ethernet device handler as a starting point, but you’re going to need to hack it up dramatically to remove a ton of unnecessary code. Use it more as a model for how LAN based network communications can be made to work.
Good luck with your project!
//*****************************************************************************
/// @file
/// @brief
/// Arduino W5100 Shield SmartThings / Lutron Interface
//*****************************************************************************
//#include <SmartThings.h>
#include <SmartThingsEthernetW5100.h>
//#define PIN_THING_RX 3
//#define PIN_THING_TX 2
SmartThingsCallout_t messageCallout; // call out function forward decalaration
//******************************************************************************************
//W5100 Ethernet Shield Information CHANGE THIS INFORMATION ACCORDINGLY FOR YOUR NETWORK!
//******************************************************************************************
byte mac[] = {0x06,0x02,0x03,0x04,0x05,0x06}; //MAC address, leave first octet 0x06, change others to be unique // <---You must edit this line!
IPAddress ip(192, 168, 1, 204); //Arduino device IP Address // <---You must edit this line!
IPAddress gateway(192, 168, 1, 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, 1, 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,1,149); // smartthings hub ip // <---You must edit this line!
const unsigned int hubPort = 39500; // smartthings hub port
//Create a SmartThings Ethernet W5100 object
st::SmartThingsEthernetW5100 smartthing(mac, ip, gateway, subnet, dnsserver, serverPort, hubIp, hubPort, messageCallout);
//SmartThings smartthing(HW_SERIAL3, messageCallout); // Hardware Serial constructor
bool isDebugEnabled; // enable or disable debug in this example
void setup()
{
isDebugEnabled = true;
// set the data rate for the Lutron port
Serial2.begin(9600);
//Run the SmartThings init() routine to make sure the Arduino W5100 Shield is connected to the ST Hub
smartthing.init();
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
}
}
String LutronResponse = "";
void getLutronResponse()
{
char ch = Serial2.read();
if (ch == 0x0D)
{
if (LutronResponse == "") return;
smartthing.send(LutronResponse);
LutronResponse = "";
}
else if (ch != '!') LutronResponse += ch;
}
void loop()
{
smartthing.run();
if (Serial2.available()>0) getLutronResponse();
}
void hello()
{
if (isDebugEnabled) Serial.println("Hello from ST");
// smartthing.shieldSetLED(1, 0, 0);
// delay(200);
// smartthing.shieldSetLED(0, 1, 0);
// delay(200);
// smartthing.shieldSetLED(0, 0, 1);
// delay(200);
// smartthing.shieldSetLED(1, 1, 0);
// delay(200);
// smartthing.shieldSetLED(1, 1, 1);
// delay(200);
// smartthing.shieldSetLED(1, 0, 1);
// delay(200);
// smartthing.shieldSetLED(0, 1, 1);
// delay(200);
// smartthing.shieldSetLED(3, 2, 1);
// delay(200);
// smartthing.shieldSetLED(1, 2, 3);
// delay(200);
// smartthing.shieldSetLED(2, 2, 4);
// delay(200);
// smartthing.shieldSetLED(4, 3, 1);
// delay(200);
// smartthing.shieldSetLED(0, 0, 0);
}
void messageCallout(String message)
{
if (message == "") return;
if (isDebugEnabled)
{
Serial.print("Received message: '");
Serial.print(message);
Serial.println("' ");
}
if (message.equals("hello")) hello();
else Serial2.println(message); // send command to Lutron
}