Xively charts in Corona demo

20 replies [Last post]
garrydwilms
Offline
United Kingdom
Joined: 31 Mar 2011

All,

I have spent the last few days putting together this proof of concept, hope its of use.

Its very rough and needs tidying but seems to work. Its labelled scene4.lua so can be included easily in Brett's multiscene demo.

Just amend the feed ID and labels in the code to suit.

NOTE: It uses the label index number in the pickerwheel to load the correct graph so its important the labels are entered in order numerically within the labels table, i.e. entry 1 relates to xively datastream 0, etc.

v02 will include a second column in the picker wheen to select chart time span.

Cheers,

Garry.

EDIT: v02 including chart time span added.

AttachmentSize
scene4.lua2.9 KB
brett
Offline
Providence, United States
Joined: 9 Jan 2010
That' pretty cool

I made some changes to Xively embedded graph scene to clean up some warts.

Brett

AttachmentSize
scene4.lua 4.47 KB
mark_baldwin
Offline
Blackburn, United Kingdom
Joined: 19 May 2012
Nice work Garry

Nice work Garry but I'm having trouble getting it to run. In terminal I get the following error

 

Corona Simulator[11076:707] httpAddress http://api.xively.com/v2/feeds/1740545434/datastreams/100.png?duration=6... House&b=true&g=true

Corona Simulator[11076:707] Invalid Parameter: URL argument was malformed URL

It doesn't look malformed to me and if I copy/paste into browser, up pops the requested graph

 

EDIT:

It seems Corona doesn't like spaces in the URL. Substituted for  _ and hey presto so I've used string.gsub(httpaddress, "%s+", '%%20') to replace spaces with %20 before passing the url

brett
Offline
Providence, United States
Joined: 9 Jan 2010
added to xapMultiScene demo (SVN)

Gary

I checked my modified version of your prototype code into the SVN repository as "Page 4" of the xapMultiScene demo.  I credited you in the header comments.   If this is your work you should remove my name !

Thx for that.

garrydwilms
Offline
United Kingdom
Joined: 31 Mar 2011
Thanks Mark

Thanks Mark, Spotted something was a miss when installed on device, not had chance to investigate so cheers. funny how it worked great on the simulator for me though?

 

Brett,

thanks for the rework, much more professional. 

 

Proper team effort heh!

Garry

mark_baldwin
Offline
Blackburn, United Kingdom
Joined: 19 May 2012
I wonder why it threw an

I wonder why it threw an error in my Corona simulator?

garrydwilms
Offline
United Kingdom
Joined: 31 Mar 2011
Strange hey

Anyhow you've fixed the bug so cheers.

Brett, can you add the gsub to switch spaces to %20 as spotted by Mark into Repo?

Thanks,

Garry.

mark_baldwin
Offline
Blackburn, United Kingdom
Joined: 19 May 2012
oh heck, now I'm back to

oh heck, now I'm back to blank screen then quit on the tablet, (works fine in simulator) time to dig deeper

EDIT:

Sorted, looks like my quit button was triggering on launch

garrydwilms
Offline
United Kingdom
Joined: 31 Mar 2011
This works great for me on

This works great for me on the tablet.

httpaddress = string.gsub (httpaddress, " ", "+")

looks like all handling spaces differently?!

G.

mark_baldwin
Offline
Blackburn, United Kingdom
Joined: 19 May 2012
I didn't try it on the

I didn't try it on the tablet, it wouldn't run on Corona simulator. Tablet may have been ok. Maybe my version of Corona is different as I'm using the OS X version. I got the malformed URL message in terminal as mentioned above.

All good now. 

Thanks for the work Garry and Brett

brett
Offline
Providence, United States
Joined: 9 Jan 2010
We should be able to escape

We should be able to escape nasty content using the url.escape() function.

http://w3.impa.br/~diego/software/luasocket/url.html

local url = require("socket.url")

local httpaddress= "http://api.xively.com/v2/feeds/"..xivelyFeed.."/datastreams/"..datastreamNumber..".png?duration="..datastream[2].value.."&w="..graphBounds.width.."&h="..graphBounds.height.."&title="..url.escape(datastream[1].value).."&b=true&g=true"

Brett

mark_baldwin
Offline
Blackburn, United Kingdom
Joined: 19 May 2012
I tried that but I used it on

I tried that but I used it on the whole httpaddress string and it made a bit of a mess :) I didn't think to use it on JUST the label

EJ-Ambient
Offline
Ringwood, United Kingdom
Joined: 5 Aug 2011
Can't see graphs

Hi Brett... thanks to you and Garry for all this work....

I've downloaded the lua (above) and edited the line

local ui = require "hahlib.interface.ui"
to
local ui = require "ui"

Then added it in as scene4 in the demo...but when I click on Page 4 and click the 'New Graph' button
the spinner covers the button and I can spin both reels, but no graph appears! Am I supposed to see
a graph of Garry's data? and how do I remove the spinner and get back to the 'New Graph' button?

Hope this makes sense...

regards...from a very wet and windy New Forest, UK....

EJ
mark_baldwin
Offline
Blackburn, United Kingdom
Joined: 19 May 2012
Hi EJHave you added YOUR feed

Hi EJ

Have you added YOUR feed ID? Or are you just trying it with Garry's data?

EJ-Ambient
Offline
Ringwood, United Kingdom
Joined: 5 Aug 2011
As is

Hi  Mark

 

I've just put the scene4.lua in As Is with Garry's data....cheers.

mark_baldwin
Offline
Blackburn, United Kingdom
Joined: 19 May 2012
Have you edited the lines as

Have you edited the lines as Brett's post above?

If you don't the URL is malformed and causes a problem with corona simulator

 

local url = require("socket.url")

local httpaddress= "http://api.xively.com/v2/feeds/"..xivelyFeed.."/datastreams/"..datastreamNumber..".png?duration="..datastream[2].value.."&w="..graphBounds.width.."&h="..graphBounds.height.."&title="..url.escape(datastream[1].value).."&b=true&g=true"

 

EJ-Ambient
Offline
Ringwood, United Kingdom
Joined: 5 Aug 2011
Done

Hi Mark

I've done that - still no joy....as per my previous post, the Spinner covers the New Graph button and I can spin the rollers but no graph appears and I can't get back to the new Graph button!!!!!

I noticed that Brett mentioned an SVN repository...and that he's included Scene4 there - how do I access this repository? Is it any different than the .lua on this forum?

Any help greatly appreciated...

Elliot

mark_baldwin
Offline
Blackburn, United Kingdom
Joined: 19 May 2012
SVN is here

http://livebox-hah.googlecode.com/svn/trunk/userapps/HAHCorona

EJ-Ambient
Offline
Ringwood, United Kingdom
Joined: 5 Aug 2011
Spoke with Garry

Thanks Mark...spoke with Garry off-forum and he sorted me out...with one minor glitch/feature still outstanding! So, all good at the moment and thanks for pointing me at the SVN....EJ

AndrewJ
Offline
United Kingdom
Joined: 22 Nov 2012
Thanks to all, nice Xively

Thanks to all, nice Xively graphs added to my app now :)

mark_baldwin
Offline
Blackburn, United Kingdom
Joined: 19 May 2012
Corona Xively graphs tweak

First of all a big thanks to Garry for the initial code.

I had an issue with the way I used the Xively feeds. I don't use consecutive numbers for my feeds so I had to add another table to index my feeds against the picker wheel selections.

In my pickerwheel I have 

local streamIDs = { "Whole House", 

"Lounge Temp", "Lounge Moved", "Lounge Light",

"Kitchen Temp", "Kitchen Moved", "Kitchen Light",

"Hallway Temp", "Hallway Moved", "Hallway Light",

"Utility Temp", "Utility Moved", "Utility Light", "Utility Humidity",

"Landing Temp", "Landing Moved", "Landing Light", "Landing Humidity", 

"Bedroom Temp", "Bedroom Moved", "Bedroom Light", "Bedroom Humidity", 

"HAH Hub(TV)", "BB iMacs", "Lounge TV",

"WH Outside Temp", "WH Inside Temp", "WH Humidity Outdoors", "WH Air Pressure", "WH Wind Avg", "WH Wind Gust", "WH Rain", "WH Data Rate",

"Mark Presence", "Liz Presence",

"Gas Pulses", "Gas Temp"

  }

If you add your feed IDs like this to the 'graphload' function

local feedIDs = {

"100",

"101", "102", "103",

"104", "105", "106",

"107", "108", "109",

"110", "111", "112", "113",

"114", "115", "116", "117",

"118", "119", "120", "121",

"130", "131", "132",

"140", "141", "142", "143", "144", "145", "146", "147",

"150", "151",

"160", "161"

then use the following 

local httpaddress=("http://api.xively.com/v2/feeds/"..xivelyFeed.."/datastreams/"..feedIDs[datastream[1].index]..".png?duration="..datastream[2].value.."&w="..graphBounds.width.."&h="..graphBounds.height.."&title="..url.escape(datastream[1].value).."&b=true&g=true&s=1")

the feed ID will be substituted for the index from the picker wheel.

I know it's a little contrived but I'm sure Brett will come up with a pretty way to do it ;)

Hardware Info