[RELEASE] ST_Anything - Arduino/ESP8266/ESP32

Got it! Will spend some time modifying sketches and hopefully get it working!

Thanks

This is the serial output when the board crashes. I set the onboard led to flash in the loop(). When it crashes the led no longer blinks, so i can assume the loop() is no longer running.

Everything: Free Ram = 3456
Everything: Sending: temperature1 74.48
Everything: Sending: humidity1 32.70
Everything: Sending: temperature1 74.30
Everything: Sending: humidity1 32.60
Everything: Sending: temperature1 74.30
Everything: Sending: humidity1 32.70
Everything: Sending: temperature1 74.30
Everything: Sending: humidity1 32.70
Everything: Free Ram = 3120
Everything: Sending: temperature1 74.30
Everything: Sending: humidity1 32.70
Everything: Sending: temperature1 74.30
Everything: Sending: humidity1 32.70
Everything: Sending: temperature1 74.30
Everything: Sending: humidity1 37.00
Everything: Sending: temperature1 74.30
Everything: Sending: humidity1 35.20
Everything: Free Ram = 2616
Everything: Sending: temperature1 74.30
Everything: Sending: humidity1 33.40
Everything: Sending: temperature1 74.12
Everything: Sending: humidity1 33.10
Everything: Sending: temperature1 74.12
Everything: Sending: humidity1 33.00
Everything: Sending: contact1 closed
PS_TemperatureHumidity: DHT Time out error
Everything: Sending: temperature1 74.12
Everything: Sending: humidity1 33.00
Everything: Free Ram = 3256
Everything: Sending: temperature1 74.12
Everything: Sending: humidity1 33.60
Everything: Sending: temperature1 73.94
Everything: Sending: humidity1 34.70

Trevor,

Thank you for providing so much detail! That helps a lot. This is the first time I have seem the freeRam decrease like this. This leads me to believe that there is a memory leak in one of the libraries. Since the Contact Sensor doesn’t use any extra 3rd party libraries, it probably is not that. You could comment it out temporarily to see if anything changes.

My suspicion is that it is the the DHT library. Did you grab the copy of the DHT library from my GitHub repository? Or did you already have a DHT library in your …Arduino\libraries\ folder? I believe I may have updated the DHT library in my GitHub repo not too long ago. Perhaps that is the problem?

I’ll set up an identical test system here when I find some time and will report back my findings.

Okay, first question:
Why do you have this at the top of your sketch:
int ledState = LOW;
long previousMillis = 0;
int interval = 1000;

Second question, why are you defining GPIO2 as an output? You seem to only have 2 sensors hooked to the board, you shouldn’t even need to use GPIO 2. What type of board are you using?

Also, you are defining a blink of the bulletin led at the end of the sketch. I don’t know how that would “mesh” with the rest of the ST_anything. I would take that out and see how it reacts.
Also, I would clean it up so your sensors are 1 and 2 and commend out the pins your aren’t using. That will allow you to use those pins for the devices you want and stay away from GPIO2 (D4).

You’re also polling the sensor every 15 seconds. That’s a LOT of data. Do you expect the temp or humidity to change that rapidly? I would recommend changing that to 120.

Why do you have the “contact sensor” doing to the sensor as well? It looks like that’s connected to pin 3 on the sensor? What’s going on there?

I grabbed all the libraries from your GitHub repo. I’m able to reproduce it quite easily here. I’ll keep investigating and let you know if i figure it out.

1 Like

The examples that Dan’s put together are really complete. There’s an example for just about everything. And a little tip I learned the hard way, comment out lines you don’t need with the “//” rather than delete them. You may decide you need it again and then you have to go back and grab it again. Also, if you’re working the Arduino IDE, save the sketch with a new name before you compile…otherwise the example will be overwritten.

1 Like

I have your sketch up and running and will keep an eye on the free ram to see if it drops here as well.

Sorry, the sketch is a little messy as i was just adding the blinking onboard led for debugging.

These are for the onboard led blinking:

int ledState = LOW;
long previousMillis = 0;
int interval = 1000;
pinMode(2, OUTPUT);

The problem was happening before i added the blink code. The polling time didn’t change from the original ST Anything code. I was planning to change that once i got everything up and running.

The contact sensor is just connected to VCC (3.3V) for now by a wire. Once i get this running i’ll add more contact sensors and use a magnetic door contact sensor.

My plan for this project is to monitor 3 garage doors, monitor temp and humidity, and control the garage doors as well.

@Trevorb1

Looks like you’re not using a DHT22 that is pre-attached to a breakout board. I think you may need to add a 10K resistor to your circuit as follows:

My free ram is holding fairly constant…

Everything: Free Ram = 40512
Everything: Sending: temperature1 75.56
Everything: Sending: humidity1 38.00
Everything: Sending: temperature1 75.56
Everything: Sending: humidity1 37.90
Everything: Sending: temperature1 75.56
Everything: Sending: humidity1 38.10
Everything: Sending: temperature1 75.56
Everything: Sending: humidity1 38.30
Everything: Free Ram = 40672
Everything: Sending: temperature1 75.56
Everything: Sending: humidity1 38.30
Everything: Sending: temperature1 75.56
Everything: Sending: humidity1 38.40
Everything: Sending: temperature1 75.56
Everything: Sending: humidity1 38.50
Everything: Sending: temperature1 75.56
Everything: Sending: humidity1 38.50
Everything: Free Ram = 40592
Everything: Sending: temperature1 75.56
Everything: Sending: humidity1 39.00
Everything: Sending: temperature1 78.08
Everything: Sending: humidity1 42.50
Everything: Sending: temperature1 77.90
Everything: Sending: humidity1 37.40
Everything: Sending: temperature1 77.54
Everything: Sending: humidity1 36.60
Everything: Free Ram = 40736
Everything: Sending: temperature1 77.18
Everything: Sending: humidity1 36.50
Everything: Sending: temperature1 77.18
Everything: Sending: humidity1 36.80
Everything: Sending: temperature1 77.00
Everything: Sending: humidity1 37.00
Everything: Sending: temperature1 76.82
Everything: Sending: humidity1 37.00
Everything: Free Ram = 40656
Everything: Sending: temperature1 76.64
Everything: Sending: humidity1 36.80
Everything: Sending: contact1 open
Everything: Sending: temperature1 76.64
Everything: Sending: humidity1 36.80
Everything: Sending: temperature1 76.64
Everything: Sending: humidity1 37.00
Everything: Sending: temperature1 76.46
Everything: Sending: humidity1 37.00
Everything: Free Ram = 40736
Everything: Sending: temperature1 76.46
Everything: Sending: humidity1 37.00
Everything: Sending: temperature1 76.46
Everything: Sending: humidity1 37.10
Everything: Sending: temperature1 76.28
Everything: Sending: humidity1 37.10
Everything: Sending: temperature1 76.28
Everything: Sending: humidity1 37.30
Everything: Free Ram = 40672
Everything: Sending: temperature1 76.28
Everything: Sending: humidity1 37.10
Everything: Sending: temperature1 76.28
Everything: Sending: humidity1 37.10
Everything: Sending: temperature1 76.28
Everything: Sending: humidity1 37.30
Everything: Sending: temperature1 76.28
Everything: Sending: humidity1 37.20
Everything: Free Ram = 40840
Everything: Sending: temperature1 76.10
Everything: Sending: humidity1 37.20
Everything: Sending: temperature1 76.28
Everything: Sending: humidity1 37.30
Everything: Sending: temperature1 76.10
Everything: Sending: humidity1 37.40
1 Like

Here my my sketch that monitors and controls 2 garage doors, monitors 4 other doors, measures Temp/Humidity, and detects motion in my garage. This is for an Arduino MEGA + W5500 shield, but the device definitions may prove useful to your project. Note this version uses the correct hub port for a Hubitat hub. Make sure you keep using the SmartThings Hub Port.

//******************************************************************************************
//  File: HubDuino_Door_EthernetW5500.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 Arduino + Ethernet W5500 Shield 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 Ethernet W5500 Shield.
//
//            ST_Anything_Multiples implements the following ST Capabilities in multiples of 2 as a demo of what is possible with a single Arduino
//              - 2 x Door Control devices (used typically for Garage Doors - input pin (contact sensor) and output pin (relay switch)
//              - 4 x Contact Sensor devices (used to monitor magnetic door sensors)
//              - 1 x Motion devices (used to detect motion)
//              - 1 x Temperature Measurement devices (Temperature from DHT22 device)
//              - 1 x Humidity Measurement devices (Humidity from DHT22 device)
//
//            During the development of this re-usable library, it became apparent that the 
//            Arduino UNO R3's very limited 2K of SRAM was very limiting in the number of 
//            devices that could be implemented simultaneously.  A tremendous amount of effort
//            has gone into reducing the SRAM usage, including siginificant improvements to
//            the SmartThings Arduino library.
//
//            Note: This sketch was fully tested on an Arduino MEGA 2560 using the Ethernet2 W5500 Shield.
//    
//  Change History:
//
//    Date        Who            What
//    ----        ---            ----
//    2018-02-11  Dan Ogorchock  Original Creation
//
//******************************************************************************************
//******************************************************************************************
// SmartThings Library for Arduino Ethernet W5500 Shield
//******************************************************************************************
#include <SmartThingsEthernetW5500.h>    //Library to provide API to the SmartThings Ethernet W5500 Shield

//******************************************************************************************
// 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 on an analog input pin 
#include <PS_Voltage.h>      //Implements a Polling Sensor (PS) to measure voltage on an analog input pin 
#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) on an analog input pin 
#include <IS_Motion.h>       //Implements an Interrupt Sensor (IS) to detect motion via a PIR sensor on a digital input pin
#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_CarbonMonoxide.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 capability with Siren and Strobe via digital outputs to relays
#include <S_TimedRelay.h>    //Implements a Sensor to control a digital output pin with timing/cycle repeat capabilities

//**********************************************************************************************************
//Define which Arduino Pins will be used for each device
//  Notes: Arduino communicates with both the W5500 and SD card using the SPI bus (through the ICSP header). 
//         This is on digital pins 10, 11, 12, and 13 on the Uno and pins 50, 51, and 52 on the Mega. 
//         On both boards, pin 10 is used to select the W5500 and pin 4 for the SD card. 
//         These pins cannot be used for general I/O. On the Mega, the hardware SS pin, 53, 
//         is not used to select either the W5500 or the SD card, but it must be kept as an output 
//         or the SPI interface won't work.
//         See https://www.arduino.cc/en/Main/ArduinoEthernetShield for details on the W5500 Sield
//**********************************************************************************************************
//"RESERVED" pins for W5500 Ethernet Shield - best to avoid
#define PIN_4_RESERVED            4   //reserved by W5500 Shield on both UNO and MEGA
#define PIN_1O_RESERVED           10  //reserved by W5500 Shield on both UNO and MEGA
#define PIN_11_RESERVED           11  //reserved by W5500 Shield on UNO
#define PIN_12_RESERVED           12  //reserved by W5500 Shield on UNO
#define PIN_13_RESERVED           13  //reserved by W5500 Shield on UNO
#define PIN_50_RESERVED           50  //reserved by W5500 Shield on MEGA
#define PIN_51_RESERVED           51  //reserved by W5500 Shield on MEGA
#define PIN_52_RESERVED           52  //reserved by W5500 Shield on MEGA
#define PIN_53_RESERVED           53  //reserved by W5500 Shield on MEGA


//Analog Pins

//Digital Pins
#define PIN_TEMPERATUREHUMIDITY_1 22  //SmartThings Capabilities "Temperature Measurement" and "Relative Humidity Measurement"
#define PIN_MOTION_1              24  //SmartThings Capability "Motion Sensor"
#define PIN_CONTACT_1             26  //SmartThings Capability "Contact Sensor"    KITCHEN DOOR
#define PIN_CONTACT_2             27  //SmartThings Capability "Contact Sensor"    FRONT DOOR
#define PIN_CONTACT_3             28  //SmartThings Capability "Contact Sensor"    BACK DOOR
#define PIN_CONTACT_4             29  //SmartThings Capability "Contact Sensor"    GARAGE BACK DOOR

//Garage Door Pins 
#define PIN_DOORCONTROL_CONTACT_1 34  //SmartThings Capabilty "Door Control"       DAN'S GARAGE DOOR
#define PIN_DOORCONTROL_RELAY_1   35  //SmartThings Capabilty "Door Control" 
#define PIN_DOORCONTROL_CONTACT_2 36  //SmartThings Capabilty "Door Control"       TRICIA'S GARAGE DOOR
#define PIN_DOORCONTROL_RELAY_2   37  //SmartThings Capabilty "Door Control" 

//Pushbutton Pins

//******************************************************************************************
//W5500 Ethernet Shield Information
//****************************************************************************************** 
byte mac[] = {0x90,0xA2,0xDA,0x11,0x06,0x5F}; //MAC address                                 //  <---You must edit this line using the MAC address provided with your W5500 Shield!
IPAddress ip(192, 168, 1, 130);               //Arduino 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

// Hubitat hub information
IPAddress hubIp(192,168,1,144);               // 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 withotu having to rely on the ST Cloud for time-critical tasks.
//******************************************************************************************
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
  
  //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
}

//******************************************************************************************
//Arduino Setup() routine
//******************************************************************************************
void setup()
{
  //******************************************************************************************
  //Declare each Device that is attached to the Arduino
  //  Notes: - For each device, there is typically a corresponding "tile" defined in your 
  //           SmartThings Device Hanlder Groovy code, except when using new COMPOSITE Device Handler
  //         - For details on each device's constructor arguments below, please refer to the 
  //           corresponding header (.h) and program (.cpp) files.
  //         - The name assigned to each device (1st argument below) must match the Groovy
  //           Device Handler names.  (Note: "temphumid" below is the exception to this rule
  //           as the DHT sensors produce both "temperature" and "humidity".  Data from that
  //           particular sensor is sent to the ST Hub in two separate updates, one for 
  //           "temperature" and one for "humidity")
  //         - The new Composite Device Handler is comprised of a Parent DH and various Child
  //           DH's.  The names used below MUST not be changed for the Automatic Creation of
  //           child devices to work properly.  Simply increment the number by +1 for each duplicate
  //           device (e.g. contact1, contact2, contact3, etc...)  You can rename the Child Devices
  //           to match your specific use case in the ST Phone Application.
  //******************************************************************************************
  //Polling Sensors 
  static st::PS_TemperatureHumidity sensor1(F("temphumid1"), 15, 0, PIN_TEMPERATUREHUMIDITY_1, st::PS_TemperatureHumidity::DHT22,"temperature1","humidity1");
  
  //Interrupt Sensors 
  static st::IS_Motion              sensor2(F("motion1"), PIN_MOTION_1, HIGH, true, 500);
  static st::IS_Contact             sensor3(F("contact1"), PIN_CONTACT_1, LOW, true, 500);
  static st::IS_Contact             sensor4(F("contact2"), PIN_CONTACT_2, LOW, true, 500);
  static st::IS_Contact             sensor5(F("contact3"), PIN_CONTACT_3, LOW, true, 500);
  static st::IS_Contact             sensor6(F("contact4"), PIN_CONTACT_4, LOW, true, 500);
  static st::IS_DoorControl         sensor7(F("doorControl1"), PIN_DOORCONTROL_CONTACT_1, LOW, true, PIN_DOORCONTROL_RELAY_1, LOW, true, 1000);
  static st::IS_DoorControl         sensor8(F("doorControl2"), PIN_DOORCONTROL_CONTACT_2, LOW, true, PIN_DOORCONTROL_RELAY_2, LOW, true, 1000);

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

  //Executors
    
  //*****************************************************************************
  //  Configure debug print output from each main class 
  //*****************************************************************************
  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 EthernetW5500 Communications Object
    //STATIC IP Assignment - Recommended
    //st::Everything::SmartThing = new st::SmartThingsEthernetW5500(mac, 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::SmartThingsEthernetW5500(mac, serverPort, hubIp, hubPort, st::receiveSmartString);

  //Run the Everything class' init() routine which establishes Ethernet communications with the 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);
  st::Everything::addSensor(&sensor8);
    
  //*****************************************************************************
  //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();
}

Not sure but this might be related to your free ram issue https://github.com/esp8266/Arduino/issues/4497

3 Likes

Thanks Jason, I think that fixed it. I downgraded the ESP8266 library from 2.4.1 to 2.3 and the memory has been stable ever since. Thank you everyone for your help!

1 Like

Nice find Jason! Thanks!

I appear to be running ESP8266 2.4.0 without any memory leak… Good know about this issue!

@ogiewon & @Ryan780 - Do you guys know if I can carry 1.2 amps over 2-strands of CAT 5E wire (50 ft cable) (12V) for a couple seconds? And then 120mA on standby?

It would be nice if I can tap into my old CCTV cameras as a source of power for my electric drop bolt? And I don’t think the D1 Wemos will have an issue being powered with 12V to 5V (DC-DC converter).

I can upgrade the current 12V power source for the IP camera so that won’t be an issue…just want to make sure if 2-strands of CAT 5E can carry the amps…if not I will see if I can use 4 strands. Worse case…I will need to find an electrician to maybe tap into one of my outdoor light fixtures or use power from my doorbell.

Here is a test I did with a voltmeter…(50 ft wire - slightly better CAT6A) but connections are poor :
Results for a single strand:

Results for two strands:

Not sure how to interpret these results.

I can also run 48 volts and use a 48V to 12V converter to prevent voltage drop…but hopefully the resistants isn’t too high.

24 gauge copper stranded is rated for 360ma only. And btw… It’s called Google. Try it sometime. :grin:

1 Like

Hi,

Sorry if this has been brought up before!

I have a Crazepony-UK 2pcs ESP8266 Module ESP-12E NodeMcu with a PIR sensor connected to D5. The unit works great for about 1 - 2 hrs but then it seems to go offline. I have to turn the power ON/OFF to get it to start reporting back to ST.

I am not an expert and only tried a few things with ST, so any help would really be appreciated.

Regards

Dale

Sounds like you may have found the same bug another user found a day or two ago…

The discussion is just a few post above this one.

HI Thanks for the reply,

looking at the serial monitor it does look the RAM is going down very fast. I only want to use the device as a motion sensor. What is using all the data?

I will have a read through the link you sent.

thanks

Dale

I am not sure where the memory leaks is precisely. It is not in any of the ST_Anything code. It seems to be a problem in the ESP866 Arduino Board package. Try using an earlier version, like 2.3, to see if it resolves the memory leak.

I tried 2.3 and the problem has gone.

thnaks

Dale

1 Like