[DEPRECATED] ST_Anything - Arduino/ESP8266/ESP32

My understanding of the DHT11 is that it is a slow device and should not be polled faster than every two seconds. Also are you using the same pins for both devices?

After some testing, it turns out my DHT11 sensor must have been bad. I replaced it with another (it came in a 5 pack) and have had no issues since. I’m only having it poll every 30 seconds, so plenty of time in between readings for the sensor.

@vseven I was never having issues with the colortemp/illuminance values, they were continuing to report accurately.

1 Like

Good to here and that makes a lot more sense since your other values kept reporting. Which means its definitely just my ESP32 and it’s WiFi.

1 Like

Kind of an odd question. But is it possible to make an esp8266 use a cpl pins to send commands using soft serial, make the things to tx a ‘function’ to call when a button in st is pushed?

I am pretty sure Software Serial does not work on an ESP8266. You could use a hardware serial port. I believe the ESP32 has more than one (usually one is used for the USB connection for debugging.)

To answer your question though, yes you could easily create a ST to Serial bridge using just my SmartThings library, or utilize the full ST_Anything library by creating a custom device class.

Has anyone tried to control a RGB device using this library yet? I started making the changes starting with what I think the Arduino sketch should look like. I would like to control a “dumb” RGB LED like this one and RGB LED strips like this one. They each need three pins, one for each color. So based on that I came up with a example sketch:

#define PIN_RGBLED1_Red           A0  //(GPIO 36) SmartThings Capability "Color Control"
#define PIN_RGBLED1_Green        A3  //(GPIO 39) SmartThings Capability "Color Control"
#define PIN_RGBLED1_Blue          A6  //(GPIO 34) SmartThings Capability "Color Control"


  //Executors
  static st::EX_RGBLED           executor1(F("RGBLED1"), PIN_RGB1_Red, PIN_RGB1_Green, PIN_RGB1_Blue);

For the DTH I combined a hue device with the ST_Anything child dimmer switch logic since its pretty similar and made a device based on that:

I made a test device (above) just to make sure it works and it does, on a change it tries to send the value up to the parent but since its a test device the parent isn’t there yet. That and the parent wouldn’t know what to do with the data anyway. But anyway on a change it sends through a HEX value for color, on level it send the level like normal, on/off like normal (would actually just shunt the leds…same as dimmer 0%).

So long story short has anyone already attempted this? If not does anyone wanna tackle the device side? Or am I better off making something completely stand alone?

FYI - Reference I’m using for LED and LED Strips: http://jakebergamin.com/2016/02/08/wifi-led-strip/. I also have a modified shell of my EX_RGBLED.h and .cpp files but again I don’t know what I’m doing so its not right (ie. it doesn’t work…)

Edit - I think I got the parent modified, DTH is done, sketch is done, just working on coverting the arduino examples over to C++ for the .h and .cpp file. I don’t want to mess up my current ESP32 so I have another on order. If no one has attempted this I’ll figure it out…

Edit edit: I removed the dimmer slider since the color control lets you pick a full range and kinda takes care of dimming. Also makes it simplier.

-Allan

While not through ST_Anything, there is an inexpensive controller made for running the RGB lights. It’s based on an esp8266. Have a look at this thread if you want to control RGB strip through smartthings.

I actually saw when I was doing research but I plan on using the controller for other stuff also so if I can add it on that would be pretty handy. That and I’d like to fit it into the “ST_Anything” architecture if possible.

Plus once it’s figured out and working on a ESP8266 I plan on converting it over to a ESP32. But the “standard” ESP8266 needs to come first.

1 Like

@ogiewon , I am having an issue with an ESP32 device . When i load up the sketch i see that it keeps rebooting constantly . Any idea why that could be happening ? I am using a Adafruit feather ESP32 based . See serial out below

Rebooting...
ets Jun  8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0010,len:4
load:0x3fff0014,len:572
load:0x40078000,len:0
load:0x40078000,len:9880
entry 0x400789d8
Guru Meditation Error of type InstrFetchProhibited occurred on core  1. Exception was unhandled.
Register dump:
PC      : 0x00000000  PS      : 0x00060530  A0      : 0x800d5086  A1      : 0x3ffd53e0  
A2      : 0x3ffc3694  A3      : 0x3f400f0c  A4      : 0x0000ea60  A5      : 0x0000d6d8  
A6      : 0x00000003  A7      : 0x00060e23  A8      : 0x800d4f86  A9      : 0x3ffd53c0  
A10     : 0x3ffc3694  A11     : 0x00000001  A12     : 0x3ffd01bc  A13     : 0x3ff48800  
A14     : 0x00060021  A15     : 0x00060223  SAR     : 0x00000020  EXCCAUSE: 0x00000014  
EXCVADDR: 0x00000000  LBEG    : 0x400d3565  LEND    : 0x400d3571  LCOUNT  : 0x00000000  

Backtrace: 0x00000000:0x3ffd53e0 0x400d5083:0x3ffd5400 0x400d14bc:0x3ffd5430 0x40119493:0x3ffd54c0

Rebooting...
ets Jun  8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0010,len:4
load:0x3fff0014,len:572
load:0x40078000,len:0
load:0x40078000,len:9880
entry 0x400789d8
Guru Meditation Error of type InstrFetchProhibited occurred on core  1. Exception was unhandled.
Register dump:
PC      : 0x00000000  PS      : 0x00060530  A0      : 0x800d5086  A1      : 0x3ffd53e0  
A2      : 0x3ffc3694  A3      : 0x3f400f0c  A4      : 0x0000ea60  A5      : 0x0000d6d8  
A6      : 0x00000003  A7      : 0x00060e23  A8      : 0x800d4f86  A9      : 0x3ffd53c0  
A10     : 0x3ffc3694  A11     : 0x00000001  A12     : 0x3ffd01bc  A13     : 0x3ff48800  
A14     : 0x00060021  A15     : 0x00060223  SAR     : 0x00000020  EXCCAUSE: 0x00000014  
EXCVADDR: 0x00000000  LBEG    : 0x400d3565  LEND    : 0x400d3571  LCOUNT  : 0x00000000  

Backtrace: 0x00000000:0x3ffd53e0 0x400d5083:0x3ffd5400 0x400d14bc:0x3ffd5430 0x40119493:0x3ffd54c0

Rebooting...

I have seen that a few times with my ESP32 as well. At this point, I attribute it to the immaturity of the ESP32 platform. To fix it, I simply reload the program via the Arduino IDE. You could try slowing down the transfer rate for the programming to see if that helps.

Good call on the esp8266 and softserial. Im going with esp32 as infantile as it is.

I am at a total loss as to where to begin on the smartthings side. I looked at some of the examples and am barely able to grasp its inner workings. Time is an issue that is probably contributing to this.

My question is, (because i have yet to learn smartthings side, trying to finish school first lol) is how would i create, say, a remote with 16 buttons on it for the smarthings side… and then use an executor per button on the arduino side. If you could at the very least point me in the right direction id greatly appreciate it.

If I understand you correctly, you want to be able to control 16 digital outputs on a micro controller from SmartThings, correct?

If so, you simply modify one of my “ST_Anything_Multiples…” example sketches to have 16 EX_Switch devices, each named “switch1” to “switch16”. That’s it. Once you start the sketch, 16 new switch devices will be created in your ST account. You can rename each of them using the ST phone app to make them easier to keep track of.

Not necessarily. Id like to invoke my own functions that send out specific
data streams over i2c and uart. Invoked by a button in smartthings…
prefer a button to a switch

Understood. You can still start with the EX_Switch class .cpp and .h files. You would use these as a template to build your own “Arduino Devices” that would communicate via I2C or UART. When they receive the “on” command, they would simply send SmartThings a reply of “on”, execute your I2C or UART code, and then send SmartThings a reply of “off”. This way, the ST Cloud is kept up to date nicely.

This is just one way to accomplish this task. There are many others. You could even just use my “SmartThings” library and custom write the entire sketch. You don’t need to use ST_Anything necessarily. ST_Anything uses one of the SmartThings libraries for all communications to the SmartThings Hub/Cloud.

Just a warning for those going with the ESP32. I’ve had some issues with the WiFi dropping and not reconnecting on it through no fault of Dans programming from what I can tell. Been working with the devs on the Arduino/ESP32 GitHub for over a week trying to figure it out. I actually bought a second ESP32 for testing and they both do the same thing so I don’t believe my hardware is bad. It “seems” to get worse when using a DTH22 but I can’t confirm that yet. Right now I have a test ESP32 with full WiFi debug running to catch everything and log for the devs to look at.

If you have a ESP32 running ST_Anything please post or PM me what devices you are using it for, what type it is, and if it’s been stable or not. Maybe I can find a commonality. I’ve added some extra checks to the SmartThingsESP32WiFi library to try and fix it but the only check that works reliably is to reset the controller when it tries to reconnect 10 times and fails (can’t get it to just turn off and back on WiFi for some reason). It does correctly reset and connect but I shouldn’t have to reset the controller just to get it back online which is what I’m trying to work through.

I’ll post more once I get a resolution.

Allan,

Just to make sure… You are running my latest SmartThingsESP32WiFi library, correct? I added automatic reconnect logic to it about three weeks ago. I have had an ESP32 running since then and it seems to always stay connected now. I am sure it is losing the connection and then reconnecting, but at least I have not had to reset the controller in a long while since making this change.

I agree that there is definitely something wrong with the ESP32 as compared the the ESP8266. Thanks for working with the developers on the Arduino/ESP32 Github. I look forward to improved stability with the ESP32 as it really is a very nice, low cost platform.

Thanks for your contributions!

Dan

Yes, definitely using the latest. Problem is the WiFi.reconnect isn’t reconnecting. It should but it’s not. Not to get too far into it but a little background: my ESP32’s are both disconnecting randomly, starting with a bunch of wifi errors (sometimes 100+ of these 113 errors) then first a disconnect due to not being associated anymore, which should be firing the WiFi.reconnect and is based on the logging, but then I get another due to association failed, and again it should try to reconnect but doesn’t then immediately after a auth expired:

[E][WiFiClient.cpp:97] connect(): lwip_connect_r: 113
[E][WiFiClient.cpp:97] connect(): lwip_connect_r: 113
Everything: Sending: temperature1 -49.02
[E][WiFiClient.cpp:97] connect(): lwip_connect_r: 113
[E][WiFiClient.cpp:97] connect(): lwip_connect_r: 113
Everything: Sending: humidity1 -5.02
[D][WiFiGeneric.cpp:182] _eventCallback(): Event: 5 - STA_DISCONNECTED
[W][WiFiGeneric.cpp:187] _eventCallback(): Reason: 7 - NOT_ASSOCED
[WiFi-event] event: 5
WiFi lost connection.  Attempting to reconnect...
[D][WiFiGeneric.cpp:182] _eventCallback(): Event: 5 - STA_DISCONNECTED
[W][WiFiGeneric.cpp:187] _eventCallback(): Reason: 202 - ASSOC_FAIL
[WiFi-event] event: 5
WiFi lost connection.  Attempting to reconnect...
[D][WiFiGeneric.cpp:182] _eventCallback(): Event: 5 - STA_DISCONNECTED
[W][WiFiGeneric.cpp:187] _eventCallback(): Reason: 2 - AUTH_EXPIRE
[WiFi-event] event: 5

The last 4 repeat over and over indefinitely. So I added a counter to your library, each time it hits the disconnect it adds 1, each time it hits the connected it resets to 0. After 5 I recall the init() (which never executes…might be related to https://github.com/espressif/esp-idf/issues/738#issuecomment-311626685 or me not coding it right) and after 10 I reboot (ESP.resstart) which resets the controller and it reconnects just fine.

I’m running the latest firmware, recompiled two days ago, on both ESP32s. Someone else mentioned that Wifi.connect worked before they updated their firmware…maybe a bug was introduced. Someone else said on a disconnect like this try to turn off and on STA but I don’t know how to do that (yet…I’m working on it). So right now I have this for the disconnect:

case SYSTEM_EVENT_STA_DISCONNECTED:
	Serial.println("WiFi lost connection.  Attempting to reconnect...");
	WiFi.reconnect();
	disconnectCounter++;
	if (disconnectCounter > 5) {
		Serial.println("We have recieved the STA_DISCONNECTED event 5 times now.  Re-init...");
		void init();
	}
	if (disconnectCounter > 10) {
		Serial.println("We have recieved the STA_DISCONNECTED event 10 times now.  Reboot...");
		ESP.restart();
	}
	break;

And this on a connect to reset the counter:

case SYSTEM_EVENT_STA_CONNECTED:
	Serial.println("ESP32 station connected to AP");
	disconnectCounter = 0;
	break;
}

I’m assuming I have the void init(); coded wrong and in its place I should have the STA off and back on part. Again…not entirely sure what I’m doing.

Right now I have one of my ESP’s running the above and sure enough it’s rebooting after the counter gets to 10 and reconnecting just fine. Little drastic but it is working. I also have some stuff commented out in the ESP32 core files per a dev so I get full verbose logging of all WiFi events which is pretty nifty…hopefully they can give me more info.

1 Like

I’m trying to retrieve the DHT temp and humidity and display on LCD. I uncommented the sniffer and can see it on the serial monitor. Do you have example Arduino code how to parse out the temp and humid data and assign to a int or float variable?

Here you go. This should get you started.

//******************************************************************************************
//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)
{
  String strTemp = 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
  if (strTemp.startsWith("temperature1"))
  {
    strTemp.remove(0,13);
    Serial.println(strTemp);
  }
  if (strTemp.startsWith("humidity1"))
  {
    strTemp.remove(0,10);
    Serial.println(strTemp);
  }
}

Thanks, I see how that works… Just need to figure out how to convert that strTemp into separate float variable seeing how its a String.