[RELEASE] ST_Anything v2.9.2 - Arduino/ESP8266/ESP32 to ST via ThingShield, Ethernet, or WiFi

arduino
alarm
dth_misc
esp8266
esp32

(Dan) #2387

Can you provide an example use-case for this? The ST App does not really allow for data entry. You can use a slider control to enter values from 0 to 99, that are then sent down to the ST_Anything sketch as a dimmer level… As far as I know, you cannot enter text into the ST App, except as a device setting. Again, those could be sent to the Arduino, if desired.

Help me understand what you’re trying to accomplish.


(Kampto) #2388

Are the DHT sensors working fine thru the Arduino serial monitor? I had DHT22 issues with ESP8266 and ESP32 boards until I found DHT librarys build specifically for the esp’s.


(Steve ) #2389

Yeah they were working fine through the monitor.
They’ve been up and running no problems for a while now :blush:


(Seth Miller) #2390

This is what I am trying to do as well. I have a nodemcu with an ultrasonic sensor and an rgb strip. I hacked the ultrasonic library so that I can poll the sensor every 100 milliseconds without interfering with the st poll of every minute. The rgb is set to display different colors depending on the ultrasonic sensor value.

I want to be able to change the distance values and the rgb color in the sketch with values from the app. I created some extra preferences in the st_anything app and was able to store some values. My assumption is that I need to create a variable and a reference like you posted a few days ago. I’m just not sure how or where to retrieve the variables.


(Dan) #2391

The easiest way to do this is to add another callback function (e.g. callbackRcvd( const String &msg) ) to your sketch. The st::everything class supports two optional callbacks, one for data being sent to SmartThings, and another for data coming from SmartThings. My example sketches demonstrate the first one. But you can easily add the second one as well.

Here are the function pointer definitions from Everything.h.

			static void (*callOnMsgSend)(const String &msg); //If this function pointer is assigned, the function it points to will be called upon every time a string is sent to the cloud.		
			static void (*callOnMsgRcvd)(const String &msg); //If this function pointer is assigned, the function it points to will be called upon every time a string is received from the cloud.

In the example sketches, you’ll find the following line of code in the setup() routine. Just add another uniquely named callback function, and add it as follows…

  //Initialize the optional local callback routine (safe to comment out if not desired)
  st::Everything::callOnMsgSend = callback;
  st::Everything::callOnMsgRcvd = callbackRcvd;

Hopefully this makes sense for the Arduino changes. Within your new callback, you can grab the name/ value pairs being sent from ST and do whatever you want in your sketch.

On the groovy side, just add appropriate calls to send the properly formatted name/value pairs to the Arduino.


(Tommy Saaek) #2392

I am modernising our old drying cabinet the used to be controlled by a mecanical timer to be humidity controlled. Using a temp/humidity sensor I monitor the humidity level, and when it hits a specified setpoint the laundry should be dry, and the cabinets turns off. I will only use St_anything for operation indication in Smartthings.
My wish is to be able to change the humidity setpoint variable without physically connect to the Arduino with a USB-cord.


(Dan) #2393

I am curious… What is being used to turn off the drying cabinet? Is the ST_Anything Arduino changing the value of an output to accomplish this? Or, are you letting SmartThings compare the humidity value against a target and then it turns off the power?

In any event, if you want to send the target data from ST to the Arduino running ST_Anything, follow the directions I outlined in the previous post.


(Dan) #2395

I fixed the code comments to include the required F() around the name of the device. Sorry about that!


(Seth Miller) #2396

I am able to send the preferences/settings in the device handler from ST back to the sketch and parse them. I have just one more step I am struggling with.

Instead of putting everything in the sketch, I’m trying to put everything into a library similar to all the other devices but my library needs to be able to call the beSmart() function in the rgb library. I tried adding a parameter to the constructor in the sketch passing the reference to the rgb executor but I can’t figure out what type it would be or how I reference the pointer in my custom library.

static st::PS_Ultrasonic sensor1(F(“ultrasonic1”), 60, 0, PIN_ULTRASONIC_T, PIN_ULTRASONIC_E, &executor1);


#2397

Is there an easy way to make the refresh a little longer, say 30 minutes? 5 minutes just seems a bit excessive as far as network traffic goes. If it’s not a one-line type change, then don’t worry about it.


(Dan) #2398

Just edit “constants.h” in the ST_Anything library. Within that file, you can choose to disable the automatic refresh, or adjust the timing of it.


(Dan) #2399

OK, sounds like you’re making some progress, but I am a little confused now. You have two ST_Anything devices defined in your sketch, correct? One is the PS Ultrasonic sensor, and the other is an EX RGB light?

Now, what are you sending from ST to the Arduino, and which of these devices needs to receive it? The Everything Class is designed to take anything sent to it from SmartThings, look up the device by name, and then call that device’s beSmart() function.

Using the pair of callback functions in the sketch is how ST_Anything is designed/architected to accomplish local device-to-device interactions. It is easy to call another device’s beSmart() function by simply “sending a new name/value pair” to Everything from within the callback function, as shown below.

st::receiveSmartString("rgbSwitch1 on");  //use same strings that the Device Handler would send

Just change the ‘on’ to whatever you’d like and let Everything take care of it for you.


(Tommy Saaek) #2400

The cabinet will be powered via a contactor, which is controlled by the Arduino. The whole process is within the sketch, without any inputs from Smartthings. I only added st_anything for monitoring in the Smartthings app. :slight_smile:


#2401

I assume it’s this:

static const int DEV_REFRESH_INTERVAL=300;


(Dan) #2402

Correct. The comments are pretty self-explanatory in the constants.h file.

			//Interval on which Device's refresh methods are called (in seconds) - most useful for Executors and InterruptSensors - only works if DISABLE_REFRESH is not defined above
			static const int DEV_REFRESH_INTERVAL=300;				//seconds - Used to make sure the ST Cloud is kept current with device status (in case of missed updates to the ST Cloud) - primarily for Executors and InterruptSensors - only works if DISABLE_REFRESH is not defined above

(Tommy Saaek) #2403

Is it possible to bind a device to a variable instead of a pin?

Lets say I use touchRead to get a value. Depending of what the value is I want to set e.g a contact as open or closed.


(Dan) #2404

I would recommend you simply create a new ST_Anything library Device Class that supports touchRead instead of using a standard pin. That is how we designed this library to be used. We encourage users to contribute additional devices to the project in the form of new device classes.


(Seth Miller) #2405

Sending the string directly made things so much easier. The only thing I added to your suggestion was an extra parameter to the constructor in my library referencing the name of the other device.

static st::PS_Ultrasonic sensor1(F(“ultrasonic1”), 60, 300, 0, PIN_ULTRASONIC_T, PIN_ULTRASONIC_E, “rgbSwitch1”);

Then I use that variable when I send the string so I’m not hardcoding anything in the library.

st::receiveSmartString(m_nRgbSwitch + " 000000");

However, I did run into a few other problems.

st::Everything::run() uses st::PollingSensor to determine the polling frequency of the sensor. I can easily increase the frequency of the poll by changing the second parameter in the sensor constructor to one second. But, when the polling library was written there was probably no reason to assume that the polling would ever be run more frequently than once every second. However, I need it to run about five times per second. The st::PollingSensor constructor accepts the interval parameter in seconds and converts it to milliseconds so I passed in 0.2. But, the interval parameter is defined as long which doesn’t accept numbers with decimals. So, I went through the st::PollingSensor library and changed the interval parameter type to float instead of long.

The second problem I have is that beSmart() in both of my libraries wants to update the hub every time it is called which a problem when I am calling it five times per second, so I’m working on adding a second interval parameter to both of the constructors. One interval will be for my local sub-second poll, and the other will be for the frequency of sending updates to the hub.


(cslee) #2406

I’m still not clear how this callback works. I’m almost done with my intercom project. Audio/Amplifier/Relay/button sensing all working as in the arduino sketch. Now I want to add the ST part. right now I have a loop that scans the buttons and sets the relays.

With ST integrated I want to use ST to log messages about what buttons were pushed. Okay, these are not ST buttons, but rather analog voltages on the Analog pins. These needs to react fast for the intercom to work without lag. I want to be able to set up some “Enables” per channel via the ST device app to control the behavior somewhat? Any pointers?

my loop looks like

void loop () {
scan_buttons;
set_relays;
}

When the buttons are debounced, I set an array B[15][5] with value 0, 1, 2, 3, 4. for channel B[i] where
0 is no button pressed, 1 is button 1 pressed, 2 is button 2 pressed , etc…

set_relays with use that information to set the channel relays as needed.


(Dan) #2407

OK, I have an idea of what you’re trying to accomplish, however I am missing how SmartThings plays a role in this.

If you want a custom sketch (and it sounds like you do based on what I have read above), you’ll probably simply want to ADD some SmartThings capabilities to your sketch, versus trying to use ST_Anything.

ST_Anything is an application framework, that assumes you are attaching standard devices (temperature, humidity, luminance, relays, etc…) to the microcontroller. ST_Anything then takes care of the rest, making it much simpler to integrate with SmartThings/Hubitat.

Underneath, ST_Anything is using one of my various “SmartThings…” communications libraries (example sketches are included with those microcontroller specific libraries) in order to integrate with SmartThings. Adding one of these libraries to your existing sketch may be the simpler way to go, especially since it sounds like you’re a programmer.

What you’ll need to decide is how you’d like to have your microcontroller appear within SmartThings, using standard ST Capabilities (e.g. switches, buttons, temperatures, etc…) Once you figure that out, I can provide some more guidance. If it is as simple as logging button presses, that is pretty darn simple. These would easily map into the SmartThings “Button” Capability. You’d probably want a SmartApp to monitor the button presses and perform any ST actions desired. webCoRE, for example, could handle this.