[RELEASE] ST_Anything v2.9.6 - Arduino/ESP8266/ESP32 to ST via ThingShield, Ethernet, or WiFi

I found that you can edit the preferences from IDE and put the info in on there its been working for me 100% of the time. There’s a weird glitch where you can still add the device when you search but it doesn’t add anything because its already in the list. Sorry if I’m explaining that poorly

Yes, I do the same as well, but the ReadMe instructions are written for using the ST Classic App… So I try to be consistent. :slight_smile:

@ogiewon was a bad board along with a section of code Hub IP address was commented out, I didn’t catch that. New board flashed and all is up and running. Thanks

1 Like

@Synthesis - Hi i was reading your post concerning the car remote, while searching for a momentary relay control. So I’m actually looking to do the same thing, but I was actually going to take another remote, connect my relay outputs to that to control the functions, and leave the remote and ESP at home. My main goal is to add remote car start to my morning routine for cold and hot days. I’m curious how your project worked out?

Crazy coincidence I just ran into this exact issue last night. I had a board that just would not add to ST, I’m glad you mentioned bad board cause as soon as I swapped it out it added right away and created all the child devices

1 Like

@thrasher204 I’ve bought mine from Ali. This one programmed once and never again, and had a heck of a time getting the first program on it. I keep spares around for that reason and when I get an idea.

Thank you Ogiewon for all of your effort on this project! I got my LinkNodeR8 up and running based on the LinkNode R4 code you included in the package. I had a **** of a time getting the children to populate but after leaving the boot jumper off and/or rebooting the ST hub, she chooched!

Here’s the final LinkNode R8 code I used if anyone else wants to play along. Relays correspond to switch numbers 1 - 8, top to bottom, left to right. I used NodeMCU 1.0 (ESP-12E Module) as the board in the IDE.

//******************************************************************************************
//  File: ST_Anything_LinkNodeR8_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 LinkNodeR8 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 LinkNodeR8 ESP8266's WiFi.
//
//            ST_Anything_LinkNodeR8 implements the following Capabilities as a demo of what 
//            is possible with a single LinkSprite LinkNode R8 board
//              - 8 x Switch devices (used to turn on a digital output (e.g. LED, relay, etc...)
//
//  Board Programming details available at: http://www.linksprite.com/wiki/index.php?title=File:1-262-a.jpg
//    
//  Change History:
//
//    Date        Who            What
//    ----        ---            ----
//    2019-03-26  Dan Ogorchock  Original Creation
//    2019-05-18  John Crusan    Modified LinkNode R4 Code to support LinkNode R8
//
//******************************************************************************************
//******************************************************************************************
// 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 <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


//******************************************************************************************
//Define which Arduino Pins will be used for each device
//******************************************************************************************
#define PIN_S1              14  //LinkNode R8 Board Marking D8
#define PIN_S2              13  //LinkNode R8 Board Marking D7
#define PIN_S3               5  //LinkNode R8 Board Marking D10
#define PIN_S4              15  //LinkNode R8 Board Marking D11
#define PIN_S5              12  //LinkNode R8 Board Marking D6
#define PIN_S6              16  //LinkNode R8 Board Marking D9
#define PIN_S7               4  //LinkNode R8 Board Marking D17
#define PIN_S8              10  //LinkNode R8 Board Marking D12

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

// Smartthings Hub Information
IPAddress hubIp(192, 168, 1, 104);  // smartthings hub ip       //  <---You must edit this line!
const unsigned int hubPort = 39500; // smartthings hub port

// Hubitat Hub Information
//IPAddress hubIp(192, 168, 1, 143);    // hubitat hub ip         //  <---You must edit this line!
//const unsigned int hubPort = 39501;   // hubitat 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
  
  //Interrupt Sensors 

  //Special sensors/executors (uses portions of both polling and executor classes)
  
  //Executors
  static st::EX_Switch executor1(F("switch1"), PIN_S1, LOW, false);  //Non-Inverted logic for "Active High" Relay Board
  static st::EX_Switch executor2(F("switch2"), PIN_S2, LOW, false);  //Non-Inverted logic for "Active High" Relay Board
  static st::EX_Switch executor3(F("switch3"), PIN_S3, LOW, false);  //Non-Inverted logic for "Active High" Relay Board
  static st::EX_Switch executor4(F("switch4"), PIN_S4, LOW, false);  //Non-Inverted logic for "Active High" Relay Board
  static st::EX_Switch executor5(F("switch5"), PIN_S5, LOW, false);  //Non-Inverted logic for "Active High" Relay Board
  static st::EX_Switch executor6(F("switch6"), PIN_S6, LOW, false);  //Non-Inverted logic for "Active High" Relay Board
  static st::EX_Switch executor7(F("switch7"), PIN_S7, LOW, false);  //Non-Inverted logic for "Active High" Relay Board
  static st::EX_Switch executor8(F("switch8"), PIN_S8, LOW, false);  //Non-Inverted logic for "Active High" 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, "LinkNodeR8");
 
    //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
  //*****************************************************************************
      
  //*****************************************************************************
  //Add each executor to the "Everything" Class
  //*****************************************************************************
  st::Everything::addExecutor(&executor1);
  st::Everything::addExecutor(&executor2);
  st::Everything::addExecutor(&executor3);
  st::Everything::addExecutor(&executor4);
  st::Everything::addExecutor(&executor5);
  st::Everything::addExecutor(&executor6);
  st::Everything::addExecutor(&executor7);
  st::Everything::addExecutor(&executor8);
    
  //*****************************************************************************
  //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();
}
1 Like

@ogiewon am I reading correctly that I can use a distance sensor in place of the contact sensor for the garage door function? If so, is there a specific sensor that I must use? I got my DS18B20 temp sensor to read in the example sketch, but before I order I thought I’d ask. Thanks

Some users have hacked together a solution like that. Personally, I use inexpensive wired contact sensors on my pair of doors. They would every time without fail. Pretty simple device, when you think about it - a reed switch and a magnet. Not much to fail.

I remember one user used an Ultrasonic sensor to know whether or not his cars were present in the garage. I think we treated this as a presence sensor. Looks like the code for that is still in the following child DTH. The reported value is compared against a threshold to determine present or away.

First of all thanks for this library and all the support you provide.

I am trying to get the LED_on/off demo working and I keep getting “post request timed out”

Here is the output from the serial monitor

setup..
Disabling ESP32 WiFi Access Point

[WiFi-event] event: 0
[WiFi-event] event: 2
ESP32 station start

Initializing ESP32 WiFi network.  Please be patient...
Attempting to connect to WPA SSID: BLAH
..[WiFi-event] event: 7
WiFi connected
IP address: 
192.168.2.232
[WiFi-event] event: 7
WiFi connected
IP address: 
192.168.2.232


Enter the following three lines of data into ST App on your phone!
localIP = 192.168.2.232
serverPort = 8090
MAC Address = MACADDRESS

SSID = BLAH
PASSWORD = PASSWORD
hubIP = 192.168.2.88
hubPort = 39500
RSSI = -55

SmartThingsESP32WiFI: Intialized

Ready! Open http://esp32-webupdate.local in your browser
IP address: 192.168.2.232
MAC address: CC:50:E3:80:9B:D4
Post request timed out

Post request timed out

Received message: 'off' 
Post request timed out

Post request timed out

And here is the output from the live debug

8:22:32 PM: debug Using ip: 192.168.2.232 and port: 8090 for device: DEVIC_ADDRESS
8:22:32 PM: debug Executing 'sendEthernet' off
8:22:32 PM: debug Sending 'off'
8:22:32 PM: debug Using ip: 192.168.2.232 and port: 8090 for device: DEVICE_ADDRESS
8:22:32 PM: debug Executing 'sendEthernet' off
8:22:32 PM: debug Sending 'off'

Hmmmm… I don’t have an ESP32 version of the very old “On/Off” demo sketch in my repository? Did you write your own?

What is your goal? Most users start with the ST_Anything_Multiples_ESP32WiFi.ino sketch as a starting point. This sketch is designed to work with the ST_Anything Groovy Device Type Handlers.

The On/Off Sketches, and their corresponding DTH, are simply a very basic example that emulates the old example sketch for now-obsolete SmartThings ThingShield. This can be a useful starting point for someone that wants to role their own sketch from scratch and not use the rest of ST_Anything.

I was planning on using it to trigger a stepper motor to run for about 10 seconds when “ON” then run 10 seconds in the other direction when “OFF”

I will take a look at the multiples example and see if I can get that working

thanks!

If a servo motor would work for your application, there is already support for those built into the library using the EX_Servo class.

i don’t think it will, i need multiple revolutions, and as I understand it the servo class is only 180 correct?

That is correct. Are you an Arduino programmer? If so, you could possibly use the EX_Servo class files as an example for adding a stepper motor device class.

@ogiewon, I’ve successfully loaded the Node MCU multi onto my chip and played with everything i think I have interest in. which leads me to the following questions:

  1. I assume we now customize the pin definitions to match our needs and load that sketch onto our board?
  2. It appears switch induces 5v when off and ground when on?
  3. Relay switch induces 3.3v when off and ground when on for its duration?
  4. How can I reverse 2 & 3 if needed?
  5. I am showing 2 temperature children one shows accurate and one is way off - I am using a DS18B20 temp sensor .

Thanks in advance, im ready to start building :smile:

Correct. You can customize the pin definitions as you see fit, but be aware that the ESP8266 boards have limitations. Please see my ReadMe to see some of these limitations.

You’ll want to also define the list of devices as you see fit. Be sure to follow the naming convention as documented in the ReadMe. The names (first parameter of each device) are critical to their proper identification and creation on the ST side of things.

5V ??? Should be 3.3V on a NodeMCU ESP board.

The behavior is user selectable. When the EX_Switch device is created in the sketch, there are numerous parameters that are passed in which control the behavior of the digital output pin. Read the comments at the top of the EX_Switch.cpp or .h file for the documentation of these parameters.

Same as the EX_Switch above.

See answer for EX_Switch above.

Sometimes ST creates two child devices instead of just one (read the recent posts from the last few weeks on this issue.) Unfortunately, I haven’t found the root cause, nor a workaround for it. You have to delete the Parent Device (not the DTH!) and manually create it again until you get just one child device for each device you’ve defined in the sketch.

Is there support for Arduino due( sam processor)
Arduino\libraries\SmartThings/SmartThingsEthernet.h:37:3: error: ‘IPAddress’ does not name a type

IPAddress st_hubIP;

Hendre,
Did you ever get a modified version of this dth to work? I have the garage door working but not the open closed sensor.

I have never tried building for an Arduino Due. Most folks these days just grab an $8 NodeMCU ESP8266 off of Amazon.

© 2019 SmartThings, Inc. All Rights Reserved. Terms of Use | Privacy Policy

SmartThings; SmartApps®; Physical Graph; Hello, Home; and Hello, Smart Home are all trademarks of the SmartThings, Inc.