Arduino Thing Shield Device Type - How to Parse Multiple Attributes?

All,

@urman I am in the process of building a custom device type for an Arduino Thing Shield. I have the Arduino monitoring 6 doors via magnetic contact sensors and 1 DS18B20 temperature sensor. Currently, the Arduino code sends a unique command for any change in state of a door contact sensor using a command similar to:

smartthing.send("kitchenDoor closed");

Likewise, it can send a new temperature reading periodically as well. Everything is working fairly well, however I am eager to add more capabilities to the Arduino - possibly a motion detector, humidity sensor, … (you get the idea!)

In order to keep the state of all of the sensors up to date and in synch between the ST Cloud and the Arduino, I periodically issue 7 smartthing.send ("… …") commands (one for each of the 7 attributes.) This results in my device type’s parse function being executed 7 times. This process is somewhat slow, causing the Arduino to be tied up for about 7 seconds while sending the zigbee data.

Is it possible to send all of the data up to the ST Cloud at one time? Hopefully this would speed up the data transfer process significantly.

  • Is there a maximum size limit to the string sent in the smartthing.send ("… …") command?
  • What would the parse function look like if all 7 (or more) attributes were sent at one time?

Any help (or similar examples) would be greatly appreciated as I become more proficient in the ST Groovy Language. I have seen some forum post refer to returning an array of results at the end of the parse function, but I am unclear if/how this would work.

Thank you!

1 Like

I’m interested in best practices here too

You could just do it as key value pairs like:

smartthing.send("kitchenDoor=closed;motionDetected=false;humidity=75");

And the just parse it back again when a value is needed?

1 Like

Lee,

That’s exactly what I was planning to do, however I am unsure exactly how to return an array of results from the parse() routine. I would love an example of how to do this properly. Or should I call SendEvent() within parse()for each of the name-value pairs, and save one final one for the parse()'s return?

I am not a Groovy/Java programmer, so I’d really like a good code example where a device returns multiple name-values in a single zigbee update.

Thanks,

Dan