[DEPRECATED] ST_Anything - Arduino/ESP8266/ESP32

Sorry for a lengthy post, but I’m still struggling with the ST. :tired_face:
Here is what get me aggravated and stumped:

  1. ST hub and Google home work flawlessly, no any delays or hiccups! (“hey, Google” command turns on&off Zwave bulbs connected to Zwave ST interface, so Wifi connected GHome passes a command through my router to web(Google cloud and back to ST cloud), then to ST hub and Zwave bulbs.)
  2. The Skybell (video door bell) works fine (passes video to its cloud and back to the phone’s app, wherever it is using-my wifi or cellular data).
  3. All Arduino boards have a huge delay, anything between one and Ninety minutes!
    Boards are mix of previously programmed over a year ago (Arduino 1.8.5, v2.3 and ST_anything v2.8), as well as newly done last week (Arduino 1.8.8 , v2.4.2 and St_anything v2.9.3)
  4. Sometimes boards work without any hiccups, but usually the board quits working after first action (let’s say the board has one contact and switch, used with Lights Automation, contact closes, the LA sends turn on command to switch, but does nothing once contacts opens)
  5. On the serial port monitor boards events post with a delay, even local such as closes/opens contact! Not sure why.

Items in paragraphs 1 and 2 works flawlessly, so all parts of my network (WAN, LAN, WIFI) and the Samsung ST work as intended.
Boards behavior described in paragraphs 3 &4 leads me to decision there is someone not right with boards sketch or how it was loaded into the board (even though I installed a fresh set on another PC :face_with_symbols_over_mouth:)
Delays make the automation beyond useful, so I am ready to rip of all boards out of walls and go back to the stone age! :sob:

Thanks Dan for quick replying. Please see the entire code as follows:

//******************************************************************************************
//  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 in multiples of 2 as a demo of what is possible with a single NodeMCU ESP8266
//              - 2 x Contact Sensor devices (used to monitor magnetic door sensors)
//              - 2 x Switch devices (used to turn on a digital output (e.g. LED, relay, etc...)
//              - 2 x Motion devices (used to detect motion)
//              - 2 x Smoke Detector devices (using simple digital input)
//
//            Plus 1 of each of the following  
//              - 1 x Water Sensor devices (using the 1 analog input pin to measure voltage from a water detector board)
//              - 1 x Alarm device (using a simple digital output)
//    
//  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)
//******************************************************************************************
//******************************************************************************************
// 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_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)
//#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
  #define D1  5
  #define D2  4
//#define D3  0
//#define D4  2
  #define D5 14
  #define D6 12
//#define D7 13
//#define D8 15

//******************************************************************************************
//Define which Arduino Pins will be used for each device
//******************************************************************************************
//#define PIN_WATER_1               A0  //NodeMCU ESP8266 only has one Analog Input Pin 'A0'

#define PIN_SWITCH_1              D1  //SmartThings Capabilty "Switch"
#define PIN_SWITCH_2              D2  //SmartThings Capabilty "Switch"
#define PIN_SWITCH_3              D5  //SmartThings Capabilty "Switch"
#define PIN_SWITCH_4              D6  //SmartThings Capabilty "Switch"
//#define PIN_CONTACT_1             D0  //SmartThings Capabilty "Contact Sensor"
//#define PIN_CONTACT_2             D3  //SmartThings Capabilty "Contact Sensor"
//#define PIN_MOTION_1              D4  //SmartThings Capabilty "Motion Sensor"
//#define PIN_SMOKE_2               D7  //SmartThings Capabilty "Smoke Detector"
//#define PIN_ALARM_1               D8  //SmartThings Capabilty "Alarm"


//******************************************************************************************
//ESP8266 WiFi Information
//******************************************************************************************
String str_ssid     = "dummy_ID";                           //  <---You must edit this line!
String str_password = "not_a_real_password"                   //  <---You must edit this line!
IPAddress ip(192, 168, 0, 227);       //Device IP Address       //  <---You must edit this line!
IPAddress gateway(192, 168, 0, 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, 0, 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, 0, 214);    // 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)
{
//Switch 2 can only be turned on only when Switch 1 is already turned ON.  In addition, turn OFF the Switch 2 when Switch 1 is turned OFF 

if (msg == "switch2 on") {
  if (D1 == HIGH){
    digitalWrite(D2, HIGH);
  else
    digitalWrite(D2, LOW);      
    }
}

if (msg == "switch1 off") {
  digitalWrite(D2, LOW);
}

}

//******************************************************************************************
//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_Water               sensor1(F("water1"), 60, 20, PIN_WATER_1, 200);
    
  //Interrupt Sensors 
 // static st::IS_Motion              sensor2(F("motion1"), PIN_MOTION_1, LOW, true);
  //static st::IS_Motion              sensor3(F("motion2"), PIN_MOTION_2, LOW, true);
 // static st::IS_Contact             sensor4(F("contact1"), PIN_CONTACT_1, LOW, true);
 // static st::IS_Contact             sensor5(F("contact2"), PIN_CONTACT_2, LOW, true);
 // static st::IS_Smoke               sensor6(F("smoke1"), PIN_SMOKE_1, HIGH, true, 500);
 // static st::IS_Smoke               sensor7(F("smoke2"), PIN_SMOKE_2, HIGH, true, 500);
  
  //Executors
  static st::EX_Switch executor1(F("switch1"), PIN_SWITCH_1, LOW, true);
  static st::EX_Switch executor2(F("switch2"), PIN_SWITCH_2, LOW, true);
  static st::EX_Switch executor3(F("switch3"), PIN_SWITCH_3, LOW, true);
  static st::EX_Switch executor4(F("switch4"), PIN_SWITCH_4, LOW, true);
  
  //static st::EX_Alarm executor3(F("alarm1"), PIN_ALARM_1, LOW, true );
  
  //*****************************************************************************
  //  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
  st::Everything::SmartThing = new st::SmartThingsESP8266WiFi(str_ssid, str_password, ip, gateway, subnet, dnsserver, 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); 
 // 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);
  st::Everything::addExecutor(&executor4);  
  //*****************************************************************************
  //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();
}

Can you guys double check my wiring please. Is it absolutely needed to add 5 bolt. If so I will have to wait for wemos D1 to come in. I’ve already burnt up one board trying this. Positive is on the left from solar charge regulator the negative is on the right.

You’re trying to control D2 as a switch function and with a callback? You’re already controlling it via the switch2 state. What you really want to do is put that logic into ST. By the time the board has received the switch2 on command, the switch is now on. You can’t prevent it from going on. The callback function comes after the switch is controlled by ST_Anything. Plus, you can’t just write the digital pin low. The switch will still be on in ST. If you want to control a switch with the callback function you have to simulate received the switch2 off message. But, like I said, the switch will already be on when the callback function executes.

There are actually 2 callback functions available. One upon receipt of a command and another once the command is processed. So… there is a way, but it requires a little coding in a few places to make it work… :wink: That’s why I asked him for the entire sketch…

Hey Dan, I have an issue and question. I have a ESP32 connected to my pool (but I’ve also noticed this on my ESP8266). It does have quite a few items connected to it: 12 relays, 6 buttons, and 2 thermostats so there’s many items receiving periodic updates that takes time to transmit.

I noticed this when bench testing and when now connected live. Some on/off commands do not reach the device and ST will stay at “Turning On/Off” until a refresh happens, then it reverts back to unchanged state. I’m NOT 100% sure this is the case, but when bench testing, it appears NOT to receive commands when the connect serial monitor was receiving status updates from ESP, as if when it transmits it does not listen.

So I guess I have three questions.

  1. Have you seen this, or is it just me? If so, is it fixable?
  2. If related ONLY to serial monitor output, can that be turned off?
  3. Can DH be modified to resend command if not status is not changed after x time?
  4. Any suggestion for me.

As always, thanks for your time and everything you’ve contributed to our community!!
Nathan

1 Like

Nathan,
Welcome to the club! I thought I was crazy!
I am experiencing the same behavior of ST connected ESP8266 and ESP01 boards from Feb 18th.
See my posts above. I would guess that the Samsung ST has changed their code which breaks Dan’s libraries or DH groovy codes.
Unfortunately, these delays make the automation beyond useful in my case, and most likely in yours as well.

Dan:
I would like to run my devices locally instead from ST cloud.
how to move from ST cloud to local? Any idea?
Thank you

I would love to do this as well, but at the same time, I do not want to lose an ability to control via ST cloud. Dan mentioned several times a local logic here, but I do not believe I have seen a published code here.
I am not a programmer, I am more a hardware guy, and could not figure out how to do this.
Here is what was suggested to do, but either it does not work or cannot be compiled.

//******************************************************************************************
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
  //NOTE:  you may need to play with the logic below to get the behavior you desire!!!
  //if (msg == "contact1 closed") {st::receiveSmartString("switch1 on");}
  //if (msg == "contact1 open") { st::receiveSmartString("switch1 off");}
  //if (msg == "contact2 closed") {st::receiveSmartString("switch2 on");}
  //if (msg == "contact2 open") { st::receiveSmartString("switch2 off");}
  
  //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
}

A second option suggested was :slight_smile:

 void callback(const String &msg)
{
  //Uncomment if it weould be desirable to using this function
  Serial.print(F("ST_Anything_Miltiples Callback: Sniffed data = "));
  Serial.println(msg);
  
  //TODO:  Add local logic here to take action when a device's value/state is changed

  if (msg == "contact1 closed"){
      if(flag1 == 0)
          st::receiveSmartString("switch1 on");
      else
          st::receiveSmartString("switch1 off");
  }
  if (msg == "contact1 open") { 
      if(flag1==0)
          st::receiveSmartString("switch1 on");
      else
          st::receiveSmartString("switch1 off");
  }
  if (msg == "switch1 on")
      flag1=1; 
  else
      flag1=0;

if (msg == "contact2 closed"){
      if(flag2 == 0)
          st::receiveSmartString("switch2 on");
      else
          st::receiveSmartString("switch2 off");
  }
  if (msg == "contact2 open") { 
      if(flag2==0)
          st::receiveSmartString("switch2 on");
      else
          st::receiveSmartString("switch2 off");
  }
  if (msg == "switch2 on")
      flag2=1; 
  else
      flag2=0;
  
  //Masquerade as the ThingShield to send data to the Arduino, as if from the ST Cloud (uncomment and edit following line(s) as you see fit)
  //st::receiveSmartString("Put your command here!");  //use same strings that the Device Handler would send
}

If you want your ST_Anything devices to run locally on your hub, I recommend buying a Hubitat Elevation hub. It runs all native and custom code locally.

ST is never going to let custom code run locally on their hub…and the new ST v3 hub has 50% less CPU and memory resources compared to the previous v2 hub. Local processing is not a priority for ST, IMHO.

1 Like

Dan:
How to get one Hubitat Elevation hub?
Any good source?

www.hubitat.com is the simplest way to get one. Please realize that this is more of a replacement for ST, although some people use both hubs. I just do not want you thinking you can add a Hubitat Elevation hub to SmartThings.

You should check out the Hubitat community at community.hubitat.com before considering migrating platforms.

@tito

Here is your sketch with the local processing changes you requested. In order to make sure the “switch2 on” command is ignored and replaced by a “switch2 off” command (which is sent back to ST to set the device status correctly), I had to modify Everything.h and Everything.cpp. Please make sure you are running a current version of all of the ST_Anything Arduino libraries. There have been some changes in the recent weeks and I want to make sure you have a matched set of code.

Note: I’m not feeling 100% right now, so this code is untested. It compiles fine…and in C++, that means the code is at least very close to working! :wink:

I look forward to hearing from you as to how well it works for your unique application.

Have fun!
Dan

//******************************************************************************************
//  File: ST_Anything_Tito_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_Tito implements the following ST Capabilities in multiples of 4 as a demo of what is possible with a single NodeMCU ESP8266
//              - 4 x Switch devices (used to turn on a digital output (e.g. LED, relay, etc...)
//
//    
//  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)
//    2019-2-24   Dan Ogorchock  Added special callbackSnd() and callbackRcvd2() functionality for local rules
//
//******************************************************************************************
//******************************************************************************************
// 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_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)
//#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
//#define D1  5
//#define D2  4
//#define D3  0
//#define D4  2
//#define D5 14
//#define D6 12
//#define D7 13
//#define D8 15

//******************************************************************************************
//Define which Arduino Pins will be used for each device
//******************************************************************************************
//#define PIN_WATER_1               A0  //NodeMCU ESP8266 only has one Analog Input Pin 'A0'

#define PIN_SWITCH_1              D1  //SmartThings Capabilty "Switch"
#define PIN_SWITCH_2              D2  //SmartThings Capabilty "Switch"
#define PIN_SWITCH_3              D5  //SmartThings Capabilty "Switch"
#define PIN_SWITCH_4              D6  //SmartThings Capabilty "Switch"
//#define PIN_CONTACT_1             D0  //SmartThings Capabilty "Contact Sensor"
//#define PIN_CONTACT_2             D3  //SmartThings Capabilty "Contact Sensor"
//#define PIN_MOTION_1              D4  //SmartThings Capabilty "Motion Sensor"
//#define PIN_SMOKE_2               D7  //SmartThings Capabilty "Smoke Detector"
//#define PIN_ALARM_1               D8  //SmartThings Capabilty "Alarm"


//******************************************************************************************
//ESP8266 WiFi Information
//******************************************************************************************
String str_ssid     = "dummy_ID";                           //  <---You must edit this line!
String str_password = "not_a_real_password";                   //  <---You must edit this line!
IPAddress ip(192, 168, 0, 227);       //Device IP Address       //  <---You must edit this line!
IPAddress gateway(192, 168, 0, 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, 0, 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, 0, 214);    // smartthings hub ip     //  <---You must edit this line!
const unsigned int hubPort = 39500;   // smartthings hub port


st::EX_Switch* switch1; //need a pointer to "switch1" so we can check its value in a callback function

//******************************************************************************************
//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 callbackSend(const String &msg)
{
  //Turn OFF the Switch 2 when Switch 1 is turned OFF 
  if (msg == "switch1 off") {
    st::receiveSmartString("switch2 off");
  }
}

//******************************************************************************************
//st::Everything::callOnMsgRcvd2() optional callback routine.  This is a sniffer to monitor 
//    data being received from ST.  This allows a user to act on data changes locally within the 
//    Arduino sktech before ST_Anything processes the command.
//******************************************************************************************
void callbackRcvd2(String &msg)
{
  //Switch 2 can only be turned on when Switch 1 is already turned ON.
  if (msg == "switch2 on") {
    msg = switch1->getStatus()== HIGH?"switch2 on":"switch2 off";
  }
}

//******************************************************************************************
//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_Water               sensor1(F("water1"), 60, 20, PIN_WATER_1, 200);
    
  //Interrupt Sensors 
 // static st::IS_Motion              sensor2(F("motion1"), PIN_MOTION_1, LOW, true);
  //static st::IS_Motion              sensor3(F("motion2"), PIN_MOTION_2, LOW, true);
 // static st::IS_Contact             sensor4(F("contact1"), PIN_CONTACT_1, LOW, true);
 // static st::IS_Contact             sensor5(F("contact2"), PIN_CONTACT_2, LOW, true);
 // static st::IS_Smoke               sensor6(F("smoke1"), PIN_SMOKE_1, HIGH, true, 500);
 // static st::IS_Smoke               sensor7(F("smoke2"), PIN_SMOKE_2, HIGH, true, 500);
  
  //Executors
  static st::EX_Switch executor1(F("switch1"), PIN_SWITCH_1, LOW, true);
  static st::EX_Switch executor2(F("switch2"), PIN_SWITCH_2, LOW, true);
  static st::EX_Switch executor3(F("switch3"), PIN_SWITCH_3, LOW, true);
  static st::EX_Switch executor4(F("switch4"), PIN_SWITCH_4, LOW, true);
  
  //static st::EX_Alarm executor3(F("alarm1"), PIN_ALARM_1, LOW, true );
  
  //*****************************************************************************
  //  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 = callbackSend;
  st::Everything::callOnMsgRcvd2 = callbackRcvd2;
  
  //Create the SmartThings ESP8266WiFi Communications Object
  st::Everything::SmartThing = new st::SmartThingsESP8266WiFi(str_ssid, str_password, ip, gateway, subnet, dnsserver, 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); 
 // 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);
  st::Everything::addExecutor(&executor4);  
  //*****************************************************************************
  //Initialize each of the devices which were added to the Everything Class
  //*****************************************************************************
  st::Everything::initDevices();

  switch1 = &executor1;  //need a global memory pointer to this object to use in the callback routine
}

//******************************************************************************************
//Arduino Loop() routine
//******************************************************************************************
void loop()
{
  //*****************************************************************************
  //Execute the Everything run method which takes care of "Everything"
  //*****************************************************************************
  st::Everything::run();
}

See the example above.

1 Like
  1. Have you seen this, or is it just me? If so, is it fixable? I have not seen this behavior myself.

  2. If related ONLY to serial monitor output, can that be turned off? It is not a simple task to disable all of the Serial.print() commands. I have never heard of the Serial.print commands messing up the receipt of new WiFi commands.

  3. Can DH be modified to resend command if not status is not changed after x time? You can modify the groovy code in any way you see fit. Look into the “runIn()” type calls if you think this would help.

  4. Any suggestion for me. Yes, I have one suggestion. Your comment about the system being unresponsive when it is writing serial data got me thinking. By default, every 5 minutes, an automatic Refresh is issued within the system to make sure ST is being kept up to date. While this is happening, the system is very busy sending data to ST and thus will not be very responsive to new commands. Since you have a high device count, the problem is worse in your case. If you want, you can adjust how often the automatic Refresh is issued, or disable it altogether. Modify constants.h as follows:

To disable the Automatic Refresh, change this line of code by uncommenting it.

//#define DISABLE_REFRESH		//If uncommented, will disable periodic refresh of the sensors and executors states to the ST Cloud - improves performance, but may reduce data integrity

To change the frequency of Automatic Refreshes, change the following line of code

			//Interval on which Device's refresh methods are called (in seconds) - most useful for Executors and InterruptSensors - only works if DISABLE_REFRESH is not defined above
			static const int DEV_REFRESH_INTERVAL=900;				//seconds - Used to make sure the ST Cloud is kept current with device status (in case of missed updates to the ST Cloud) - primarily for Executors and InterruptSensors - only works if DISABLE_REFRESH is not defined above

It doesn’t sound like you’re experiencing the same issue as @AlecBL. You’ve just got a busy little board there! :wink:

Bob - we have no way to know if you’re wiring is correct or not. There is no microcontroller even in the picture. I explained all of the wiring requirements in a detailed Fritzing wiring diagram to you in this pot on Friday. Please use it to compare all of your wiring to make sure everything is being done correctly.

Dan, I’m sorry but I don’t see how this code is revalent to my desire have a local logic?
I understand that you are doing this project and support it as a hobby and I really admire you for that!

@AlecBL - I wish I knew what was going on in your system… I just don’t really have a clue as to why commands would take so long to be received by the ESP8266. I can tell you that I have done zero testing with the Arduino ESP8266 v2.5 board manager. All of my recent testing for both SmartThings and Hubitat have been with Arduino IDE 1.8.8 and ESP8266 v2.4.2.

You stated that you hadn’t see an example of local logic implemented within the sketch. I just provided you with one. There have been others previously in the thread as well.

I do not recall you ever defining specific local logic requirements that you wanted assistance with. I am happy to assist, however it seems you still have bigger issues currently just getting the basic functionality working.

@AlecBL - As a test, have you considered trying Konnected? It is a similar project that uses the same ESP8266 hardware. It communicates to ST slightly differently, and does not require any programming. It is not as flexible as ST_Anything… But, it might be worth taking a look at if ST_Anything continues to have issues in your environment.

Dan, Are you referring to Konnected alarm system? If so, I will try tomorrow.
I would like to get your help, please , with a local logic implemented as a toggle switch for ESP01.
Here is how it should work-switch1 turns on once contact1 closes, and turns off once contact1 opens.
I also want to turn on and off switch via ST phone app or using ST routine.