Just an FYI this code is great but XIVELY wont report data accurately unless you alter it slightly.
That is to fast for Xively to properly GRAPH the data. So your method will report the data to Xively but it is to fast to graph it. For those who want to use Xively’s graphing tools change 1000 to 5000. Perhaps I am the only one who uses graphing in Xively but wanted to share in case it might help another.