[DEPRECATED] ST_Anything - Arduino/ESP8266/ESP32

Dan
I found out why the ESP-01 was not booting up correctly …you have to connect the chip power down pin too to the 3v3 line for it to work right …i guess it was a requirement that i did not know about :slight_smile:

Not too long ago we did this together that actually works flawlessly

/// @brief
///   Arduino SmartThings Ethernet ESP8266 WiFi On/Off with LED Example 
///
///   Revised by Dan Ogorchock on 2017-02-11 to work with new "SmartThings v2.0" Library
///
///   Notes: The ESP-01 communicates via WiFi to your home network router,
///          then to the ST Hub, and eventually to the ST cloud servers.
///   For Denis Grabocka use case
///
//*****************************************************************************

#include <SmartThingsESP8266WiFi.h>

//*****************************************************************************
// Pin Definitions    | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
//                    V V V V V V V V V V V V V V V V V V V V V V V V V V V V V
//*****************************************************************************
//******************************************************************************************
//NodeMCU ESP8266 Pin Definitions (makes it much easier as these match the board markings)
//******************************************************************************************
/* #define LED_BUILTIN 16                 ****   // If i am understanding it correctly we do not need any digital Inputs or Outputs in this sketch
#define BUILTIN_LED 16                    ****   // hence the commenting out of this portion

#define D0 16
#define D1  5
#define D2  4
#define D3  0
#define D4  2
#define D5 14
#define D6 12
#define D7 13
#define D8 15
#define D9  3
#define D10 1


#define PIN_LED LED_BUILTIN  //Onboard LED   */

byte relON[] = {0xA0, 0x01, 0x01, 0xA2};  // Hex command to send to serial for open relay      Help needed here: Do I define these here or can i just serial write the hex command directly further down??
byte relOFF[] = {0xA0, 0x01, 0x00, 0xA1}; // Hex command to send to serial for close relay     Also is byte the proper parameter

//*****************************************************************************
// Global Variables   | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
//                    V V V V V V V V V V V V V V V V V V V V V V V V V V V V V
//*****************************************************************************
SmartThingsCallout_t messageCallout;    // call out function forward decalaration

//******************************************************************************************
//ESP8266 WiFi Information    CHANGE THIS INFORMATION ACCORDINGLY FOR YOUR NETWORK!
//******************************************************************************************
String str_ssid     = "grabockanet_2ghz";                           //  <---You must edit this line! // I will be putting my informations on this part 
String str_password = "4697374387";                   //  <---You must edit this line!
IPAddress ip(192, 168, 1, 222);       // 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, 192);    // smartthings hub ip     //  <---You must edit this line!
const unsigned int hubPort = 39500;   // smartthings hub port


//Create a SmartThings Ethernet ESP8266WiFi object
st::SmartThingsESP8266WiFi smartthing(str_ssid, str_password, ip, gateway, subnet, dnsserver, serverPort, hubIp, hubPort, messageCallout);

// bool isDebugEnabled;    // enable or disable debug in this example

bool momentaryActive = false;
int period = 2000;
unsigned long time_now = 0;

//*****************************************************************************
// Local Functions  | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
//                  V V V V V V V V V V V V V V V V V V V V V V V V V V V V V V
//*****************************************************************************
void on()
{
  Serial.write(relON, sizeof(relON));  // turn LED on
  time_now = millis();
  momentaryActive = true;
  smartthing.send("switch1 on");        // send message to cloud
}

//*****************************************************************************
void off()
{
  Serial.write(relOFF, sizeof(relOFF));   // turn LED off
  momentaryActive = false;
  smartthing.send("switch1 off");       // send message to cloud
}

//*****************************************************************************
// API Functions    | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
//                  V V V V V V V V V V V V V V V V V V V V V V V V V V V V V V
//*****************************************************************************
void setup()
{
  // setup default state of global variables
  // isDebugEnabled = true;

  // if (isDebugEnabled)
  // { // setup debug serial port           
  Serial.begin(9600);         // setup serial with a baud rate of 9600             **** In my ESP01 case the baud rate is the same as well 9600
    // Serial.println("");
    // Serial.println("setup..");  // print out 'setup..' on start
  // }
  
  // setup hardware pins 
  // pinMode(PIN_LED, OUTPUT);     // define PIN_LED as an output    **** Should i comment this out in my case?? if Not what do i do here??
  Serial.write(relOFF, sizeof(relOFF));   // set value to HIGH (off) **** Is this right??

  //Run the SmartThings init() routine to make sure the ThingShield is connected to the ST Hub
  smartthing.init();

  //synch up the ST cloud
  smartthing.send("switch1 off");       // send message to cloud
}

//*****************************************************************************
void loop()
{
  // run smartthing logic
  smartthing.run();

  //check to see if we need to run off the momentary switch device
  if (momentaryActive) {
    if (millis() - time_now > period) {
      momentaryActive = false;
      off();
    }
  }
}

//*****************************************************************************
void messageCallout(String message)
{
  // if debug is enabled print out the received message
  // if (isDebugEnabled)
  // {
    // Serial.print("Received message: '");
    // Serial.print(message);
    // Serial.println("' ");
  // } 

  // if message contents equals to 'on' then call on() function
  // else if message contents equals to 'off' then call off() function
  if (message.equals("switch1 on"))
  {
    on();
  }
  else if (message.equals("switch1 off"))
  {
    off();
  }
}

Which also uses an ESP-01 and a serially controlled relay with SmartThings and ST_Anything.

I have one request please can you guide me on how to incorporate the webserver part of the above example into it ( [RELEASE] ST_Anything v2.9.2 - Arduino/ESP8266/ESP32 to ST via ThingShield, Ethernet, or WiFi) it will be really practical to have something like this in my situation since i have lots of family members and cousins that come in and out of the house that do not have Smartthings on their phones so i can share a code with each of them and also be able to change it once in a while.

I really appreciate all you do and i completely understand if you have no time or patience to deal with it

Thank you again
Denis

I tracked down the code and found the problem.

The code got stuck in SmartThingsESP8266WiFi.cpp / SmartThingsESP8266WiFi::send(). Near the end there is a while loop (line 371)
while (st_client.connected()) {
//while (st_client.available()) {
char c = st_client.read(); //gets byte from ethernet buffer
//if (_isDebugEnabled) { Serial.print©; } //prints byte to serial monitor
//}
}
st_client.connected() always returns true, and the st_client.read() returns ascii code of 255.
I then switched the while condition to st_client.available() and everything seems to be good now. Not sure what is the cause for the old code to break and if there is any negative effect from this fix.
I have another controller using W5500 ethernet shield, and there is a similar block of code which can be fixed in this way. I guess other devices could be affected too.

1 Like

Yes. Hubitat is not “following the lead of ST.” Rather, it is its own company, focusing on their own strategy. That have not indicated that they have an desire to ever get rid of Groovy based Apps and Drivers. Their focus is local processing.

Hmmmm :thinking:

As you can see, we’ve gone around and around regarding that section of code. Sounds like I need to look at it once again. Thank you for the feedback!

Denis,

I’m not an Arduino webserver expert. In fact, none of my sketches implement a webserver.

The thing to be careful of is the fact that ST_Anything does implement a network server already. I’m not sure how many can be run simultaneously in one sketch.

Good luck!

1 Like

I am working on a project so that I can learn how to program the ESP8266 and also work with groovy code. My project is a garage door opener (boring, I know), but I’m trying to do something a little unique and I’d like some feedback on whether I should head down this path or not.

At a high level, the idea is to press a button in the ST app, then my ESP8266 will initiate a buzzer for 10sec, and after that the garage door will begin to open (or close). During that 10sec window, I’m going to monitor the physical garage door opener with digital inputs on the ESP8266, and if the physical button is pressed while the buzzer is sounding, the process would be cancelled. I think I can do this with the “callbackRcvd2” functionality. I also plan to have a reed switch connected to the ESP8266 to monitor if the door is open or closed.

So question #1 is whether I can do all this in a single sketch without having to modify anything else?

Next, I’m wondering if I can have ST see this entire setup as a simple switch, and handle everything in the arduino sketch. My original plan was to have a timedrelay, a contact sensor, and then use the custom garage door opener device handler (found on another thread on this site) to combine them in ST.

So question #2 is: can I just do it all in the sketch and avoid these unnecessary ST devices? Have ST think it is operating a simple switch, and within my code I can update the switch status?

I’m sure what you want can be done, but I’m not sure it can be done in one sketch without modifying/borrowing from the ST_Anything library. I could be wrong, but I don’t believe there’s a way to intercept messages to/from the ST cloud (that’d be a pretty cool feature for future releases, though).

You can trigger callbacks using callOnMsgSend or callOnMsgRcvd, but that doesn’t stop the data from reaching its endpoint. As far as I can tell, there’s no built-in way to do that.

I can think of some roundabout ways to maybe accomplish what you want using dummy switches, etc., but if it were me, I’d use the ST_Anything_Multiples_ESP8266WiFi example as a starting point. Then I’d copy the S_TimedRelay class, which should get you about 80% of the way to your goal.

My advice is to start simple. Try to get the ST_Anything Door Control Device up and running without making any changes to the base code. This will get you 90%+ of the way without having to write any Arduino or Groovy code. Once you get that working, we can discuss the next steps.

I was focused too much into modifying the ESP8266_multiples sketch to realize that you had a IS_DoorControl class. Whoops.

So I restarted from ST_Anything_GarageDoors_ESP8266WiFi. I have it working, but it is buggy in the fact that the phone app doesn’t seem to be updated with the contact sensors. Also, I’m randomly getting an extra child app after opening/closing the door a few times. Sometimes I’ll get an extra doorContro1, and after deleting everything and re-adding the parent, I’ll get an extra doorControl2.

Looking at the livelogging, it appears the status is updating. Just isn’t going updating on my phone app. But I also see the line “isChild = true, but no child found - Auto Add it!” showing up when it shouldn’t.

Yes, the problem you’re experiencing with duplicate child devices appears to be getting worse for SmartThings users. I don’t know what ST has done to their backend to cause this. I wish I had better news. If anyone has a fix, I’m all ears…

Which error were you getting when trying the atomicState code?

Hey Dan,

I cannot get the serial monitor to work. Do I need to turn on debug?

Hi all.
Can anyone recommend another Temp/humidity sensor to work with this other then the DHT22.
My issue is I use them in a humid Vivarium and if any water gets on them from spraying they mess up and tend to get stuck on a overly high reading.
THESE ones say they don’t do that but I can’t seem to find them to buy or if they would work in a sketch.
Thanks

You should not need to change anything, assuming you’re using the example sketch I created for the LinkNode R4. Make sure you have the Arduino IDE Serial Monitor Windows set to 115,200 baud rate.

ST_Anything’s ReadMe lists all of the Temperature and Humidity sensors that are already supported. Three that might be worth a look are the

  • AM2320 I2C sensor
  • BME280 I2C sensor
  • SHT31 I2C sensor

If you can find these packaged properly for you application, they should work.

For reliable, robust temperature only measurements, the DS18B20 sensors are available in a stainless steel package for a low price.

https://www.amazon.com/Vktech-Waterproof-Digital-Temperature-DS18b20/dp/B00EU70ZL8/ref=sr_1_3?keywords=DS18B20&qid=1556711161&s=gateway&sr=8-3

1 Like

I’ll have to give it another try when I am at home. I don’t recall the exact error.

Adafruit’s SHT31 module might be a good candidate. They use a version of the sensor with a PTFE filter over the sensing element to prevent exactly your problem.

Also, @ogiewon, I actually modified your PS_AdafruitAM2320_TempHumid library to support the SHT31 maybe a week before your released your version. If only I waited… Both versions turned out remarkably similar, though. Great minds, right?

Anyway, just an FYI, I found that the SHT30 works just fine using the same library with no further modifications. Just another sensor to add to the list!

2 Likes

Thanks I’ll try them.

Cheers yeah I’ve just been looking through them, I noticed the SHT31 needs soldering though and I’m useless at that I can never get it right lol.

How else would you connect it? Breadboard?

EDIT: The SHT30 I mentioned is available in a module with a cable connector, but unfortunately it doesn’t have a PTFE filter.

https://wiki.wemos.cc/products:d1_mini_shields:sht30_shield

1 Like

I normally get ones with the pins and just connect the cables to it.
I’ll order some of them though and give my soldering another go.
Thanks