[DEPRECATED] ST_Anything - Arduino/ESP8266/ESP32

Dan,

That sounds great!!! How about just putting an option in the sketch to enable DHCP? Or is that at DH dependent?

Thanks Dan!

Rob

Rob,

I have a working version of the ESP8266WiFi network communications SmartThings library that will allow you to use Statically Assigned DHCP addresses. I am trying to incorporate support within my ā€œSmartThingsā€ library (which does all of the network communications for ST_Anything or a custom sketch) for additional network devices like the W5500 shield and the ATWINC1500 WiFi breakout module from Adafruit.

Can you wait a few more days for all of these SmartThings library changes, or do you want what I have so far for the ESP8266WiFi?

Dan

Dan,

Absolutely!!! I can wait! Thank you so much for the effort!

Very excited about this!

Thanks again,

Rob

Hey Dan,

Any Chance you could point me in the right direction to make a momentary switch? I want to try to use this to open and close my garage door. Currently, when I hit the tile to turn on or off switch1, it stays on. Iā€™d like to have it turn on for a second, then turn right back off.

Also, Iā€™m seeing some debounce in the contact sensorā€¦ for instance, when I set the contact sensor up to turn on switch2, it initially turns on switch2 when I open contact2, (it is just two wiresā€¦ One to D3 and one to GND) but a few seconds later when I close contact2, switch2 opens, then a second later closes. Iā€™m thinking Iā€™m getting a bounce when I close my contact.

Iā€™m getting close to where I want this to be, thanks to you!

Thanks again Dan,

Rob

Rob,

Please explain exactly what youā€™re trying to do, so I can help guide you to use the best options that ST_Anything has to offer. Also, if using a NodeMCU ESP8266 board, please be aware that there are some pins which are best to avoid. See

Here are some tips that may help you move your ST_Anything based project alongā€¦

If you look at one of the Arduino MEGA based default examples, like ST_Anything_Multiples_EthernetW5100.ino, you will see quite a few more devices supported in ST_Anything, aside from what youā€™ll find in the NodeMCU ESP8266 WiFi example.

For a garage door, I would encourage you to use one of my ā€œdoorControlā€ objects, as it is designed to operate a garage door. You supply it one input pin (a magnetic reed switch) and one output pin (a relay which is wired to ā€œpress your garage door buttonā€). You also supply it with how long you want the button pressed. It will automatically turn off the relay after the amount of time you desire Mine is set to 1 second (1000msec) as shown below.

static st::IS_DoorControl sensor15(F("doorControl1"), PIN_DOORCONTROL_CONTACT_1, LOW, true, PIN_DOORCONTROL_RELAY_1, LOW, true, 1000);

If really just want an automatic timed relay, you should use one of my TimedRelay devices. In the example below, it will turn off after 3 seconds (3000 msec).

static st::S_TimedRelay sensor21(F("relaySwitch1"), PIN_TIMEDRELAY_1, LOW, true, 3000, 0, 1);

To adjust the debounce on the contact sensor, simply change the last argument of its constructor. That is the NUMBER of COUNTS (number of times through the arduino loop() routine) that the input must be either or high or low before it is considered a valid change. Increase from 500 to a larger value if desired.

static st::IS_Contact sensor11(F("contact1"), PIN_CONTACT_1, LOW, true, 500);

Read the comments at the top of each respective devices class module, found in the ST_Anything Arduino library folder, to learn about all of the arguments and their purpose. IS_DoorControl.h, S_TimedRelay.h, and IS_Contact.h.

If you want some additional assistance, please post your Arduino Sketch (please be sure to highlighted the pasted text and click the Preformatted Text button ā€œ< / >ā€ in Forum Editor Menu bar. Otherwise, the code gets really messed up.)

Hopefully youā€™re not putting code in the loop() routine as you really should not need to for most applications. If you find yourself needing to, let me know and we can discuss what the best options are for your application. Any code in loop() which would cause delays or manipulate GPIO pins used by ST_Anything is a bad idea, in general.

Dan

Dan,

That was it! Thatā€™s what I needed to get the garage door opening. I do like having the contact sensor to let me know when the door is open. My garage door has two contact sensors built in. One for setting the closed limit switch and the open limit switch. Iā€™m hoping to use both contact (Yep, they are reed switches) switches to let me know when the door has made it to the open or closed positions. Is there a way to add a Second (or is it third???) argument to:

static st::IS_DoorControl sensor6(F(ā€œdoorControl1ā€), PIN_DOORCONTROL_CONTACT_1, LOW, true, PIN_DOORCONTROL_RELAY_1, LOW, true, 1500);

ā€¦And make it like thisā€¦

static st::IS_DoorControl sensor6(F(ā€œdoorControl1ā€), PIN_DOORCONTROL_CONTACT_1, LOW, true, PIN_DOORCONTROL_CONTACT_2, LOW, true, PIN_DOORCONTROL_RELAY_1, LOW, true, 1500);

I feel like thatā€™d make the ā€œopeningā€ and ā€œclosingā€ un-needed. So, Iā€™m looking to make it state ā€œnot closedā€. Iā€™ll get there.

Interesting discoveryā€¦ I placed the NodeMCU next to the garage door opener, and the wifi signal coming from the device keeps the car remote control from working. Verified it by moving the device away and back.

Thanks again!

Rob

1 Like

Glad to hear youā€™ve got things working. I really donā€™t think the doorControl needs yet another pin added to it. Obviously, youā€™re free to make a new version for your personal use. My feeling is that one magentic reed switch, positioned properly to activate when the garage door is in the closed position, provides all of the necessary information in 99% of the cases. If it is not closed, it must be open. We just donā€™t know how much it is openā€¦ :wink:

The ā€œopeningā€ and ā€œclosingā€ are standard Door Control states that SmartThings somewhat expects. If you use an original ST Multisensor as a GarageDoor sensor, it actually uses these for states. The states are based on the 3-axis orientation feature of the original multisensor. The sequence is always Closed-Opening-Open-Closing-Closed.

In my ST_Anything DoorControl class and Device Handler, I implement these same four states. Letā€™s say the starts in the Closed state. When you click on the tile, the state of the tile immediately changes to ā€œOpeningā€ to let you know a message has been sent to the Arduino/ESP8266 device. Once that message is received, the relay is fired for ~1sec. This causes the magnetic reed switch to change state, resulting in a message being sent to ST that the door is ā€œOpenā€ which updates the tile accordingly. The reverse process occurs for the closing sequence. Personally, I like seeing the 4 discrete states. But, to each his own. Thatā€™s what I love about the Arduino platform and SmartThings - make it the way you want it! :slight_smile:

Thanks for the tip about placing the WiFi device too close to the opener. Good to know.

Dan,

I certainly understand the reasoning behind the single reed switch. My door has two, and I was going to try and use both to get more details about what the door was doing. I may still try to write a different garage Door device handler. For now, no re-creating the wheel. It does what I need it to do.

Iā€™m waiting to add more nodemcuā€™s until I hear back from you on the DHCP static IP thoughts.

Thanks for all of this and especially your support!!!

Rob

@ogiewon: I have been using ST_Anything since you initially released it and your wonderful utility has increased the capabilities of my SmartThings set-up infinitesimally! Thanks for all your hard work!

I had a query since you revamped the ST_Anything code recently. Any idea if I can still do the following, which I was able to achieve in the earlier version of your code?
a) Control the on-board RGB LED on the ThingShield [shieldSetLED(r,g,b) function]
b) Send messages to the ST cloud to modify device states via code [send(string) function]

I did try accessing the same way as I did with the older version of ST_Anything, but that did not seem to work.
Please advise.

Iā€™ve had my Garage Doors system since the beginning of ST_Anything, so I had to have a different approach which still may be something to consider. I created 3 door switches: The Master ON provides overall status and then I had one of each other door. So if either door is open, then the master/overall is open. Pressing close only closes any open door. Since the Master switch is a switch capability I use CoRE to warn me if the door is left open at night or during freezing weather. IFTT callā€™s me if the door has been left a very long and texts me when I leave home and door is still open. Oh yea, my door automatically opens when I get back from work (I have a guard that keeps this from happening after 7pm, and only enables once a day when I leave my work area). So my DH tile looks like:
> standardTile(ā€œmainGDā€, ā€œdevice.mainGDā€, canChangeBackground: true) {

  	state("unknown", label:"unknown Main", action:"refresh.refresh", icon:"st.doors.garage.garage-open", backgroundColor:"#d04e00")
  	state("closed",  label:"closed Main",  action:"pushMainGD", icon:"st.doors.garage.garage-closed", backgroundColor:"#79b821", nextState:"opening")
  	state("open",    label:"open Main",    action:"pushMainGD", icon:"st.doors.garage.garage-open", backgroundColor:"#ffa81e", nextState:"closing")
  	state("opening", label:"opening Main", icon:"st.doors.garage.garage-opening", backgroundColor:"#ffe71e")
  	state("closing", label:"closing Main", icon:"st.doors.garage.garage-closing", backgroundColor:"#ffe71e")
  }

AJ,

Can you please share the old lines of code that perform the two functions you mentioned? I will then figure out and post how to do them using the newer libraries.

Dan

Dan,
I changed over to the nodemcu yesterday and got everything working. this morning all of my devices (lights, locks, fans, ect) were all acting very strange and most non responsive. Right now i have lights randomly turning on and off but they dont respond to any commands. I have been chatting with support and they believe the culprit is your custom device I installed yesterday. I am trying to get them to give me more information to share with you on what they believe it is doing.
have you seen issues like this in the past?

They didnt give me much. They said that this is an issue they have seen with custom device types and have only had a few instances of it happening. My chat got disconnected but this is all they said when I was asking for more details for you:

Upon further discussion with our team, since this is a custom integration we really donā€™t have much details to give you other than weā€™re going off what weā€™ve seen recently. Again, this is a fairly new issue with only a few cases weā€™ve seen and itā€™s now being tracked.

The only thing I can think of is that you have a bunch of polling sensors that you set the polling interval to be too fast. This could then overwhelm STā€¦ ???

If you simply remove power from the NodeMCU, all traffic will stop flowing.

Does doing thins resolve the issue? I have never seen this issue.

Are you using V1 or V2 hub? I have only tried this with V2 hub.

Just guessing here! I have run about 5 copies of the my ā€œST_Anything_Multiples_xxxxx.inoā€ sketches at the same time (each on different hardware platform) without any ill-effects on my other Zigbee/Z-Wave devices.

Sure. Thanks for offering to help!

Given below is the code snippet from the original code I had, which worked pre-v2 of ST_Anything (I have retained the key lines only. Can post the full code if needed).

ā€¦include < SmartThingsThingShield.h>
.
.
.
if defined(ARDUINO_AVR_UNO) || defined(ARDUINO_AVR_NANO) || defined(ARDUINO_AVR_MINI) //Arduino UNO, NANO, MINI
st::SmartThingsThingShield smartthing(PIN_THING_RX, PIN_THING_TX, messageCallout);
.
.
.
void on()
{
digitalWrite(PIN_LED, HIGH);
smartthing.shieldSetLED(0, 0, 1); // Canā€™t call this shieldSetLED function with the new library
smartthing.send(ā€œonā€); // Canā€™t call this send function with the new library
}
ā€¦

In the above code, I have issues with calling the functions on the last two lines, from within the ST_Anything_Multiples_Thingshield.ino script that you currently have in v2.6.
I have tried changing the scope variable specified in the call but I keep getting an errors about the member function not being available.

Take a look at the updated example sketch for the SmartThings library for the ThingShield. I am pretty sure I tested the functionality youā€™re referring to.

Yes, I did check the example script and it works perfectly as is.

However, when attempting to call these functions from within the ST_Anything_Multiples_Thingshield.ino script you have provided, I face different errors, all mostly to do with ā€œcannot call member function ā€˜ā€¦shieldSetLEDā€¦ā€™ without objectā€.

I am relatively new to SmartThings and Arduino programming as such and I suspect the problem lies in my understanding of how to call the functions that I am having issues with.
As a last resort, I have posted the entire code of what I am trying to achieve. The problem I am facing lies with any line that starts with
st::SmartThingsThingShield::shieldSetLED(
OR
st::SmartThingsThingShield::send(

My apologies if this is too basic troubleshooting that I am requesting for but even a push in the right direction can help me work this out.

https://github.com/ajayjohn/ST_Anything/blob/master/Arduino/Sketches/ThingShield_Test_v20170510.ino

Hi, not to hijack the last guys question as I donā€™t think theyā€™re related (FIFO :slight_smile: )

Having trouble getting a DHT11 working. I can see data in/out on the serial port (Itā€™s a NODE MCU btw), but no child devices get created, and it doesnā€™t seem to like having ā€˜0ā€™ for the number of buttons (though ā€˜00ā€™ seems to workā€¦).

I noted the part about temphumid1 and temperature1/humidity1, but it didnā€™t seem to change anything either way. I chopped out most of the commented bits to make it a bit more forum friendly. As an aside, I uncommented most of the debug/log sections in both the DH and the INO file (though after I couldnā€™t get it working). I also noticed that in the ā€˜Temperatureā€™ child DH, thereā€™s some lines commented out for humidity -
tried it both ways with no love. Hereā€™s my version of your ST_Anything_ESP8266WiFi sketch:

//* v2.6 *//
//******************************************************************************************
//  File: ST_Anything_Multiples_ESP8266WiFi.ino
//  Authors: Dan G Ogorchock & Daniel J Ogorchock (Father and Son)
//  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_TemperatureHumidity.h>  //Implements a Polling Sensor (PS) to measure Temperature and Humidity via DHT library

//*************************************************************************************************
//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 D4  2

//******************************************************************************************
//Define which Arduino Pins will be used for each device
//******************************************************************************************
#define PIN_TEMPERATUREHUMIDITY         D4

//******************************************************************************************
//ESP8266 WiFi Information
//******************************************************************************************
String str_ssid     = "ssid";                           //  <---You must edit this line!
String str_password = "pass";                   //  <---You must edit this line!
IPAddress ip(10, 20, 30, 104);       //Device IP Address       //  <---You must edit this line!
IPAddress gateway(10, 20, 30, 1);    //Router gateway          //  <---You must edit this line!
IPAddress subnet(255, 255, 255, 0);   //LAN subnet mask         //  <---You must edit this line!
IPAddress dnsserver(8, 8, 8, 8);  //DNS server              //  <---You must edit this line!
const unsigned int serverPort = 8090; // port to run the http server on

// Smartthings Hub Information
IPAddress hubIp(10, 22, 11, 35);    // 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("enableDebug = true");  //use same strings that the Device Handler would send
}

//******************************************************************************************
//Arduino Setup() routine
//******************************************************************************************
void setup()
{
  //******************************************************************************************
  //Polling Sensors
    static st::PS_TemperatureHumidity sensor1(F("temphumid1"), 15, 0, PIN_TEMPERATUREHUMIDITY, st::PS_TemperatureHumidity::DHT11,"temperature","humidity");
    
  //Interrupt Sensors 
  
  //Executors
  
  //*****************************************************************************
  //  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); 
    
  //*****************************************************************************
  //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();
}

I feel like I missed something obviousā€¦ :stuck_out_tongue:

EDIT: Theyā€™re not in the same IP range, and it just occurred to me that while the deivce can ping the hub, the hub may not be able to ping the device - donā€™t no if it matters, but Iā€™m not in control of the network (just my ā€˜non-enterprise levelā€™ AP hiding under my desk (thus the different IP range) Investigating this - but in theory, if this isnā€™t the problemā€¦what did I miss?

Simple fixā€¦

Change the constructor line of code in setup() for the DHT11 to

static st::PS_TemperatureHumidity sensor1(F("temphumid1"), 15, 0, PIN_TEMPERATUREHUMIDITY, st::PS_TemperatureHumidity::DHT11,"temperature1","humidity1");

Note the ā€œ1ā€ after ā€œtemperatureā€ and ā€œhumidityā€ - the numeric value is required to distinguish each child device. Thus for a child to be created, the naming convention must be adhered to. This is in the ST_Anything ReadMe near the bottom, I believe. The DHT sensor is a bit strange since it does both Temp and Humidity.

Well, thereā€™s an idiot born every dayā€¦ I had actually started with that line, and changed it to be without it for debuggingā€¦ Turns out I was right though - was a network issue. Of course it didnā€™t occur to me till Iā€™d clicked the ā€˜replyā€™ button.
<sigh>

Thanks for the reply though :slight_smile: