[Release] HubDuino v1.1.9 - Hubitat to Arduino / ESP8266 / ESP32 / ThingShield Integration (ST_Anything)

OK, found some time to try to help explain how things work...

ST_Anything is a set of Arduino libraries and example sketches that allow simple integration of Arduino-style devices with Hubitat. It has support for various sensors and handles all of the GPIO scheduling, polling, etc... In order to communicate with the Hubitat hub, it uses a set of "SmartThings..." libraries that are based off of the old SmartThings ThingShield library from back in about 2014. I have since extended that library to support various LAN/WiFi devices as well.

There is also a set of Groovy Drivers for Hubitat, that implement the Composite Device driver model (i.e. Parent/Child.) The parent device handles all communications, and creates child devices as needed, as long as those 'devices' adhere to the strict naming convention as documented in the HubDuino ReadMe. Devices must be uniquely named things like "contact1", "motion1", "voltage1", "voltage2", "voltage3" . The text portion of the name, for example "voltage", is used by the parent to know what child device type to create. The numeric portion, for example "1", indicates which sequence of child devices of the same type to create/update. So, if you need two voltage measurement sensors, you would use the names "voltage1" and "voltage2".

Now...in order to transmit the value of the child devices to the hub, we need to to follow a very simple "name value" string format. It uses a simple space delimiter between the name and value. So, if you want to send data from the Arduino to the Hub, you would send a string something like "voltage1 241.3", which would cause the parent device to create/update a Child Voltage Measurement device named "voltage1" with a value of "242.3" volts.

In order to manually update the hub from within the Arduino sketch, all one needs to do is make the following call from within the loop() routine.

String strUpdate = "voltage1 241.3";
st::Everything::sendSmartString(strUpdate); 

It is VERY IMPORTANT that you not update the hub very fast, or else you will bring the hub to its knees. Implement a NON-blocking mechanism (use a millis() timer) to only poll your voltage measurement device every ~60 seconds, and then send the result using the call shown above.

You need not declare a PS_Generic or PS_Voltage device in this case. Your code in the sketch is handling everything that would happen inside one of these ST_Anything 'devices'. We're just taking a short-cut.

I hope this helps explain what's going on... Please let me know if you have any questions.

Thanks for the very good explanation! Already set up a test and works great from manually sending trigger data to Arduino. I was never going to get this to work with the naming convention not being followed. As for non-blocking, I was planning on using the rules engine in Hubitat to periodically send a trigger via a string from sendData of the parent device, but it appears it is not exposed to the rules engine from what I can tell. I may have to set up some other exposed way of updating. I figured the easiest way would be to put my code inside of the callback routine to keep from having to implement a delay on the Arduino side and use Hubitat as a poll. IS there a way to create a rule inside Hubitat to send a String via the sendData parameter of the parent device. I tried using generic1 as a way to communicate as well, but I don't see it in the actions of a rule either. Fake relays are my thoughts right now to trigger different code in the callback. I have 7 different routines for various parameters that I would like to poll a different one around a minute apart. If what is needed isn't exposed through the Hubitat side, then I can possibly using the polling interval with a generic1 to run a counter on the Arduino side. Thoughts on each way? Thanks again for clarifying and awesome work on this library. Switching over to Hubitat from OH has been amazing thanks in part to work like you guys are doing.

I would not add the extra work to the Hubitat side. Just use a non-blocking timer based on using the millis() Arduino function in the loop() routine of the sketch. This is exactly how ST_Anything is doing things behind the scenes. Lots of simple guides available online.

I would assume your current sketch is also performing some sort of delay, to prevent polling the physical device constantly, correct?

Here is a simple example of what I am talking about...

https://www.arduino.cc/en/tutorial/BlinkWithoutDelay

Yes. Current code will work for this. I know I am kinda taking a hack saw to what the purpose of the ST_Anything library was developed for. I am adding a full alarm system through the library to add to the existing relays and temp/hum sensor, so I wanted one device instead of having a couple running different code. Thanks a ton!

Dan, quick question. Any idea roughly how many loops per seconds a ESP8266 processes? Is this processor and sketch specific or is it a set number? Would be helpful in estimating the right value for the contact parameter.

It depends on how much code the ESP8266 has to process each time through the loop(), so no easy way to estimate.

Just adjust the value in huge increments and you’ll be able to perceive when the delay is too long.

Try 500, 5000, 50000, etc... at some point you’ll be waiting for the contact sensor to change states, instead of it being almost instant. Then you’ll know the upper limit and can back down appropriately for your application.

Should my hubduino devices be broadcasting an SSID? Seems that one of mine is. Is there some setting for this I might have enabled by accident? It's still reporting in as it should and connected via wifi as far as I can tell.

What microcontroller are you using? I am pretty sure that the ST_Anything Arduino code for the ESP8266 disables the Access Point mode...:thinking:

Crap. It's not you, it's me. It's a Wemos D1 Mini not running hubduino.

1 Like

Just downloaded latest Arduino IDE 1.8.13, was on 1.8.8. Did a compile on my Mega with <SmartThingsEthernetW5500.h>, No issue.

Went to your github and installed All the latest Arduino Librarys including <SmartThingsEthernetW5x00.h> into libraries folder, removed all the old ones. Changed sketch Mega to use <SmartThingsEthernetW5x00.h> (in 2 places).

Get the following error:
"Error compiling for board Arduino Mega or Mega 2560".

Put the <SmartThingsEthernetW5500.h> folder back in libraries folder. Changed sketch back to <SmartThingsEthernetW5500.h>. Still same compile error.
"Error compiling for board Arduino Mega or Mega 2560".

Any ideas? Error occurs after coping all your latest librarys

Do you have an Ethernet2 library in your libraries folder? You may want to remove it.

Another option is to rename your current Arduino/libraries folder, create a new Arduino/libraries folder, and copy the contents of my GitHub repo’s libraries folder. Afterwards, be sure to close and reopen the Arduino IDE for it to pick up the new libraries folder contents.

I did have ethernet2, just removed it and the w5500 library, closed IDE and reopened. Same issue. "Error compiling for board Arduino Mega or Mega 2560".

On a side note I was able to compile a Adafruit esp32 board with ST anything and new librarys with out issue.

Is there Legacy junk in my Arduino15 folder?

Dan:
Just got C-7 and planning to migrate all my devices to C-5 to C-7. For Z-wave devices, I am going to follow steps in Migrating a Z-Wave Network . This will be my first step.

Then, at the very last, for all the devices under ST_Anythng, I am planning to assign new IP address for existing HE C-5 first. Then I will use previously reserved IP address for C-5 (192.168.0.166) to C-7. so that I don't have to change any code. This will save time and the automation. Please comment.

1 Like

By the way, I did move out all the "ST....." Librarys and copy in all your new ones. Also Copied in all your off the shelf non ST Libraries and over wrote the old ones.

Compiler also flagging "Servo" even though im not using it.

C:\Users\kampto\AppData\Local\Temp\arduino_build_834831\libraries\Servo\avr\Servo.cpp.o (symbol from plugin): In function ServoCount': (.text+0x0): multiple definition of __vector_17'
C:\Users\kampto\AppData\Local\Temp\arduino_build_834831\libraries\RadioHead\RH_ASK.cpp.o (symbol from plugin):(.text+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
Multiple libraries were found for "Servo.h"
Used: C:\Users\kampto\Documents\Arduino\libraries\Servo
Not used: C:\Program Files (x86)\Arduino\libraries\Servo

That should work fine, as long as your parent device is using the IP address of the HubDuino microcontroller as the device network ID, not the MAC address. If you set these up recently it “should” be fine. If you set these up a long time ago, the child device network ID’s may still be based on the MAC address + name, which was the old design.

It’s worth a try!

The multiple Servo libraries warning is fairly normal/common.

Thanks Dan

I have no clue. You could create a new user account on your PC, log In as that user, and try to set things up from scratch to see if you can get a clean build of the MEGA + W5x00.

Update:
Ok so it compiles with all the old ST librarys and ethernet W5500. It does not compile with all the new ST Librarys. "Error compiling for Arduino Mega or Mega 2560"

So I can get it to compile if I remove all ST_Anything lines from the sketch and keep all the RadioHead RH_RF95.h LoRa lines in sketch. Both with with w5x00 library.

I can also get it to compile if I keep all ST_Anything and remove all the RadioHead Lora sketch lines and RF95 library. Both with w5x00 library.

So must be an interaction. Both the Ethernet and LoRa modules use SPI . It used to compile fine with both in the sketch