[DEPRECATED] ST_Anything - Arduino/ESP8266/ESP32

@jturner318

I have spent about 2 hours trying to make a Routine either Open or Close a garage door. No matter what I try, it seems like that feature of a Routine NEVER calls any of the methods within the Child Door Control device. I tried making it have significantly more ST Capabilities, and added the associated commands for those capabilities, in the hope that I could figure exactly what command(s) the routine is expecting. As far as I can tell, I have properly implemented everything necessary for both a “Door Control” and “Garage Door Control” device. I also implemented the “Momentary” capability to no avail. I tried both “Switch” and “Relay Switch” as well.

To me, it appears that SmartThings has broken the ability for a Routine to interact with a “Garage Door Control” device.

If you figure it out, please let me know as I would be happy to improve the “Child Door Control” Device Handler to work with a Routine.

It could be a “security feature” that samsung has implemented. Similar to how Alexa wont let you execute a routine with a smart lock associated with it.

Has anyone successfully added the AdafruitThermocouple to an ESP8266? I added it to the ESP sketch, but get a compile error in the Adafruit_MAX31855.cpp code as it can’t find: #include avr/pgmspace.h
Looks like the ESP code does not have that library
I guess?

Any help would be appreciated.

@Garnet,

I have just updated my library for the Adafruit MAX31855 Thermocouple with Adafruit’s current version which is now ESP8266 compatible.

I have also added a new ST_Anything_AdafruitThermocouple_ESP8266WiFi.ino sketch example for you to take a look at. It successfully compiles. However, I really just took a guess at which pins the MAX31855 would be connected to on a NodeMCU ESP8266 board. You may need to adjust the pin assignments based on your experimentation. Please let me know if this works for you and if you need to change the pins so I can update the example sketch accordingly.

All of the new code is already in my Github repository.

Hope this helps!

Dan

Note: I do not have an Adafruit MAX31855 board to test with, so I am relying on you to test this out.

1 Like

WOW
That was fast! I appreciate the quick response as I’m cooking 50 lbs of BBQ for a work event. My only issue is that the temperature is off, but at least it complies. It does seem to work and the temperature does change, but it is reporting high. I did get the Thermocouple directly from AliExpress, so I need to make sure it’s the right chip-set. I also bought one from another vendor, so I check that out too.
Update: Yea, the chipset on all three of my Thermocouples are from the other MAX6675, but used the Adafruit MAX6675 library and got it to work! I just hacked and made another PS_AdafruitThermocouple2 class that used the MAX6675 (this code didn’t have a guard, so I had to put that in too.). Not good engineering practice, but I’ll clean it up later and send the changes if you want to add to your library.

BTW: I bought the Thermocouple and converter (MAX6675) for about $3.00 from AliExpress. Will likely get one higher end one from Sparkfun, and eventually a real food grade version.

Thanks.

2 Likes

Hi Dan
I found a code for smoke detector Q2 and I would like to include it to your St_anything smoke in my node 8266.
Do you have any Idea.


I don’t need the led, buzzer or anything else juste the threshold of 400 that send a signal to ST.

Thank you

ST_Anything already has basic support for the MQ-2 smoke sensor. Take a look at the PS_MQ2_Smoke device. The device constructor details are shown below.

//******************************************************************************************
//  File: PS_MQ2_Smoke.h
//  Authors: Dan G Ogorchock & Daniel J Ogorchock (Father and Son)
//
//  Summary:  PS_MQ2_Smoke is a class which implements the SmartThings "Smoke Detector" device capability.
//			  It inherits from the st::PollingSensor class.  The current version uses an analog input to measure the 
//			  value from the MQ2 sensor.
//
//			  Create an instance of this class in your sketch's global variable section
//			  For Example:  st::PS_MQ2_Smoke sensor1("smoke1", 10, 0, PIN_MQ2_SMOKE, 300);
//
//			  st::PS_MQ2_Smoke() constructor requires the following arguments
//				- String &name - REQUIRED - the name of the object - must match the Groovy ST_Anything DeviceType tile name e.g. "smoke1", "smoke2", etc...
//				- long interval - REQUIRED - the polling interval in seconds
//				- long offset - REQUIRED - the polling interval offset in seconds - used to prevent all polling sensors from executing at the same time
//				- byte pin - REQUIRED - the Arduino Pin to be used as a digital output
//				- int sensorLimit - REQUIRED - if sensor reads value above this limit, report Smoke Detected (typical range is 0 to 1023 on Arduino Analog Input)
//
//
//  Change History:
//
//    Date        Who            What
//    ----        ---            ----
//    2017-07-04  Dan Ogorchock  Original Creation
//
//
//******************************************************************************************

Hi Dan

Thank you for the reply
Can you tell me what is wrong?
Thank you

Arduino: 1.8.3 (Windows 10), Board: “NodeMCU 1.0 (ESP-12E Module), 80 MHz, 115200, 4M (3M SPIFFS)”

C:\Users\Stephane\Documents\Arduino\Bureau\Bureau.ino:50:20: fatal error: PS_MQ2.h: No such file or directory

#include <PS_MQ2.h>

                ^

compilation terminated.

exit status 1
Error compiling for board NodeMCU 1.0 (ESP-12E Module).

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

//******************************************************************************************
// File: ST_Anything_Multiples_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_Multiples implements the following ST Capabilities as a demo of what is possible with a single NodeMCU ESP8266
// - 1 x Alarm device (using a simple digital output)
// - 1 x Contact Sensor devices (used to monitor magnetic door sensors)
// - 1 x Switch devices (used to turn on a digital output (e.g. LED, relay, etc
)
// - 1 x Motion devices (used to detect motion)
// - 1 x Smoke Detector devices (using simple digital input)
// - 1 x Temperature Measurement devices (Temperature from Dallas Semi 1-Wire DS18B20 device)
// - 1 x Relay Switch devices (used to turn on a digital output for a set number of cycles And On/Off times (e.g.relay, etc
))
// - 2 x Button devices (sends “pushed” if held for less than 1 second, else sends “held”
// - 1 x Water Sensor devices (using the 1 analog input pin to measure voltage from a water detector board)
//
// Change History:
//
// Date Who What
// ---- — ----
// 2015-01-03 Dan & Daniel Original Creation
// 2017-02-12 Dan Ogorchock Revised to use the new SMartThings v2.0 library
// 2017-04-17 Dan Ogorchock New example showing use of Multiple device of same ST Capability
// used with new Parent/Child Device Handlers (i.e. Composite DH)
// 2017-05-25 Dan Ogorchock Revised example sketch, taking into account limitations of NodeMCU GPIO pins
//
//******************************************************************************************
//******************************************************************************************
// 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
#include <PS_MQ2.h>
#include <PS_TemperatureHumidity.h> //Implements a Polling Sensor (PS) to measure Temperature and Humidity via DHT library
#include <PS_DS18B20_Temperature.h> //Implements a Polling Sesnor (PS) to measure Temperature via DS18B20 libraries
#include <PS_Water.h> //Implements a Polling Sensor (PS) to measure presence of water (i.e. leak detector)
#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
#include <IS_Smoke.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 Siren capability via a digital output to a relay
#include <S_TimedRelay.h> //Implements a Sensor to control a digital output pin with timing 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_ALARM_1 D0 //SmartThings Capabilty “Alarm”
#define PIN_SWITCH_blue_iris D1 //SmartThings Capability “Switch”
#define PIN_SWITCH_bain D2 //SmartThings Capability “Switch”
#define PIN_BUTTON_1 D3 //SmartThings Capabilty Button / Holdable Button (Normally Open!)
#define PIN_BUTTON_2 D4 //SmartThings Capabilty Button / Holdable Button (Normally Open!)
#define PIN_MOTION2 D5 //SmartThings Capabilty “Motion Sensor” (HC-SR501 PIR Sensor)
#define PIN_MQ2_Smoke D6 //SmartThings Capabilty “Smoke Detector”
#define PIN_TEMPERATUREHUMIDITY D7 //SmartThings Capabilty “Temperature humidity Measurement”

//******************************************************************************************
//ESP8266 WiFi Information
//******************************************************************************************
String str_ssid = “TinaetSteph 2”; // <—You must edit this line!
String str_password = “summ1ers00000”; // <—You must edit this line!
IPAddress ip(192, 168, 2, 120); //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(xxx, xxx, xxx,xxx); //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, 2, 100); // 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
static st::PS_TemperatureHumidity sensor2(F(“temphumid1”), 120, 10, PIN_TEMPERATUREHUMIDITY, st::PS_TemperatureHumidity::DHT11, “Temperature1”, “Humidity1”);

//Interrupt Sensors
static st::IS_Button sensor4(F(“button1”), PIN_BUTTON_1, 1000, LOW, true, 500);
static st::IS_Button sensor5(F(“button2”), PIN_BUTTON_2, 1000, LOW, true, 500);
static st::IS_Motion sensor6(F(“motion2”), PIN_MOTION2, HIGH, false);
static st::PS_MQ2 sensor7(F(“smoke1”), PIN_MQ2_SMOKE, 10, 0, PIN_MQ2_Smoke, 300);

//Special sensors/executors (uses portions of both polling and executor classes)

//Executors
static st::EX_Alarm executor1(F(“alarm1”), PIN_ALARM_1, LOW, true);
static st::EX_Switch executor2(F(“switch1”), PIN_SWITCH_blue_iris, LOW, true); //Inverted logic for “Active Low” Relay Board
static st::EX_Switch executor3(F(“switch2”), PIN_SWITCH_bain, LOW, true); //Inverted logic for “Active Low” Relay Board

//*****************************************************************************
// 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(&sensor2);
st::Everything::addSensor(&sensor4);
st::Everything::addSensor(&sensor5);
st::Everything::addSensor(&sensor6);
st::Everything::addSensor(&sensor7);

//*****************************************************************************
//Add each executor to the “Everything” Class
//*****************************************************************************
st::Everything::addExecutor(&executor1);
st::Everything::addExecutor(&executor2);
st::Everything::addExecutor(&executor3);

//*****************************************************************************
//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();
}

Please, when pasting code into a forum post, highlight the text and click the Preformatted Text menu button. Otherwise much of you code is lost.

The error message indicates that you are not including the correct header file. Please include PS_MQ2_Smoke.h.

#include <PS_MQ2_Smoke.h> //Implements an Polling Sensor (PS) to monitor the value of an analog input pin with a MQ-2 sensor attached

and in your setup() routine, you need to call the constructor defined in the header file as shown below:

static st::PS_MQ2_Smoke sensor7(F("smoke1"), PIN_MQ2_SMOKE, 10, 0, PIN_MQ2_Smoke, 400);

I have a question about that.
You told me to include the file PS_MQ2_Smoke.h but in github you have the file is PS_MQ2.h
Is there a reason that you add Smoke.
For now it did not work yet, look like the file is misplace in the Arduino program`

Here is the error and next the code

Arduino: 1.8.3 (Windows 10), Board: "NodeMCU 1.0 (ESP-12E Module), 80 MHz, 115200, 4M (3M SPIFFS)"
 
C:\Users\Stephane\Documents\Arduino\Bureau\Bureau.ino:48:137: fatal error: PS_MQ2_Smoke.h: No such file or directory

#include <PS_MQ2_Smoke.h>    //Implements an Polling Sensor (PS) to monitor the value of an analog input pin with a MQ-2 sensor attached
 
                                                                                                                                         ^
 
compilation terminated.
 
exit status 1
Error compiling for board NodeMCU 1.0 (ESP-12E Module).
 
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.



//******************************************************************************************
//  File: ST_Anything_Multiples_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_Multiples implements the following ST Capabilities as a demo of what is possible with a single NodeMCU ESP8266
//              - 1 x Alarm device (using a simple digital output)
//              - 1 x Contact Sensor devices (used to monitor magnetic door sensors)
//              - 1 x Switch devices (used to turn on a digital output (e.g. LED, relay, etc...)
//              - 1 x Motion devices (used to detect motion)
//              - 1 x Smoke Detector devices (using simple digital input)
//              - 1 x Temperature Measurement devices (Temperature from Dallas Semi 1-Wire DS18B20 device)
//              - 1 x Relay Switch devices (used to turn on a digital output for a set number of cycles And On/Off times (e.g.relay, etc...))
//              - 2 x Button devices (sends "pushed" if held for less than 1 second, else sends "held"
//              - 1 x Water Sensor devices (using the 1 analog input pin to measure voltage from a water detector board)
//   
//  Change History:
//
//    Date        Who            What
//    ----        ---            ----
//    2015-01-03  Dan & Daniel   Original Creation
//    2017-02-12  Dan Ogorchock  Revised to use the new SMartThings v2.0 library
//    2017-04-17  Dan Ogorchock  New example showing use of Multiple device of same ST Capability
//                               used with new Parent/Child Device Handlers (i.e. Composite DH)
//    2017-05-25  Dan Ogorchock  Revised example sketch, taking into account limitations of NodeMCU GPIO pins
//
//******************************************************************************************
//******************************************************************************************
// 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_MQ2_Smoke.h>    //Implements an Polling Sensor (PS) to monitor the value of an analog input pin with a MQ-2 sensor attached
#include <PS_Illuminance.h>  //Implements a Polling Sensor (PS) to measure light levels via a photo resistor
 
#include <PS_TemperatureHumidity.h>  //Implements a Polling Sensor (PS) to measure Temperature and Humidity via DHT library
#include <PS_DS18B20_Temperature.h>  //Implements a Polling Sesnor (PS) to measure Temperature via DS18B20 libraries
#include <PS_Water.h>        //Implements a Polling Sensor (PS) to measure presence of water (i.e. leak detector)
#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
#include <IS_Smoke.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 Siren capability via a digital output to a relay
#include <S_TimedRelay.h>    //Implements a Sensor to control a digital output pin with timing 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_ALARM_1               D0  //SmartThings Capabilty "Alarm"
#define PIN_SWITCH_blue_iris      D1  //SmartThings Capability "Switch"
#define PIN_SWITCH_bain           D2  //SmartThings Capability "Switch"
#define PIN_BUTTON_1              D3  //SmartThings Capabilty Button / Holdable Button (Normally Open!)
#define PIN_BUTTON_2              D4  //SmartThings Capabilty Button / Holdable Button (Normally Open!)
#define PIN_MOTION2               D5  //SmartThings Capabilty "Motion Sensor" (HC-SR501 PIR Sensor)
#define PIN_MQ2_Smoke             D6  //SmartThings Capabilty "Smoke Detector"
#define PIN_TEMPERATUREHUMIDITY   D7  //SmartThings Capabilty "Temperature humidity Measurement"
 
//******************************************************************************************
//ESP8266 WiFi Information
//******************************************************************************************
String str_ssid     = "TinaetSteph 2";                           //  <---You must edit this line!
String str_password = "summ1ers00000";                   //  <---You must edit this line!
IPAddress ip(192, 168, 2, 120);       //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(xxx xxx xxx xxx);  //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, 2, 100);    // 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
  static st::PS_TemperatureHumidity sensor2(F("temphumid1"), 120, 10, PIN_TEMPERATUREHUMIDITY, st::PS_TemperatureHumidity::DHT11, "Temperature1", "Humidity1");
  
  //Interrupt Sensors
  static st::IS_Button              sensor4(F("button1"), PIN_BUTTON_1, 1000, LOW, true, 500);
  static st::IS_Button              sensor5(F("button2"), PIN_BUTTON_2, 1000, LOW, true, 500);
  static st::IS_Motion              sensor6(F("motion2"), PIN_MOTION2, HIGH, false);
  static st::PS_MQ2_Smoke           sensor7(F("smoke1"), PIN_MQ2_SMOKE, 10, 0, PIN_MQ2_Smoke, 300);
 
  //Special sensors/executors (uses portions of both polling and executor classes)
 
 
  //Executors
  static st::EX_Alarm executor1(F("alarm1"), PIN_ALARM_1, LOW, true);
  static st::EX_Switch executor2(F("switch1"), PIN_SWITCH_blue_iris, LOW, true);  //Inverted logic for "Active Low" Relay Board
  static st::EX_Switch executor3(F("switch2"), PIN_SWITCH_bain, LOW, true);  //Inverted logic for "Active Low" Relay Board
 
  //*****************************************************************************
  //  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(&sensor2);
  st::Everything::addSensor(&sensor4);
  st::Everything::addSensor(&sensor5);
  st::Everything::addSensor(&sensor6);
  st::Everything::addSensor(&sensor7);
      
  //*****************************************************************************
  //Add each executor to the "Everything" Class
  //*****************************************************************************
  st::Everything::addExecutor(&executor1);
  st::Everything::addExecutor(&executor2);
  st::Everything::addExecutor(&executor3);
   
  //*****************************************************************************
  //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();
}

The file is properly named in my github repository as far as I can tell. Here is a link to it. Do you have latest version of my repo downloaded? The MQ2 was very recently added.

Quick dumb question - I couldn’t find anything that directly said yes or no, though I suspect the latter - is the thing shield a ‘local control’ device? By which I mean the much sought after “local control” without the cloud. I’m guessing the answer is that this is a cloud device just like most things, but since I didn’t see something that flat out said it, I figured I’d ask (I have one of them and its been gathering dust - and shows up as a cloud device in the devices list, but I don’t recall if I used a custom device handler with it or not - or if it even matters
)

All custom Device Handlers and Smart Apps run in the ST Cloud, not locally on the ST Hub v2.

That being said, you can implement your own local control within the Arduino. This would be limited to devices attached directly to the Arduino, of course.

Well, I guess I meant more along the lines of - is the original “thing shield” device handler “custom” or not since it was originally(?) provided by ST. Not that that would guarantee local control


The original Smart Things Thingshield Device Handler was nothing more than a demo to help users get started with writing their own custom device handler for the ThingShield. It, and every other bit of custom code, still runs in the ST Cloud only. Hope this helps to clarify any confusion. :slight_smile:

Thats about what I figured
 was hoping in the off chance I was wrong
 there might be some interesting way of turning that into a workaround for local control, but that sort of hinged on the device handler being local
 I could make a local-ish cloud-like thing, but I’m kind of getting tired of always ‘making’ things work
 plus the app (as far as I know) doesn’t work ‘locally’ should the interwebs go offline. that one I think is kind of lame - I get the cloud thing (I don’t particularly like it, but from a business model/overhead etc standpoint, I get it). I suppose it would be too difficult to interact with the hub directly AND make use of cloud based smart in a sane fashion. Oh well. Thanks!

1 Like

@ogiewon, I’ve been trying to understand in your library and sketches where the code is that connects to the SmartThings hub, sends the message to hub for the device action, where the hub receives and acts on the message, and then where the message is received back from the hub. What libraries and sketches and what functions are these I want to see the details of how that is done not just an example call. I’m also curious about the actual format of the message that gets sent to the hub. I’m sure it’s probably right in front of me but not seeing where this is done.

EDIT: To add, I’m specifically looking for this for an esp8266 nodemcu if that matters.

I think I’ve figured some of this out. I found the code that does the connect to the hub and issues a POST to the hub. Once it does the POST I’m not completely understanding how the hub knows what to do with the request. I think it’s calling the Parent_ST_Anything_Ethernet device handler. The part I don’t understand is how the hub associates the POST with that device handler and not other device handlers.

@ecframe, sure thing. The architecture slide in the ReadMe of my Github repository explains things at a very high level.

There are two Arduino Libraries in use by a typical ST_Anything based Arduino sketch (same for either a real Arduino or an ESP8266). The first library is ST_Anything which is basically performing all of the local I/O processing and scheduling. It has a main class called “Everything” which is responsible for keeping track of each of the devices defined in the sketch’s setup() routine. Everything takes care of polling the “Polling Sensors” on a regular schedule as well as monitoring the “Interrupt Sensors” continuously for any change in state. Everything also is responsible for all bi-directional communication of the state of each device to the second library, “SmartThings”.

SmartThings is an enhanced version of the original ThingShield library provided by SmartThings. My son and I did quite of bit of work a few years ago to improve the performance and reduce the memory usage of this library for the ThingShield. When the ThingShield went end of life earlier this year, I decided to enhance the “SmartThings” library to allow it to also be used for LAN connected devices. SmartThings is the library used to perform all of the communications between the Arduino/ESP8266 and the ST Hub. The hub then communicates to the ST cloud and eventually the ST_Anything Parent Device Handler.

So, in your sketch’s setup() routine, you will find the creation of one of the SmartThings communications objects that is passed to the Everything class. Everything does not care which of the various SmartThings objects is passed to it, as they all implement the exact same interface. This keeps the ST_Anything library very generic.

As for the communication protocol, it is simply ASCII text. This mimics the same behavior originally used by the ThingShield. I felt it best to keep things very simple and similar to allow developers to easily migrate from the old ThingShield to one of the various LAN connected platforms. The ASCII text protocol that I have chosen to use is a simple name/value pair (space delimited.) So, the Arduino sends something like “contact1 open” or “contact1 closed” to the ST cloud, where the Parent Device Handler receives this string in its parse() routine. This in turn causes one of the child devices named “contact1” to be updated with a new value (Note: If the child named “contact1” does not already exist, the parent automagically creates the child device and updates the value. I tried to make this as plug-n-play as possible! :slight_smile: )

Likewise, data send from the ST Cloud is routed to “Everything” via the SmartThings library. A command is received in the same format, for example “switch1 on” or “switch1 off”. Everything finds a device object named “switch1” and calls its beSmart() routine. Within beSmart(), the device specific code parses the string and updates the I/O accordingly.

It should be known that you can use the “SmartThings” library independently of “ST_Anything”. The opposite is not the case though. So, if you want to simply invent your own communications mechanism and handle all of the I/O processing yourself, you’re more than welcome to use just the “SmartThings” library. I have some example sketches included in the library that match the original example provided by SmartThings for the ThingShield. This allows a user to refer to the original ST documentation as a “guideline” as obviously using a LAN connected device requires a little more configuration versus the old ThingShield.

Hope this helps!

Dan

Good question! The Device in SmartThings (look in the ST web based IDE) has a field called “Network Device ID” which is set to be the MAC address of the Arduino/ESP8266. Thus, when the hub gets a packet from the Arduino, it sends that packet up to the ST cloud. There, the sender’s MAC address is used to figure out which Device’s Network Device ID is a match. If it finds a match, the packet is sent to that Device’s parse() routine.

1 Like