[DEPRECATED] ST_Anything - Arduino/ESP8266/ESP32

Gabriel,

So, I just took your last sketch you posted above, compiled it and loaded it on a NodeMCU ESP8266-12e board without any errors.

Does the problem only manifest itself if you use GPIO 10?

I am happy to try to help test things from here. I just need to know what are the test scenarios you’d like me to test?

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

//******************************************************************************************
//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_TIMEDRELAY_1          D2  //SmartThings Capability "Relay Switch"
#define PIN_TIMEDRELAY_2          10  //SmartThings Capability "Relay Switch"
#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_CONTACT_1             D8  //SmartThings Capabilty "Contact Sensor"

//******************************************************************************************
//ESP8266 WiFi Information
//******************************************************************************************
String str_ssid     = "Wifi";                           //  <---You must edit this line!
String str_password = "password";                   //  <---You must edit this line!
IPAddress ip(192, 168, 1, 110);       //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, 2);    // smartthings hub ip     //  <---You must edit this line!
const unsigned int hubPort = 39500;   // smartthings hub port

//******************************************************************************************
//st::Everything::callOnMsgSend() optional callback routine.  This is a sniffer to monitor 
//    data being sent to ST.  This allows a user to act on data changes locally within the 
//    Arduino sktech.
//******************************************************************************************
void callback(const String &msg)
{
//  Serial.print(F("ST_Anything Callback: Sniffed data = "));
//  Serial.println(msg);
  
  //TODO:  Add local logic here to take action when a device's value/state is changed
  
  //Masquerade as the ThingShield to send data to the Arduino, as if from the ST Cloud (uncomment and edit following line)
  //st::receiveSmartString("Put your command here!");  //use same strings that the Device Handler would send
}

//******************************************************************************************
//Arduino Setup() routine
//******************************************************************************************
void setup()
{
  //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, 1000, 0, 1);
  static st::S_TimedRelay           sensor9(F("relaySwitch2"), PIN_TIMEDRELAY_2, LOW, false, 1000, 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, false);  //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);
  st::Everything::addSensor(&sensor9);
      
  //*****************************************************************************
  //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();
}

@gferrari

Gabriel,

I took one of your other sketches which uses 2 timedRelays and maps one of them to GPIO10. Below is the Serial Monitor output which looks perfectly normal to me. I have also pasted the sketch I used below (only changes are to the WiFi parameters section.

Everything: init started
Everything: Free RAM = 45600

Initializing ESP8266 WiFi network.  Please be patient...
Attempting to connect to WPA SSID: yourSSIDhere
..

Enter the following three lines of data into ST App on your phone!
localIP = 192.168.1.235
serverPort = 8090
MAC Address = 5C:CF:7F:3D:B3:2E

SSID = yourSSIDhere
PASSWORD = yourWiFiPasswordhere
hubIP = 192.168.1.149
hubPort = 39500

SmartThingsESP8266WiFI: Intialized

Disabling ESP8266 WiFi Access Point

Everything: init ended
Everything: Free RAM = 45368
Everything: adding sensor named water1
Everything: Free RAM = 45368
Everything: adding sensor named temperature1
Everything: Free RAM = 45368
Everything: adding sensor named contact1
Everything: Free RAM = 45368
Everything: adding sensor named button1
Everything: Free RAM = 45368
Everything: adding sensor named button2
Everything: Free RAM = 45368
Everything: adding sensor named motion1
Everything: Free RAM = 45368
Everything: adding sensor named smoke1
Everything: Free RAM = 45368
Everything: adding sensor named relaySwitch1
Everything: Free RAM = 45368
Everything: adding sensor named relaySwitch2
Everything: Free RAM = 45368
Everything: adding executor named alarm1
Everything: Free RAM = 45368
Everything: adding executor named switch1
Everything: Free RAM = 45368
Everything: initDevices started
Everything: Free RAM = 45368
PS_Water::Analog Pin value is 4 vs limit of 200
Everything: Sending: water1 dry
PS_DS18B20_Temperature::Requesting temperatures...DONE
PS_DS18B20_Temperature:: Temperature for the device # 1 is: -196.60
Everything: Sending: temperature1 -196.60
Everything: Sending: contact1 closed
IS_Motion: 30 second Motion Sensor Calibration Started...
Everything: Sending: relaySwitch1 off
Everything: Sending: relaySwitch2 off
Everything: Sending: alarm1 off
Everything: Sending: switch1 off
Everything: initDevices ended
Everything: Free RAM = 45344
Everything: Sending: smoke1 clear
PS_DS18B20_Temperature::Requesting temperatures...DONE
PS_DS18B20_Temperature:: Temperature for the device # 1 is: -196.60
Everything: Sending: temperature1 -196.60
IS_Motion: Motion Sensor Calibration Finished
Everything: Sending: motion1 active

Sketch

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

//******************************************************************************************
//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_TIMEDRELAY_1          D2  //SmartThings Capability "Relay Switch"
#define PIN_TIMEDRELAY_2          10  //SmartThings Capability "Relay Switch"
#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_CONTACT_1             D8  //SmartThings Capabilty "Contact Sensor"

//******************************************************************************************
//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, 235);       //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, 149);    // smartthings hub ip     //  <---You must edit this line!
const unsigned int hubPort = 39500;   // smartthings hub port

//******************************************************************************************
//st::Everything::callOnMsgSend() optional callback routine.  This is a sniffer to monitor 
//    data being sent to ST.  This allows a user to act on data changes locally within the 
//    Arduino sktech.
//******************************************************************************************
void callback(const String &msg)
{
//  Serial.print(F("ST_Anything Callback: Sniffed data = "));
//  Serial.println(msg);
  
  //TODO:  Add local logic here to take action when a device's value/state is changed
  
  //Masquerade as the ThingShield to send data to the Arduino, as if from the ST Cloud (uncomment and edit following line)
  //st::receiveSmartString("Put your command here!");  //use same strings that the Device Handler would send
}

//******************************************************************************************
//Arduino Setup() routine
//******************************************************************************************
void setup()
{
  //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, 1000, 0, 1);
  static st::S_TimedRelay           sensor9(F("relaySwitch2"), PIN_TIMEDRELAY_2, LOW, false, 1000, 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, false);  //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);
  st::Everything::addSensor(&sensor9);
      
  //*****************************************************************************
  //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();
}

@ogiewon

Checking in here - I have made several steps in the right direction thanks to your fantastic documentation but I’m somewhat at a loss for what I still need to do to get this working.

Currently I have the NodeMCU chip you recommended successfully reading color temperature and illuminance from the Adafruit sensor and just outputting the values into Serial Monitor - very exciting! So, from a hardware perspective I should be good.

I wrote a new groovy child device handler to display both the illuminance and color temperature in smart things - I added it to my device handlers. You can check out the code here: Child Color Temperature & Illuminance Sensor · GitHub I manually added this into the My Device Handlers section - will this work?

ST_Anything is where I’m stuck now. There is a lot in there I know I can comment out, but I’m just not sure which files I need to edit to get it passing the colorTemperature and illuminance values. I’d really appreciate some additional guidance here!

In case it’s relevant - the Adafruit sensor uses SDA/SCL to pass over all the values. Here is a sample line of everything being passed into the serial monitor:

Color Temp: 3423 K - Lux: 114 - R: 276 G: 206 B: 165 C: 580

Color Temp and Lux are all I care about passing to ST. Thank you in advance!

edit: One of the current questions I have is how to define the pins properly since my understanding of this sensor it that it is returning multiple values on the same pin(s)? My understanding of the code is that the example pins assume each sensor value is being passed through separate pins:

//#define PIN_ALARM_1 D0 //SmartThings Capabilty “Alarm”
//#define PIN_SWITCH_1 D1 //SmartThings Capability “Switch”

Based on this my instinct would be that I need to create something like PIN_COLORTEMP_ILLUMINANCE_1 or something but I am not confident that is the right approach.

Todd,
Looks like you’re off to a good start. Congrats!

Probably best to take small steps from this point forward, adding a little at a time until you get a feel for the entire architecture.

ST_Anything is simply an Arduino Library, which does three main things:

  1. It takes care of the SmartThings communications (it actually uses another library called SmartThings for this)
  2. It monitors and updates “devices” bidirectionally between the real world physical devices and SmartThings. It handles three distinct types of devices:
    a) Polling Sensors (PS) - devices whose pins are read on a repeating schedule, like once every 30 seconds. Temperature, Illuminance, Humidity, etc… These are typically analog inputs or sensors who have a continuous stream of numeric data (not just a 1 or 0 state.) We don’t want to bombard ST with updates for these devices so we only check them on a time-based schedule.
    b) Interrupts Sensors (IS) - devices whose pins are read continuously looking for a state change. Contact Sensors, Carbon Monoxide, Smoke Detectors, etc. These are typically digital inputs. We want to update ST as soon as a change is detected, however by the nature of these devices, updates are not all that frequent.
    c) Executors (EX) - These are typically outputs, like a relay connected to a digital outputs. These devices wait for a signal from SmartThings before changing state.

So, in your case, you want to create a new Polling Sensor class, since you want to sample illuminance and color temperature. You should start by looking at the PS_Illuminace.h and .cpp files in the …Arduino\libraries\ST_Anything library folder on you computer. This would be a very good starting point for your project. To keep things nice and neat, I would create a new library folder called:

…\Arduino\libraries\ST_Anything_AdafruitTCS34725_Illum_Color

In this folder, create two files named:

PS_AdafruitTCS34725_Illum_Color.h (copy of PS_Illuminance.h)
PS_AdafruitTCS34725_Illum_Color.cpp (copy of PC_Illuminance.cpp)

These are the only two files you will need to add/modify to ST_Anything in order to support your new Polling Sensor Device.

Inside these 2 files, you will need to rename everything from “PS_Illuminance” to “PS_AdafruitTCS34725_Illum_Color” to avoid any conflicts with the original PS_Illuminance C++ class.

Once you have done this, it is simply a matter of modifying this new C++ class to be able to interface with the “TCS34725” instead of the simple analog input that it currently uses. Use code from your TCS34725 example sketch to replace the analogRead code in the getData() . You’ll need to #include the correct Adafruit libraries in PS_AdafruitTCS34725_Illum_Color.h, make the correct calls etc… Things you would normally do in the setup() portion of your sketch should probably be handled in the init() routine of your new class. Things from your sample’s loop() function will go in your new getData() function. Etc…

As I typed these instructions, I decided to give you a head start by creating the shell of what you need to get going. Send me a PM with your email address and I’ll send you a zip file with starting files that will help you get started and heading down the correct path.

I think it is best to begin with just Illuminace to make sure everything works as desired. Since I already have a Child Device for Illuminace, it will be auto created and populated with data from your new class. This is just to get the Arduino code working correctly. Later, you’ll want to figure out how to send all of the data in a single message or a pair of messages (one for illuminace and one for color temp) to your Child Device handler. This will also require changes to the Parent Device Handler to recognize your new Child Device and auto create it.

3 Likes

Dan,

Thanks for trying the code with the 2 timedrelay. I dont think I have problems with GPIO10 since if I put a switch instead of a timedrelay, the program flashed and work as expected. However, when I flash the sketch with 2 timedrelay (D2 & 10), after it install without any errors, i get into an infinite loop of resets in the serial window. I was reading around other forums and I think it has to do with the “watch dog timer time-out” (link below).

https://internetofhomethings.com/homethings/?p=396

I think my problem is that I am using a bare bones ESP8266-12E and not a NodeMCU. I added all the pull-up/pull-down resistor, reset and flash switches. However, I am missing some capacitors per the link above. So, I am going to get some to add to my circuit and see if that gets rid of the infinite loop after install. I’ll keep you posted.

On a side note, GPIO10 seems reliable to me to use with your code, so thats another input/output people can use if they need it. I haven’t been so successful with pin 9 (GPIO9/SD2) as it always goes into the infinite loop. I will try once I get the capacitors.

1 Like

Sure, that’s pretty easy. Just go into the Child Device Handler and change the Off() routine to look just like the On() routine. That way when you tell Alexa to turn it off, it will execute the same code as On.

Dan - this looks awesome. I ordered my ESP-32 today and can’t wait to try it. I had no luck using ESP-01 as a wifi shield so I hope this is better as a standalone solution. If I only need 1 port I assume I can still make use of my 10-pack of ESP-01 boards? Otherwise I can make my wife some nerdy jewelry with them … LOL.

Ken,

Yes, the ESP01’s can be used as standalone devices running a local copy of ST_Anything. You actually get 2 GPIOs to use in that configuration.

The ESP32 support was actually added by another community member, for which I am extremely grateful.

I did just determine that my ESP32 does not automatically reconnect to WiFi if I reset my wireless access point. The ESP8266 series of modules (-01 and -12e tested) did auto-reconnect to WiFi. Not sure where the issue is, or if it is just the immaturity of the ESP32 firmware or Arduino IDE support.

I hope to find some time in the near future to try and sort it out. If anyone wants to help, that would be great too!

Dan

@kewashi @black-paladin @vseven

All,

I have just uploaded a new version of the SmartThingsESP32WiFi library to GitHub. This new version should trap the WiFi disconnect event and automagically attempt to reconnect. I have tested it successfully over the last hour by changing my router SSID, watching the ESP32 complain in the Serial Monitor window, then changing the SSID in the router back, and watching the ESP32 reconnect successfully.

Please download and try these updates with your ESP32 projects.

Dan

3 Likes

nudge (points at pull requests I entered) nudge

I’m actually really interested in doing what @Todd_Meyer is doing especially since my ESP32 is mounted in my garage on a outside wall…it would be easy to get the outdoor light conditions. My wife works from home in the basement and although we have a couple windows I’m sure having something more “natural” to whats outside would help.

If you guys (Todd / Dan) haven’t played with this much I’ll take a stab at it this weekend or early next week. I can already envision a child device with all 5 stats on it and how to send the data.

Will push it tonight and test.

-Allan

1 Like

Ok, I can confirm I had the same issue (no auto-reconnect) and also that the new version reconnects automatically now for me too.

1 Like

Hi All…

It’s me again… like a broken record …( Old School )

If anyone has an Arduino ThingShield available for sale, please let me know
still looking for a couple units.

Thanks

Ben

Think I got this figured out. I don’t have the sensor yet (get it Saturday) but I believe I got the child device and programming done. It’s not pretty but it seems to work. From what I can tell the sensor library is sending the max values for RGB and C when it doesn’t read so the numbers look inflated but again it works:

@ogiewon - only way I could get this to work easily was using the updated code to pass from parent to child (generateEvent in the pull requests). I’m pushing a big string of all the values with a colon in between then using a split command to split them back apart in the child and assign them to the tiles. Once I get the sensor and can verify it works correctly I’ll throw it in your github to look at and possibly include.

@Todd_Meyer - I can send you my code if you wanna try it.

-Allan

2 Likes

The readme file only talks about standalone ESP-32 and ESP-8266 boards. Will plow ahead but if I get stuck I might need some advice.

UPDATE: I found your ESP01WiFi example and I see that it just uses the same library as ESP8266 so I think I am good. Just need to wire it up now and give it a whirl. I assume I will have to use the 5V to 3.3V conversion chip. Also, how does one go about connecting this ESP01 board to their computer as a standalone? Do I have to hack a USB cord and tie it into the Send/Receive and 3.3V lines? There must be an easier way?

UPDATE 2: This file seems to provide a decent tutorial that looks like it might work. Although I must admit that I was hoping it was easier.
http://codeclub.cornwall.ac.uk/edenofthings/files/ESP-01FactSheet.pdf

1 Like

Thanks will take a look at it . Ordered one and waiting for it to arrive.

I am trying to add some custom calculations in the child device . Is there anyway i can intercept or override the sendevent function in the child device handler and then manipulate the value data ?

@vseven I PM’d you my details, i’d love to see your code.

As of this morning, I’m happy to report that I have the code compiling on my ESP8266 and sending both illuminance and color temperature to ST! Big thanks to @ogiewon for all the help!!

26 AM

As you can see, the last major hurdle (other than figuring out how to update the bulb temperature using these values) is getting the color temperature to show up. It’s being sent, what files do I need to add/modify to get it to work?

@vseven what did you do here?

Hi all, my first post here. I’m using ST_Anything with an adafruit huzzah esp8266 board. Everything is working awesome thanks to the excellent tutorial and readme! I’m using a photoresistor attached to an LED indicator on a washing machine to send me a notification when the washer is complete. (my specific brand of washer does not play well with the standard method of measuring power via a smart plug)

Where can I find what each of the instructions do for this: static st::PS_Illuminance sensor1(F(“illuminance1”), 60, 20, PIN_ILLUMINANCE_1, 0, 4095, 0, 10000);

I’d like to lengthen the polling time. I can guess it’s the “60” number, but I’d like to know what all the numbers are - for all of the sensor types too.

Also, my photoresistor measures nearly 200lux, even while completely blacked out. Would this be a configuration issue with ST_Anything?

I feel your pain. I’m awaiting a 5v–>3.3v divider in order to do mine. But I did find a few other options:

This is an adapter that allows for programming via USB and the Arduino IDE:

Alternatively, you can just use an Arduino board with a voltage divider:

I’ll be doing this 2nd option next week, hopefully it goes smoothly.

I’ve modified the source code to do exactly this but it’s not fully tested. Instead of the parent just pushing the data to the child it raises a event instead which lets you do stuff with the data. I can send you details but again it’s not fully tested. PM me the devices you are using.