[DEPRECATED] ST_Anything - Arduino/ESP8266/ESP32

@ogiewon It is running but not updating, I have proper power, ground, and data connections and the board is getting plenty of power without overloading it. I am not getting updated temp or humidity from any of the three sensors. I have included the sketch to see if you see where I may have made my mistake: (Redacted network data)

//******************************************************************************************
// 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_TEMPERATUREHUMIDITY_1 D1 //SmartThings Capabilities “Temperature Measurement” and “Relative Humidity Measurement”
#define PIN_TEMPERATUREHUMIDITY_2 D2 //SmartThings Capabilities “Temperature Measurement” and “Relative Humidity Measurement”
#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_TEMPERATUREHUMIDITY_3 D5 //SmartThings Capabilities “Temperature Measurement” and “Relative Humidity Measurement”
#define PIN_MOTION_1 D7 //SmartThings Capabilty “Motion Sensor” (HC-SR501 PIR Sensor)
#define PIN_SMOKE_1 D6 //SmartThings Capabilty “Smoke Detector”
//#define PIN_TEMPERATUREHUMIDITY_1 D5 //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(XXXXX); //Device IP Address // <—You must edit this line!
IPAddress gateway(XXXXX); //Router gateway // <—You must edit this line!
IPAddress subnet(XXXXX); //LAN subnet mask // <—You must edit this line!
IPAddress dnsserver(XXXXX); //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 hubIpXXXX); // 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_TemperatureHumidity sensor1(F(“temphumid1”), 60, 0, PIN_TEMPERATUREHUMIDITY_1, st::PS_TemperatureHumidity::DHT22,“temperature1”,“humidity1”);
static st::PS_TemperatureHumidity sensor2(F(“temphumid2”), 60, 10, PIN_TEMPERATUREHUMIDITY_2, st::PS_TemperatureHumidity::DHT22,“temperature2”,“humidity2”);
static st::PS_TemperatureHumidity sensor3(F(“temphumid3”), 60, 20, PIN_TEMPERATUREHUMIDITY_3, st::PS_TemperatureHumidity::DHT22,“temperature3”,“humidity3”);

//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);

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

yeah that is what i thought

just making sure since it is not officially listed as a supported board but searching
this thread i seen some people using them successfully.

i have done that my HC-SR501 is connected to my wemos d1 mini
GND, 5V ,and D5 pins ,i used a test sketch and it is working just fine
as i can see in the serial monitor ,i am not getting any false positives
as some other people were reporting with this sensor using the 5v pin on node MCU boards , (some people were suggesting powering with 3.3v from the node MCU to one of the jumper pins)

ok so if i pick an address outside of the router DHCP range it will assign that address automatically to the boards mac when it connects and then i just set it to static
or it could assign a different IP and then i just change it to the one i put in the sketch and then set it to static

but what do i put for DNS server ? is this an optional field ,if it is then do i just delete the example IP that is in there or the whole line ? or leave it as is?

also i do t use hubitat should i delete the whole line or just the example IP or just leave it alone?

what do i do after i get the sketch to successfully compiled to add the device/s into ST?

i am pretty new to ST the only other project i did was with the smartlife h801 controller and flashing them to work with ST
i had to setup the wifi credentials in the controller manually because the smart app wouldn’t do it automatically for me but there was no filed for DNS server and i know that controller also uses an esp8266 so i am not sure about what this extra credential is even for ,i assume it is optional if you want to use a DNS server but i don’t so then what should i put there, how should i edit the line? or should i just delete it or just dele the example IP and leave it blank?
my lixada h801’s flashed with the smartlife.ino are esp8266 based and require no such credential to work so i have no clue what this is even for or what exactly it is asking for , please clarify this

in my router under advanced settings , wan settings i see DNS server and it is set to connect to DNS server automatically , YES
if set that to NO i see 2 additional fields for DNS server 1 and DNS server 2 and both are blank

i have limited experience with arduino but i know enough i just never worked with the wifi boards before

The ESP8266 board will set its own IP address, based on what you enter in the sketch. Your router will not be involved except as a wireless access point.

DNS ip address should be the LAN address of your router. Usually this is also the GATEWAY address.

If you’re on a Windows PC, bring up a command prompt and type “ipconfig/all” and review the returned results. You should see the DNS, GATEWAY, and SUBNET MASK fields that are used for your home network (assuming your PC is connected to your home network, of course! :slight_smile: ) You can simply copy these values into the sketch.

Just comment out the two Hubitat Hub lines of code AND uncomment the two lines of code for SmartThings. Make sure you enter in the IP address of your SmartThings hub (which should have a reserved IP address in your router’s DHCP server settings.)

// Smarthings Hub Information
IPAddress hubIp(192, 168, 1, 149);  // 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

Hi, I got a project going.
I got a mini scale of my house, and I want all light inside my mini house to behave as my Real lights.

I got 1 idea, I can use 1x Sonoff SV for each light.
But then I need 10-15x sonoff SV with wires for each LED light inside the tiny house.

My other question is: can I make my arduino D1 with 10x Output with 10 different LED, turn ON/Off using ST?

Inside CoRE i need to see my arduino as 1 Thing with 10x switches. Like 01, 02, 03, and so on.

So when My TV is On, arduino output 01 is turned ON also?? That would be totally awesome if possible.

If not, back to basic with soldering 10 sonoff relays.

Thanks for helping.

Short story : building a 3D model of house with LED lamp controlled with arduino from SmartThing.

Yes. You can easily control multiple ‘switch’ devices from a single microcontroller using ST_Anything. What specific microcontroller do you plan on using? Model number, please. That will help determine a starting point with ST_Anything. (note: Arduino never made a ‘D1’ board that I am aware of, this the question for more details.)

For example, with an Arduino MEGA 2560 + W5100 Ethernet Shield, you could control ~50 LEDs independently from SmartThings using ST_Anything. This would require a hardwired Cat5 network connection.

With a NodeMCU ESP8266 board, you could potentially control ~7 LEDs via ST using a WiFi connection.

You could also use a NodeMCU ESP32 or an Arduino MKR 1010 board for higher GPIO count applications. Both of these also support WiFi natively.

Thank you for answer so fast :slight_smile:

To be more specific, I got a Wemos D1 R1 (look like Arduino Uno, but with ESP8266 included)

So the Wemos D1 is WiFi.
But if the Wemos D1 is not supported, I got many NodeMcu V3 Lua ESP12E ESP8266 CH340.

I will need to check out the tutorial, and get started to install this in my ST.

1 Like

Ok i did that but it just says “DNS serverS” and they are nothing like the default gateway of my router.
My routers default gateway is 192.168.50.1

the same as it says for DHCP server
but under “DNS servers” says 75.75.75.75
and 75.75.76.76

so i am not sure if i should put in the 75.75.75.75 or 192.168.50.1

You should be able to use the Wemos D1, as it simply uses an ESP8266. Just start with the ST_Anything_Multiples_ESP8266WiFi.ino sketch, and tweak it to only have a bunch of EX_Switch devices. The pin number/mapping in the example sketch is for a NodeMCU ESP8266 board, so you may need to tweak that a bit. Be sure to select the Wemos D1 in the Arduino Boards Manager.

What type of ISP connection do you have? What type of router?

Can you please copy and paste the output of the “ipconfig/all” command here? I am not understanding what you’re saying above.

Should I not be using Arduino 1.8.9 ?

Nevermind
 I notice you have not tested 1.8.9.

I will try to downgrade to 1.8.8 before testing

I believe Arduino IDE v1.8.9 with ESP8266 v2.5.2 is stable. I have been testing it this week in the lab and everything seems stable after a few days.

1 Like

i have comcast 250gb cable
and my router is an Asus RT-AC66U_B1
that i am soon replacing with a an RT AC5300

From teh Asus RT-AC66U_B1 web admin screens, can you please copy and paste the LAN network settings, as well as the DHCP server settings page(s) here as well?

I have Asus routers as well, and I have never seen the Asus DHCP server pass the ISP’s DNS server addresses to the client. Typically it passes the LAN IP address of the router itself. Of course, I am running AsusWRT Merlin firmware on my RT-AC86u.

So, based on what I see above, I would use the following:

IP address: 192.168.50.x (need to still figure this one out based on the DHCP server range)
Subnet Mask: 255.255.255.0
Gateway: 192.168.50.1
DNS: 192.168.50.1

Ok, you’re going to need to reduce the size of the DHCP pool slightly to accommodate true static IP addresses. I would change the “IP Pool Ending Address” to 192.168.50.200. This will free up some IP address from 192.168.50.201 to .250 for whatever you’d like to use them for. Just be aware that making this change could impact some existing DHCP leases for currently active devices.

Your other option is to create a DHCP Reservation for the microcontroller board. Within the example sketches you can actually use DHCP instead of a static IP address assignment. However, it is very important that the IP address of the ST Hub and the microcontroller never change (thus the DHCP reservations in the router based on MAC address.)

To use DHCP with ST_Anything, you would modify the sketch as follows:

//******************************************************************************************
//  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     = "yourSSIDhere";                           //  <---You must edit this line!
String str_password = "yourWiFiPasswordhere";                   //  <---You must edit this line!
//IPAddress ip(192, 168, 1, 227);       //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

// Smarthings Hub Information
IPAddress hubIp(192, 168, 1, 149);  // 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
  static st::PS_Water               sensor1(F("water1"), 60, 20, PIN_WATER_1, 200);
  static st::PS_DS18B20_Temperature sensor2(F("temperature1"), 15, 0, PIN_TEMPERATURE_1, false, 10, 1); 
  
  //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 provide/reserve 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();
}

OK, I think I`m up and running :slight_smile:

Inside my ST app i got this:

RSSI - 69
Alarm
Contact
motion


temperature -196,9

And temperature is the same as my Serial Monitor is showing me (no temp sensor on this board I guess) , but the same number indicate it does work ?

So my next step now, is to make the PINout on my board to turn ON\OFF LEDs.

Do I change my Arduino code for that then (but keep the IP adress etc
) ?
(there are so many example, is each example for everytime I add another arduino board yes?)

ok now i am even more confused i don’t even know why that credential is there to begin with i never set up any such credential for my smartlife sketch on my lixada H801’s
those run on esp8266 and they communicate with ST fine without this why is it even needed at all?

i can’t narrow the DHCP pool because i have a lot of those H801 controllers and other devices that are using static IP’s in the 250’s
i was going to enter192.168.256 since the ending IP in the pool ends in .254

but i still don’t know what i am supposed to put for the DNS server value

my router is a very common router and it is using default settings i don’t understand why this is an issue

EDIT: ok i tried that and it will not compile
i get

Using library Adafruit_Sensor-master at version 1.0.3 in folder: C:\Program Files (x86)\Arduino\libraries\Adafruit_Sensor-master
exit status 1
Error compiling for board WeMos D1 R1

i copied ALL the libraries from the github repo to my arduino libraries folder ,i just downloaded the repo like 3 days ago, there must be missing libraries or maybe the sketch is calling for an older or newer version?

EDIT:
i tried removing the adafruit sensor-master folder from my libaries folder temporarily

and now i get this error
Using library Adafruit_Unified_Sensor at version 1.0.2 in folder: C:\Program Files (x86)\Arduino\libraries\Adafruit_Unified_Sensor
exit status 1
Error compiling for board WeMos D1 R1.

i thought maybe that the adafruit sensor master library that i probably added myself a few months ago was conflicting with the adafruit unified sensor library but it still does not compile
after removing it

what is the problem here? the repo is missing libraries or the repo has out of date libraries maybe?

i am using arduino version 1.8.8 and v2.4.2 of the Arduino ESP8266 Board manager

my board is selected as wemos D1 R1 , there is no option for D1 mini in the list though
my other sketch to test the PIR worked flawlessly with this board setting

EDIT: i tried it again with a different board selected (LOLIN(WEMOS) D1 R2 & mini.) and i still get an error about the sensor library
Using library Adafruit_Unified_Sensor at version 1.0.2 in folder: C:\Program Files (x86)\Arduino\libraries\Adafruit_Unified_Sensor
exit status 1
Error compiling for board LOLIN(WEMOS) D1 R2 & mini.

EDIT: i tried both the sketch you posted here and the esp8266 multiples sketch directly from the sketch book i get the same error every time at unified sensor library

i tried to delete and replace the unified sensor library folder in my arduino libraries folder with one from the repo again and it still doesn’t work

need some help, my device is showing Contact OPEN \ CLOSE

So my ESP in online.

But inside ST it will not TURN ON switch, it only says “TURNING ON
” but never actually turns it ON or OFF.

any ideas ?

I have tested many different Arduino codes, and they do appear in my ST just fine.
But my ST app will simply not turn ON any switch, it try for some time and then give up (like a device is disconnected to the system) , but I am able to read temperature and contact status from my ESP.

Here is my LIVE LOG:

0af9448b-c462-4e97-a983-e7c8475f3ca5 12:47:17 AM: debug Executing ‘sendEthernet’ switch1 off

0af9448b-c462-4e97-a983-e7c8475f3ca5 12:47:17 AM: debug Using ip: 192.168. 1.133 and port: 8090 for device: 0af9448b-c462-4e97-a983-e7c8475f3ca5

0af9448b-c462-4e97-a983-e7c8475f3ca5 12:47:17 AM: debug Executing ‘sendEthernet’ switch1 on

0af9448b-c462-4e97-a983-e7c8475f3ca5 12:47:17 AM: debug Using ip: 192.168. 1.133 and port: 8090 for device: 0af9448b-c462-4e97-a983-e7c8475f3ca5

0af9448b-c462-4e97-a983-e7c8475f3ca5 12:47:17 AM: debug Executing ‘sendEthernet’ switch1 on

0af9448b-c462-4e97-a983-e7c8475f3ca5 12:47:11 AM: debug Using ip: 192.168. 1.133 and port: 8090 for device: 0af9448b-c462-4e97-a983-e7c8475f3ca5

Hi - This is a great little system - I got it up & running reading a couple of test DS18B20s without any major issues.
The query I have is a weird one - I have a number of DS18B20s buried in inaccessible locations (the ground). I know the IDs of each and their location.
Is there a way for me to identify which is which? I was thinking that I might be able to mod the code to return the ID along with the temperature (this would require it being possible, and my coding skills being up to it, which is the more likely issue).
Otherwise the workaround I guess is to hope they all read slightly different stable temperatures, then hook them up one by one first, note the temperatures, then hook them up together & correlate the temps to work out the locations.

Any suggestions are welcome!

Cheers, James

1 Like