The original thread is extremely long so , decided to start new fresh one.
I created a Hubduino-based custom controller for the Autoslide (sliding door open/close actuator).
Everything is working almost fine but it looks like there is some timing related issues and I wonder
if this can be fixed right in Hubduino Sketch instead of adding a delays in RM
(Being experienced EE I hate the delay-based fixes for the problems).
Here is a Hubduino Sketch:
r for the //******************************************************************************************
// File: ST_Anything_Relays_ESP8266.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_Relays_ESP8266 implements the following ST Capabilities as a demo of what is possible with a single NodeMCU ESP8266
// - 3 x Relay Switch devices
//
//
// 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
// 2017-11-27 Kai Lenk Modified to 3 relaySwitch
// 2017-11-29 Dan Ogorchock Revisions to make sure works for Kai Lenk
// 2018-02-09 Dan Ogorchock Added support for Hubitat Elevation Hub
//
//******************************************************************************************
//******************************************************************************************
// SmartThings Library for ESP32WiFi
//******************************************************************************************
#include <SmartThingsESP32WiFi.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 <IS_Contact.h> //Implements an Interrupt Sensor (IS) to monitor the status of a digital input pin
#include <EX_Switch.h> //Implements an Executor (EX) via a digital output to a relay
#include <S_TimedRelay.h> //Implements a Sensor to control a digital output pin with timing capabilities
#include <EX_TimedRelayPair.h> //Implements an Executor to control a pair of digital output pins
//*************************************************************************************************
// WiFi Credentials
#include "credentials.h"
//*************************************************************************************************
//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
// ESP32 WDOOM IO Pins
#define IN1 14
#define IN2 12
#define IN3 13
#define OUT1 25
#define OUT2 26
#define OUT3 23
//******************************************************************************************
//Define which Arduino Pins will be used for each device
//******************************************************************************************
#define PIN_CONTACT_1 IN1 //Hubitat Capabilities - DIO Pin (Normally Open!)
#define PIN_CONTACT_2 IN2 //Hubitat Capabilities - DIO Pin (Normally Open!)
#define PIN_CONTACT_3 IN3 //Hubitat Capabilities - DIO Pin (Normally Open!)
#define PIN_TIMEDRELAY_1 OUT1 //SmartThings Capability "Relay Switch"
#define PIN_TIMEDRELAY_2 OUT2 //SmartThings Capability "Relay Switch"
#define PIN_RELAY_1 OUT3 //SmartThings Capability "Relay Switch"
//******************************************************************************************
//ESP8266 WiFi Information
//******************************************************************************************
// Set your WiFi details so the board can connect to the WiFi and Internet
// Get Credentials from the credentials.h file
const char* str_ssid = mySSID;
const char* str_password = myPASSWORD;
IPAddress ip (192, 168, 20, 151); // Device IP Address // <---You must edit this line!
IPAddress gateway (192, 168, 20, 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, 20, 1); // DNS Server // <---You must edit this line!
const unsigned int serverPort = 8090; // Port to run the HTTP Server on
// Hubitat Hub TCP/IP Address
IPAddress hubIp (192, 168, 20, 90); // Hubitat Hub IP // <---You must edit this line!
// Hubitat Hub TCP/IP Address
const unsigned int hubPort = 39501; // Hubitat Nub 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
//Interrupt Sensors
// Name, IO Pin, Initial State, Internal Pullup, Number of Loop Counts
static st::IS_Contact sensor1(F("contact1"), PIN_CONTACT_1, LOW, false, 500);
static st::IS_Contact sensor2(F("contact2"), PIN_CONTACT_2, LOW, false, 500);
static st::IS_Contact sensor3(F("contact3"), PIN_CONTACT_3, LOW, false, 500);
//Special sensors/executors (uses portions of both polling and executor classes)
static st::S_TimedRelay sensor4(F("relaySwitch1"), PIN_TIMEDRELAY_1, LOW, true, 1200, 0, 1, 0);
static st::S_TimedRelay sensor5(F("relaySwitch2"), PIN_TIMEDRELAY_2, LOW, true, 1200, 0, 1, 0);
//EX_Switch arguments(Name, Pin, Initial State, Invert Logic) change last 2 args as needed for your application
static st::EX_Switch executor1(F("switch1"), PIN_RELAY_1, HIGH, 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 ESP32WiFi Communications Object
//STATIC IP Assignment - Recommended
st::Everything::SmartThing = new st::SmartThingsESP32WiFi(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(&sensor1);
st::Everything::addSensor(&sensor2);
st::Everything::addSensor(&sensor3);
st::Everything::addSensor(&sensor4);
st::Everything::addSensor(&sensor5);
//*****************************************************************************
//Add each executor to the "Everything" Class
//*****************************************************************************
st::Everything::addExecutor(&executor1);
//*****************************************************************************
//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();
}
Here is a RM rule witch has timing related problem currently fixed with an added delay
The rule is triggered by physical Foot Switch connected to one out of 3 Hubduino
contact sensors. When rule is triggered it toggles virtual switch which triggers a dependent
RM rule. This one is actually sends a commands to the Autoslide actuator by toggling one of
two Hubduino relay-switch with 2sec auto off function. Without a 1 sec delay the log actually records on/off activity for the relay switch but physical Autoslide actuator ignores this command
(I am not sure if actual pulse was generated or it was too short). With the added 1 sec delay
things are working as expected however in both cases the Hubduino controller produces
"Connection reset" event in a log at exact time when on command was sent to the relay-switch.
My question is: Is it possible to fix this right in Arduino/Hubduino sketch?
The added delays are absolutely not welcome for fixing a problems.