[DEPRECATED] ST_Anything - Arduino/ESP8266/ESP32

There is no built in web server in ST_Anything.

If you want to adjust the output, you can do so in the child temperature device. Click on the settings gear icon and you can tweak the offset and unit conversion.

If you want to tweak the output more, feel free to edit the Device Handler groovy source code in the ST Classic IDE.

Relatively new I guess yes, so thank you for your responses and help! It really is fantastic!

I get a little confused as online it almost looks as if the DHT22 and AM2320 are the same thing and im struggling to tell the difference! I will take a look a modifying the script thank you.

Hi, first of all thank you so much for all of your hard work on this! Bravo!

I am using a ESP8266 and your “Multiples” sketch to collect temperature from a DS18B20 sensor. (I commented out the pieces I don’t need from the sketch)

I have everything working and I am able to view the recorded temperatures with the SmartThings app. However, I get maybe one or two temperature updates within the first minute and then nothing
no more updates in the app. Within Arduino IDE, I still get temperature updates according to the polling interval inside the serial debugger.

Only way to get an updated reading is to reset power to the ESP8266.

Any ideas?

Thanks in advance,

Gene

Downgrade the ESP8266 board support package to v2.3 in the Arduino IDE. That will probably fix it. Known bug in v2.4/2.4.1.

Thanks Dan,

I just confirmed that I am using firmware version 2.3.0.
I have tried playing with the polling timing to no avail. Also made sure I updated the repo with changes you’ve been making recently.

Are you using the SmartThings Classic mobile app?

I can’t think of a reason that the ESP8266 would continue to operate ‘normally’ while the ST side of things locks up.

Try opening a Live Logging Tab in the ST Classic WEB IDE. It would be very helpful to see if the updates are still coming in on schedule or not. You may just be seeing an issue in the ST Classic Mobile App, where it doesn’t always show updates.

I am using the ST Classic mobile app.

When I opened the live logging in Web IDE, I’m seeing just one instance of the temperature value at initial startup.
When viewing the Arduino IDE serial monitor, I see constant updates of the temperature values based on the logging interval time. (I have mine set for 60 second logging)

I should also mention that the RSSI values for WiFi do update regularly in the Web IDE live logging. I am getting the RSSI updates in the app as well. Just no updates to the temperature.

OK, that helps and it means that the ESP8266 is communicating just fine with ST. So, now let’s take a look at your sketch. Can you post a copy of it here so I can see how you have defined your DS18B20 temperature device?

Another quick test you can run is to click the ‘Refresh’ tile on the Parent Device in the ST Classic App. It should cause all devices to send an update to ST, which should then show up in Live Logging. This will further help to identify what is going on.

Here’s the sketch:

//******************************************************************************************
// 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 as a demo of what is possible with a single NodeMCU ESP8266
// - 1 x Alarm device (using a simple digital output)
// - 1 x Contact Sensor devices (used to monitor magnetic door sensors)
// - 1 x Switch devices (used to turn on a digital output (e.g. LED, relay, etc
)
// - 1 x Motion devices (used to detect motion)
// - 1 x Smoke Detector devices (using simple digital input)
// - 1 x Temperature Measurement devices (Temperature from Dallas Semi 1-Wire DS18B20 device)
// - 1 x Relay Switch devices (used to turn on a digital output for a set number of cycles And On/Off times (e.g.relay, etc
))
// - 2 x Button devices (sends “pushed” if held for less than 1 second, else sends “held”
// - 1 x Water Sensor devices (using the 1 analog input pin to measure voltage from a water detector board)
//
// 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
// 2018-02-09 Dan Ogorchock Added support for Hubitat Elevation Hub
//
//******************************************************************************************
//******************************************************************************************
// 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_DS18B20_Temperature.h> //Implements a Polling Sesnor (PS) to measure Temperature via DS18B20 libraries
//#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 //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

//******************************************************************************************
//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_ALARM_1 D0 //SmartThings Capabilty “Alarm”
//#define PIN_SWITCH_1 D1 //SmartThings Capability “Switch”
//#define PIN_CONTACT_1 D2 //SmartThings Capabilty “Contact Sensor”
//#define PIN_BUTTON_1 D3 //SmartThings Capabilty Button / Holdable Button (Normally Open!)
//#define PIN_BUTTON_2 D4 //SmartThings Capabilty Button / Holdable Button (Normally Open!)
//#define PIN_MOTION_1 D5 //SmartThings Capabilty “Motion Sensor” (HC-SR501 PIR Sensor)
//#define PIN_SMOKE_1 D6 //SmartThings Capabilty “Smoke Detector”
#define PIN_TEMPERATURE_1 D7 //SmartThings Capabilty “Temperature Measurement” (Dallas Semiconductor DS18B20)
//#define PIN_TIMEDRELAY_1 D8 //SmartThings Capability “Relay Switch”

//******************************************************************************************
//ESP8266 WiFi Information
//******************************************************************************************
String str_ssid = “XXXXX”; // <—You must edit this line!
String str_password = “XXXXX”; // <—You must edit this line!
IPAddress ip(192, 168, 1, 228); //Device IP Address // <—You must edit this line!
IPAddress gateway(192, 168, 1, 2); //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, 2); //DNS server // <—You must edit this line!
const unsigned int serverPort = 8090; // port to run the http server on

// Smartthings / Hubitat Hub TCP/IP Address
IPAddress hubIp(192, 168, 1, 127); // smartthings/hubitat hub ip // <—You must edit this line!

// SmartThings / Hubitat Hub TCP/IP Address: UNCOMMENT line that corresponds to your hub, COMMENT the other
const unsigned int hubPort = 39500; // smartthings hub port
//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
//static st::PS_Water sensor1(F(“water1”), 60, 20, PIN_WATER_1, 200);
static st::PS_DS18B20_Temperature sensor1(F(“temperature1”),60,5, PIN_TEMPERATURE_1, false, 10, 3);

//Interrupt Sensors
//static st::IS_Contact sensor3(F(“contact1”), PIN_CONTACT_1, LOW, true);
//static st::IS_Button sensor4(F(“button1”), PIN_BUTTON_1, 1000, LOW, true, 500);
//static st::IS_Button sensor5(F(“button2”), PIN_BUTTON_2, 1000, LOW, true, 500);
//static st::IS_Motion sensor6(F(“motion1”), PIN_MOTION_1, HIGH, false);
//static st::IS_Smoke sensor7(F(“smoke1”), PIN_SMOKE_1, HIGH, true, 500);

//Special sensors/executors (uses portions of both polling and executor classes)
//static st::S_TimedRelay sensor8(F(“relaySwitch1”), PIN_TIMEDRELAY_1, LOW, false, 3000, 0, 1);

//Executors
//static st::EX_Alarm executor1(F(“alarm1”), PIN_ALARM_1, LOW, true);
//static st::EX_Switch executor2(F(“switch1”), PIN_SWITCH_1, LOW, true); //Inverted logic for “Active Low” 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);

//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);
//st::Everything::addSensor(&sensor6);
//st::Everything::addSensor(&sensor7);
//st::Everything::addSensor(&sensor8);

//*****************************************************************************
//Add each executor to the “Everything” Class
//*****************************************************************************
//st::Everything::addExecutor(&executor1);
//st::Everything::addExecutor(&executor2);

//*****************************************************************************
//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();
}

How many DS18B20 sensors are attached to ‘PIN_TEMPERATURE_1’?

You are currently attempting to read from ‘3’ sensors based on the following definition

static st::PS_DS18B20_Temperature sensor1(F(“temperature1”),60,5, PIN_TEMPERATURE_1, false, 10, 3);

If you only have one sensor attached, change the line to be

static st::PS_DS18B20_Temperature sensor1(F(“temperature1”),60,5, PIN_TEMPERATURE_1, false, 10, 1);

Here is the documentation for the DS18B20 class (every device’s .h and .cpp has a similar comment section at the top to explain how to properly use it.)

//******************************************************************************************
//  File: PS_18B20_Temperature.h
//  Author: Dan G Ogorchock
//
//  Summary:  PS_DS18B20_Temperature is a class which implements both the SmartThings "Temperature Measurement" capability.
//			  It inherits from the st::PollingSensor class.  The current version uses a digital pin to measure the 
//			  temperature from a Dallas Semiconductor One Wire DS18B20 series sensor. 
//
//			  Create an instance of this class in your sketch's global variable section
//			  For Example:  st::PS_DS18B20_Temperature sensor1("temperature1", 120, 0, PIN_TEMPERATURE, false);
//
//			  st::PS_DS18B20_Temperature() constructor requires the following arguments
//				- String &name - REQUIRED - the name of the object - must match the Groovy ST_Anything DeviceType tile name
//				- long interval - REQUIRED - the polling interval in seconds
//				- long offset - REQUIRED - the polling interval offset in seconds - used to prevent all polling sensors from executing at the same time
//				- byte pin - REQUIRED - the Arduino Pin to be used for the One-Wire DS18B20 sensor conenction
//				- bool In_C - OPTIONAL - true = Report Celsius, false = Report Farenheit (Farentheit is the default)
//				- byte resolution - OPTIONAL - DS18B20 sensor resolution in bits.  9, 10, 11, or 12.  Defaults to 10 for decent accuracy and performance
//				- byte num_sensors - OPTIONAL - number of OneWire DS18B20 sensors attached to OneWire bus - Defaults to 1

Also, do you have the required 4.7Kohm resistor wired into the circuit?

Example wiring (pin not the same as your sketch, just showing where the 4.7K resistor goes.)

Yes, I have three sensors. I also tried with just one sensor initially to get started and got the same results. I am using a 4.7KOhm resistor too.

I started off with just getting everything working in Arduino IDE first. Once I was getting temperature updates from all three sensors, I moved on to ST_Anything. If you are wondering, I am replacing my pool control system with my own design based on all of your sketches, libraries, and device handlers.

Since you’re using three sensors, try changing the sketch as follows:

static st::PS_DS18B20_Temperature sensor1(F(“temperature”),60,5, PIN_TEMPERATURE_1, false, 10, 3);

note: The name “temperature1” has been changed to simply “temperature” as the code automagically appends the sensor number to it when sending updates. I wonder if the code only handles a single digit for the numeric suffix?

I made the code change and I get the same results. Here’s the output of the Smart Things IDE Live Logging. Now I am noticing that the RSSI values are no longer updating in the app or on the live logging.

I am going to try a different ESP8266 to see if there is a problem with hardware. Is it possible the CPU is locking up?

I suppose it is possible that it is locking up
 These little boards need a decent power supply as the WiFi transmissions need some juice.

Try setting the temperature polling interval to 15 seconds, instead of the 60 it is currently at. I am curious if you’ll get a few values before things go bad.

Does pressing Refresh on the Parent Device result in any live logging or ST IDE Serial Monitor window output?

I installed on a different ESP8266 and get basically the same results. I changed the polling to 15 seconds. I did get updates every 15 seconds for about three (3) minutes before everything stops
no more RSSI either. The Arduino IDE monitor is still going strong with updates.

Pressing “refresh” in the app gives the following results in live logging:

The problem you’re experiencing seems to be related to the issue with the new ESP8266 Arduino IDE Board Support package. Are you sure you’re using v2.3 of it?

It is weird that it works fine for a few minutes and then suddenly stops. The v2.4/v2.4.1 ESP8266 support for Arduino IDE has a memory leak in it, that causes things to lock up.

If that isn’t the issue, I am not sure what it could be. Here are a few more ideas of things to check


  • I do recall some folks warning that there may be a little to the number of LAN connected devices a ST Hub can support. Is this the only LAN connected device? If not, how many do you have?
  • Can you still ping the ESP8266 once updates stop being received by ST?
  • What model of the ST Hub are you using? I have only tested ST_Anything with the v1 and v2 hubs.
  • What are the freeRam values over time in the Arduino IDE’s Serial Monitor window? Do you see it reducing steadily over time, or does it stabilize quickly?

One more question
 After pressing Refresh, what do you see in the Arduino IDE Serial Monitor window, if anything?

I’m having similar issue.
After pressing Refresh there is no response in the Arduino IDE Serial Monitor window.

@Ehartmann, @TEvgeny

Not sure what to tell you. I set up a NodeMCU v1.0 MCU, running all of the latest code from my GitHub repository and running the ST_Anything_Multiples_ESP8266WiFi.ino sketch. This was started at 8pm tonight and has been running for about 4 hours without missing a beat. Everything is still responsive on both the ESP8266 and ST sides.

[UPDATE: Still running fine after ~6 hours)

@ogiewon, thank you.

Not sure yet, but I think this is related to WiFi connection - sometimes device looses it and reconnects.
I saw reconnects issues after I enabled debug mode in SmartThingsESP8266WiFi constructor.
And, also, debug mode fixed my issues.
Device run overnight and all works as expected.

1 Like