[RELEASE] ST_Anything - Arduino/ESP8266/ESP32

Are you trying to bypass ST_Anything and only use the “SmartThings…” communications libraries? The example you’re attempting to use is very old, and is based off of the old SmartThings ThingShield example code.

So the hunt for the zombies continues.

I did some digging inside the SmartThingsEthernetWx500.cpp file. I turned on _isDebugEnabled and got more information about why the network seems to be resetting. The monitor stream now shows this:

19:45:27.809 -> ***********************************************************
19:45:27.809 -> ***** SmartThings.send() - Ethernet Connection Failed *****
19:45:27.809 -> ***********************************************************
19:45:27.809 -> hubIP = 192.168.1.29 hubPort = 39500
19:45:27.809 -> ***********************************************************
19:45:27.809 -> ******        Attempting to restart network         *******
19:45:27.842 -> ***********************************************************
19:45:28.826 -> 
19:45:28.826 -> Enter the following three lines of data into ST App on your phone!
19:45:28.826 -> localIP = 192.168.1.202
19:45:28.826 -> serverPort = 8090
19:45:28.826 -> MAC Address = 06AABBCCDE02
19:45:28.826 -> 
19:45:28.826 -> hubIP = 192.168.1.29
19:45:28.826 -> hubPort = 39500
19:45:28.826 -> 
19:45:28.826 -> SmartThingsEthernet: Intialized
19:45:28.860 -> 
19:45:28.860 -> ***********************************************************
19:45:28.860 -> ******        Attempting to resend missed data      *******
19:45:28.860 -> ***********************************************************

So, I started to poke around to find out why the connection to the Hub might be failing. This is the code snipped inside the SmartThingsEthernetWx500.cpp file:

    //*******************************************************************************
	/// Send Message out over Ethernet to the Hub 
	//*******************************************************************************
	void SmartThingsEthernetW5x00::send(String message)
	{
		//Make sure the client is stopped, to free up socket for new conenction
		st_client.stop();

		if (st_client.connect(st_hubIP, st_hubPort))
		{
			st_client.println(F("POST / HTTP/1.1"));
			st_client.print(F("HOST: "));
			st_client.print(st_hubIP);
			st_client.print(F(":"));
			st_client.println(st_hubPort);
			st_client.println(F("CONTENT-TYPE: text"));
			st_client.print(F("CONTENT-LENGTH: "));
			st_client.println(message.length());
			st_client.println();
			st_client.println(message);
		}
   ...
  ...

That’s where the debug trail ended for me. I couldn’t find where st_client is defined nor instantiated.

Can you help me find it?

Sure thing… Look in the SmartThingsEthernetW5x00.h file. It is a private member of the SmartThingsEthernetW5x00 class.

namespace st
{
	class SmartThingsEthernetW5x00: public SmartThingsEthernet
	{
	private:
		//Ethernet W5x00 Specific 
		byte st_mac[6];
		EthernetServer st_server; //server
		EthernetClient st_client; //client
.
.
.

Yeah, I was thinking trying to learn how the code it would be easier to start with a small project that way I could step through it easier.

Sure thing. That makes sense. Which DTH did you use with the On/Off example sketch? You’ll need to use the following. Be sure when you enter the MAC address into the Device’s settings (gear icon) in the ST Classic App that you use all uppercase and no colons. Also, be sure to configure the sketch to use the ST Hub’s TCP/IP address on your LAN.

Hopefully this helps you along your path of learning. :slight_smile:

Trying this out for the first time for a slight odd project (of course).

I have a Wemos D1 arduinio board which is working fine and i’m using it to sequence 10 leds with high side switching via some custom electronics. I want to control this as a single device in Smartthings - I don’t want individual LED control on the ST side - in fact all I want to do is tell it on/off (it will then deal with sequencing the lights).

Is this the right library to use for this? ATM I’ve rigged it up with a ‘fake’ A0 switch and just trapped the event in the callback where i then switch the digital outputs as I see fit. From a few mins of messing round it looks like i’m going against the grain in that the idea of ST_A seems to be to expose all the digital outs as individual devices. I’ve used A0 to avoid switching anything else but it’s a total hack but enough to show control is possible this way. It’s working but whether it’s on/off is reported wrongly (but hey i’m hacking an analog A0) in the app. It works well enough for me to control them but the state is a bit pants.

Is there a better way to do this? I’m impressed I could hang things together enough to make this work at all and all credit to you for your hard work but I feel I’m abusing it :disappointed:

I’m using an executor:

static st::EX_Switch executor1(F(“switch1”), FAKE_SWITCH, HIGH, false);

where FAKE_SWITCH is A0 obviously.

If I exposed all 10 digital outs to ST_A would this be better and how would I override the actual state switching for the pins so that I’m intercepting and controlling it myself? I felt it easier to ask rather than trawl through the code and inserting more hacks and I may be on the wrong track completely.

Seems like a reasonable ‘hack’ to me. If it is working for your needs, then you should be fine.

If you wanted to take the ST_Anything library out of the picture, you could look at just using the ‘SmartThingsESP8266WiFi’ communications library and adding that to your own sketch. This way there would be no need to worry about using a GPIO pin at all for the ST connectivity.

Look at the post immediately above yours for some hints at how to make it work…

1 Like

Okay…with your assistance and crap ton of trial and error I can now turn on an LED!!!

Thank you again for your help!
Loren

1 Like

I’m so close… of course I say that at every turn. :wink:

A key problem seems to be that the SmartThings database was corrupted. I had to get the support folks to go in and clean it up. So now with Ethernet problems fixed, database problems fixed, I’m ready to give this a swing and darn it… now I’m getting an error about filling out all the requried fields.

I think I have them all filled out. Am I on drugs?

Click the little white x in the error banner. Underneath it should be a SAVE button to click.

Yeah… i can clear the banner with the little white X, but when I tap SAVE, the banner returns.

If this is an old device, which you upgraded to my latest code… you may need to delete the parent device (not the DTH code) and manually reads it again. I changed the list of user settings on the Parent device in my latest release.

Well, I couldn’t do it in the smartthings classic app, but I could do it in the IDE by changing the preferences on the device details page

1 Like

Something look amiss in that screen capture. Perhaps the screen just needs refreshed… after entering the MAC address into that preference field, the ‘Device Network ID’ field should get automagically updated to the MAC address of the Arduino. Are there any errors in the Live Logs?

It is possible to use STAnything on ESP32 to control the monoprice 6zone amp via RS232?
So on the ST app, there will be virtual zone controls, and at ESP32 will send RS232 commands to the AMP, anything remotely close that can be used as a spring board from?

Sure, it is possible. However, I do not believe there are any existing examples of serial devices within ST_Anything.

Much will depend on how you expect things to work, as well as the RS232 API for the device. You’ll also need a voltage level shifter to adjust the ESP32’s 0v to 3.3v to RS232’s -12v to 12v.

More details needed before a design can be considered.

Awesome thanks! I was able to get it to work however, I see the variable it stores it is a long. Can I change this in the .cpp file to a float so I can get a decimal?

m_nSensorValue = float(m_fCnvSlope * tmpCounts + m_fCnvOffset);

I’m reporting out gallons/minute so I have to change my slope to get a 100x value and then divide in my head by 100 to get and accurate number.

Sure, that’s worth a try. Feel free to tweak your copy of the code to make it suit your needs.

OK… for the record, and only for the record, I’d like to document what the root cause was:

Recall the symptom: “ST_Anything running with W5x00 ethernet card keeps resetting the ethernet connection on every attempt to send data to the hub.”

The root cause: The hub IP Address mystically changed. It wasn’t where I thought it was.

The solution: Fix the HUB IP address in whatever way is best for you. In my case, the fixed IP assignment in my router was mysteriously lost for the MAC address of my ST Hub.

The silver lining: The path to find this problem could have been, “Yo dude, are you sending data to the right IP address?” I ignored this possibility because I’ve had a working system for so long. It never occurred to me. However, on the way to the solution, I dug deeply into SmartThingsEthernetW5x00.cpp, .h, ethernet.cpp, ethernet.h, etc, etc. I wouldn’t call myself an Arduino networking expert, but I am now an experienced tourist.

Thanks for the patient attempts to help me find this. All I needed was the right IP, but I got an education for free!

Paul

1 Like

I should add here, though not part of the problem/solution I wanted to document, that the ST devices database got mangled around the same time I was solving this problem. That distracted me for a while, but was unrelated to this particular problem.

I’ve also been reading a terrific book about the 1918-19 flu pandemic. In that situation, most of the medical experts were distracted looking for a bacterial source. It turned out to be viral, of course, but the opportunistic bacteria found their way in once the virus weakened the host. In this case, I was distracted looking for a ST device database problem for a while, even while the real problem was my stinking ST Hub went for an IP walk with out telling anyone.

1 Like