Announcing the "ST_Anything" Arduino/ThingShield Project

Ben,

The easiest way I could think to know the Arduino has stopped sending data would be have the Arduino send a timestamp text string every 30 seconds, or so. Display that string in a “Value Tile” via your Device Handler code so you will know the time of the last update by simply looking at it.

If you want to be notified that the Arduino is offline, you will need to write a SmartApp that can subscribe to the events from the Arduino Device Hander. The SmartApp would need to implement some sort of timeout logic (which can be problematic on the ST Cloud Platform since you will need to use a repeating timer - the new scheduler is much improved in this regard, so it may work well). If the timeout occurs before a regular EVENT comes in from the Arduino, you know it is offline and can then send a PUSH/TEXT notification to your phone.

FYI - My Arduino UNO R3 has been running my ST_Anything_Doors example for many months now, and it has never stopped sending data. It also properly recovers from a power loss, without user intervention. This doesn’t necessarily mean you should not implement your “power loss watchdog”, as your situation may be very different than mine (e.g. trying to run on batteries instead of an AC adapter.)

Hope this helps!

Dan

Hi Dan, thankyou for the reply

I assume a Watch dog timer is not possible in a Device handler?

Time stamp is a good thought, have to get RTC attached, could be using I2C
maybe from mills() or maybe just a toggle indicator that flips every time period, like a heart beat

Battery operation, in conjunction with an AC adapter , wired OR would also make things more relable
but thinking more of total power loss, both Arduino shield, and Hub ( hub has batteries in it, so do not know how long the hub would still be on when total power loss occurs)

If batteries were to power both, the hub and the Arduino shield ( my current system draws about 260 ma peak)
then one could just measure the Voltage from the AC adapter, and when that was down to 0 volts, then send some Text to a special valueTile.

Thanks Dan,

You are an inspiration …

1 Like

I have to say Thanks to Dan and his son for coming up with the libraries and so much sample code and support. I am certainly not new to Arduino but i will be working new projects soon as I just bought 2 shields with the 20% off sale they were under $30. I was thinking I was going to have to slug it out code wise etc… to have to get them off the ground but your work will really make this easy.

Seeing the $100 price tags for a relay for garage doors is what made me pull the trigger. I have several arduino’s around and some trinkets too. I have more temp and other sensors than you can shake a stick at. Including magnetism (hall effect) sensors that can detect when an electric motor/solenoid is active.

I was brainstorming with a friend yesterday and had a thought for a practical use in the bathroom. Using a humidity sensor to determine when someone is showering and steaming up the place and turning the vent fan on. I have one wire temp sensors but also a few AM2301 Humidity and temp combo sensors I can use as triggers. He even commented that if only there was an arduino “stink” sensor for well… other fans :wink:

I am still waiting for the arrival of the shields and look forward to pushing the limits of what it can do and interacting with this community!

2 Likes

If the issue was the Arduino locking up, the Arduino watch dog timer could be used to reset the device. But the ST Anything libraries are pretty solid and that has not been a problem for me with this code. (Although I’ve used watch dog in other cases where I had issues with flaky hardware causing the Arduino to lock up.)

There is an article describing how to set up watch dog here:

-Todd

Hi Todd,

Thank you for the information,

The whole issue is that if communication is lost, or power is lost where, the Arduino and Hub are located, there is no indication on the receiving phone that this is the case, other than looking at the notification section and looking at the last time stamp.

This maybe is the action to take, if the readings are stagnant, look at the notifications and their time stamps.

One last question, since the notifications are time stamped, is the Time stamp available as a variable to be printed out on a ValueTile?

Thanks again

Ben

Have you looked at this?

I haven’t used it, but it’s on my list of things to look at when I have time. Sounds like it might be useful for what you are trying to do.

1 Like

Todd,

Thanks for the link regarding the Arduino watchdog. I learned something new about the Arduino today!

Dan

Ben,

You should be able to update multiple tiles in the parse() routine of the Device Handler groovy code. Simply update the “normal tile” and then also update a new Value Tile that contains the current timestamp from the cloud server (not from the Arduino.) I’m not much of a groovy programmer, so I’m afraid I can’t code it up. I’m sure it’s not too difficult though…

I also think the “Device Monitor” SmartApp, that @Todd_Whitehead posted a link to above, would also be a good solution. I just added it to my system to keep an eye on devices that I rarely think about.

Dan

To be clear, I only posted the link. I did not write the notification smart app…

Todd and Dan, thank you for your replies,

I wish there were some code that would show

Simply update the “normal tile” and then also update a new Value Tile that contains the current timestamp from the cloud server (not from the Arduino.)

looking at :
http://groovy-lang.org/gdk.html
http://docs.smartthings.com/en/latest/getting-started/groovy-for-smartthings.html
http://docs.groovy-lang.org/latest/html/documentation/index.html#_keywords

there is documentation of Time stamp, calendar etc, but with out a SmartThings example I am lost

These are references, for people who know how to program in Groovy

I believe the Device Monitor is a SmartApp, not a Device Handler, so this would have to be run separately from the observations created by the valueTiles.

Thanks again for your input

Ben

Hi Todd and Dan,

I have another question,

In the device handler I have

standardTile("refresh", "device.poll", decoration: "flat", wordWrap: true, width: 3, height: 3, ) {
    state "default", label:'Refresh', action:"device.poll()", icon:"st.secondary.refresh"
}

main (["roomTemp_F1", "humidity_F1", "cO2_F1"])

// details([“roomTemp_F1”, “humidity_F1”, “cO2_F1”])
details([“roomTemp_F1”, “humidity_F1”, “cO2_F1”, “refresh”])

and at the end

def poll() {
zigbee.smartShield(text: “poll”).format()
}

Does this code indicate that when I press the Refresh button/tile on the phone,
that the word"poll" would be sent to the Arduino serial port and show up in the debug screen?

Arduino code is

//*****************************************************************************
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("on"))
{
  on();
}
else if (message.equals("off"))
{
  off();
}
else if (message.equals("poll"))
{
//reportData();
Serial.println("Poll Request ");
Serial.println(" ");
}

}

There doesnot seem to be a specific call for the
void messageCallout(String message)

is this called from
#include <SmartThings.h>

I donot get any messages from the phone to the Arduino Serial port

any help?

@BenB2016

Ben,

So, it appears that you are not using one of my ST_Anything Arduino sketches…correct? With only small code snippets, it is very difficult for me to try and help you debug your Arduino and Groovy code. It would help if you had your source code available in GitHub to allow easy access.

If you use one of my sketches, like ST_Anything.ini along with its corresponding groovy Device Type Handler code, you will be able to see exactly how everything works together. They are a matched set of code, due to the requirement that certain names are shared between the Arduino objects and the Groovy tile names.

As for you question regarding receiving the string “poll” on the Arduino, yes, that should work. Have you checked the live logging in the ST IDE to confirm that your poll() function is being called when you touch the tile? Add a log.debug statement BEFORE the zigbee.smartShield(text: “poll”).format() statement, and make sure there are no other calls afterwards.

Dan

Dan,

This project is a life saver. I pulled out the 80’s alarm system in my place and am working to use the remaining, working sensors. I have a couple of nice PIR hard-wired motion sensors (C-100ST’s) that close a contact when motion is detected. I plan to wire them in after I get the door sensors and a couple of Waterbug WB-200 waters sensors wired in and working.

The electronics and Arduino pieces are fairly straightforward for me, but the groovy Smartthings pieces are causing me issues.

I hate to waste your time but I am having issues with the multiplexer. I have four devices working and updating under the Thingshield device, but the individual (virtual) devices do not update or change state at all.

Are there any tips you can give me for getting the virtual devices to work with the multiplexor?

Thanks,

My recommendation is to start with one of the existing examples, like ST_Anything_Doors_Windows. It shows exactly how the multiplexer architecture works.

Also, read through this explanation I wrote for another user earlier in this thread.

Hi Dan, sorry to be such a pain, but I very new to both Arduino and the SmartThings

here is the Github link

Both the Arduino and Groovy files are there

any assistance is appreciated

Thanks

Ben

Dan, I would like to try our ST-Anything.ino system, but have no idea as to what should be removed or commented out.Tried to compile as is with added libraries, and got a message sketch was too big for the Leonardo memory

I added to the groovy program

	capability "Alarm"

	command "test"

and changed the standard tile to

}

standardTile("test", "device.alarm", decoration: "flat", width: 3, height: 3,) {
    state "default", label:'', action:"test", icon:"st.secondary.test"        
}

main (["roomTemp_F1", "humidity_F1", "cO2_F1"])

// details([“roomTemp_F1”, “humidity_F1”, “cO2_F1”])
details([“roomTemp_F1”, “humidity_F1”, “cO2_F1”, “test”])
}

and added

def test() {
log.debug “Executing ‘alarm test’”
[
zigbee.smartShield(text: “on”).format(),
“delay 3000”,
zigbee.smartShield(text: “off”).format()
]
}

and are able to get a debug response on the groovy Device Handler web page

like

6aadb3c0-a6d7-487b-bb37-81a23fda3c10 4:29:09 PM: debug A32
6aadb3c0-a6d7-487b-bb37-81a23fda3c10 4:29:09 PM: debug Parsing 'catchall: 0104 0000 01 01 0140 00 4631 00 00 0000 0A 00 0A413332’
6aadb3c0-a6d7-487b-bb37-81a23fda3c10 4:29:08 PM: debug F-One was
6aadb3c0-a6d7-487b-bb37-81a23fda3c10 4:29:08 PM: debug
6aadb3c0-a6d7-487b-bb37-81a23fda3c10 4:29:08 PM: debug
6aadb3c0-a6d7-487b-bb37-81a23fda3c10 4:29:08 PM: debug Parsing 'catchall: 0104 0000 01 01 0140 00 4631 00 00 0000 0B 01 0A00’
6aadb3c0-a6d7-487b-bb37-81a23fda3c10 4:29:05 PM: debug F-One was
6aadb3c0-a6d7-487b-bb37-81a23fda3c10 4:29:05 PM: debug
6aadb3c0-a6d7-487b-bb37-81a23fda3c10 4:29:05 PM: debug
6aadb3c0-a6d7-487b-bb37-81a23fda3c10 4:29:05 PM: debug Parsing 'catchall: 0104 0000 01 01 0140 00 4631 00 00 0000 0B 01 0A00’
6aadb3c0-a6d7-487b-bb37-81a23fda3c10 4:29:04 PM: debug Executing ‘alarm test’

but still unable to show the results of this button push on the Arduino Debug console.

I tested the hardware serial port on the Leonardo by connecting an FTDI USB cable to TTL serial and transmitting and receiving characters from a terminal program to and from the Arduino, using a Serial port sketch, and using Serial1 as the hardware port, so I am confident the hardware on the Arduino is running OK,

the catchall parsing statements after the "debug Executing ‘alarm test’ are both the same assuming this is the info for “on” and “off”

Any assistance would be appreciated

The Leonardo doesn’t have any more memory than the Uno, which is really pushing it from a memory perspective. As cheap as they are, I recommend picking up an Arduino Mega. That should have plenty of memory and you won’t have to worry about that.

-Todd

2 Likes

Hi Todd, I fully understand this, Dan’s coding is very elegant, but in my case I started with
code from jodyalbritton’s JodyThing project, and from CHRISTOPHER SCORDINSKY’s programming.

My Arduino sketch, with three sensors, all I2C, with a local LCD compiles as follows

Sketch uses 19,826 bytes (69%) of program storage space. Maximum is 28,672 bytes.
Global variables use 1,319 bytes (44%) of dynamic memory, leaving 1,241 bytes for
local variables. Maximum is 2,560 bytes.

I donot think memory is the issue

I am able to send 3 pieces of data to Groovy Device Handler, and have it show up properly, sort of , on valueTiles on my smartphone.
For Android 2.14 I could not create multiline text on the valueTiles, or use lower case characters.
I just saw that 2.15 has just been released, but no mention of multiline text.

My problem is that I cannot send a command from the phone to the Arduino.

I confirmed that the Arduino’s hardware serial port is working properly,

I am not convinced that the shield is receiving data properly,
When powered up with the arduino code used by Christopher, as shown

//*****************************************************************************
void setNetworkStateLED()
{
SmartThingsNetworkState_t tempState = smartthing.shieldGetLastNetworkState();
if (tempState != stateNetwork)
{
switch (tempState)
{
case STATE_NO_NETWORK:
if (isDebugEnabled) Serial.println(“NO_NETWORK”);
smartthing.shieldSetLED(2, 0, 0); // red
break;
case STATE_JOINING:
if (isDebugEnabled) Serial.println(“JOINING”);
smartthing.shieldSetLED(2, 0, 0); // red
break;
case STATE_JOINED:
if (isDebugEnabled) Serial.println(“JOINED”);
smartthing.shieldSetLED(0, 0, 0); // off
break;
case STATE_JOINED_NOPARENT:
if (isDebugEnabled) Serial.println(“JOINED_NOPARENT”);
smartthing.shieldSetLED(2, 0, 2); // purple
break;
case STATE_LEAVING:
if (isDebugEnabled) Serial.println(“LEAVING”);
smartthing.shieldSetLED(2, 0, 0); // red
break;
default:
case STATE_UNKNOWN:
if (isDebugEnabled) Serial.println(“UNKNOWN”);
smartthing.shieldSetLED(0, 2, 0); // green
break;
}
stateNetwork = tempState;
}
}

the big LED on the Shield always turns to a Green color, indicating an :UNKNOWN" state
yet it still transmits correctly with a proper Smart Phone Valuetile display.

I put a pair of oscilloscope probes on the TXD, and RXD lines coming off the Arduino Shield

The Blue trace is the data being sent to the Shield from the Arduino, in this case the payload is “A37”

The red trace, I was surprised to see, is on the Arduino’s RXD line

I have looked at the Smartthings.h and .cpp files trying to determine the baudrate between the Arduino and the Smartthings Shield, I could not find and numbers. Anyone know the baudrate between the Arduino and the Shield?

I loaded the “stLEDwithNetworkStatus.ino” file and added

_#include <Wire.h>
_#include <LiquidCrystal.h>
_#include <TKLCD.h>
_#include “Adafruit_SHT31.h”
_#include <avr/pgmspace.h>
_Adafruit_SHT31 sht31 = Adafruit_SHT31();

_TKLCD_Local lcd = TKLCD_Local(); // when programming a TKLCD module itself

//*****************************************************************************
// 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
//*****************************************************************************
_#define PIN_LED 5

// this transmit to phone 05/31/16 4:53 pm
_#define PIN_THING_RX 0 // RX for Leonardo on TKLCD
_#define PIN_THING_TX 1 // TX for Leonardo on TKLCD

The underscores are to prevent this page from going bonkers with the Include # signs

The loop is

//*****************************************************************************
void loop()
{
// run smartthing logic
smartthing.run();
setNetworkStateLED();
Serial.println(“In the Loop”);
delay (5000);

}

The Arduino Debug Monitor shows a column of “In the Loop”

There is no Arduino data being transmitted, except what
smartthing.run(); and setNetworkStateLED(); create.

The oscilloscope waveform looks like this

Someting is being transmitted, and something is being received ( I have no idea as to what )

The last function looks like this, added some serial println for the Arduino Debug screen

//*****************************************************************************
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(“on”))
{
Serial.println(“on”);
on();
}
else if (message.equals(“off”))
{
Serial.println(“off”);
off();
}

}

The groovy code I have loaded has the ability to send the text “on” and “off”

While the above arduino code is running every 5 seconds, I get the oscilloscope wave form as above, but when I push the Test button Time on the Smart phone, to send a text message of “on” and “off” I get the following waveform

The added red I presume is the text being sent from the Groovy program, to the Shield, and into the Arduino.

So we are receiving something from the groovy program, whay is not showing up on the Arduino Debug screen?

Also, the Big LED on the Smart Things shield comes up Green.

If I knew the serial protocol used between the Arduino and the Shield, I may be able to use the scopes RS232 decoding to see what was being transmitted to the Arduino.

Any assistance would be appreciated

Ben

Ben,

So… Which SmartThings library are you using? The “official” one directly downloaded from SmartThings.com? Or the one I created, which enables the use of Hardware Serial UARTs on the Arduino MEGA?

In either case, I would recommend you try using SoftwareSerial communications on the Leonardo to get things started. Please be sure to add a wire jumper between pins 10 and 3 on the Leonardo, as the Leonardo’s PIN3 does not support HW interrupts required for Receiving Data.

Also, I am not familiar with the I2C communications… BUT if it also requires HW interrupts to function, you may have an interrupt conflict.

Please remove all of your hardware from the Leonardo except the ThingShield (with switch set to D2/D3) and a jumper between pins 10 and 3 . Then, load up one of the standard example sketches, and modify it to use PIN 10 for Rx instead of Pin 3. Also, use one of the standard example Groovy Device Handlers. If it works as expected, try adding your additional HW one by one until you figure out what is causing the conflict.

The really nice thing about the Arduino MEGA is that it has 3 additional HW UARTs, which really comes in handy to prevent conflicts like this.

I helped another user who was trying to use the ThingShield along with a RS-232 shield. Both were trying to use the same HW interrupt for the SoftwareSerial library. He ended up buying an Arduino MEGA. I have had very good luck with SainSmart Arduino MEGA clones from eBay for less than $15.

Dan

@BenB2016

Also, I just looked at your sketch… You cannot have all of the delay() statements in the main loop, especially not the 9 second delay at the end. The SmartThings.run() must be executed basically continuously, otherwise you will overflow the Receive Buffer from the ThingShield. Instead, simply measure time differences to determine whether or not to execute certains parts of your code.

Even better, just use ST_Anything as your starting point, and simply add in a few new classes/objects to handle your new sensor types. ST_Anything already takes care of scheduling and performing all of the updates for sensors, whether they be polled periodically (e.g. a temperature sensor) or continuously (e.g. a digital input for a contact sensor.)

ST_Anything is a framework that my son and I have always hoped others would simply add new sensor classes to.

One more note - we never have had a Leonardo, so I have no idea whether or not our ThingShield Arduino library is compatible or not!

Dan