Xively charts in Corona demo
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.
Attachment | Size |
---|---|
scene4.lua | 2.9 KB |
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
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.
I wonder why it threw an error in my Corona simulator?
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
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
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
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
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
Hi EJ
Have you added YOUR feed ID? Or are you just trying it with Garry's data?
Hi Mark
I've just put the scene4.lua in As Is with Garry's data....cheers.
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"
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
http://livebox-hah.googlecode.com/svn/trunk/userapps/HAHCorona
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
Thanks to all, nice Xively graphs added to my app now :)
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 ;)
I made some changes to Xively embedded graph scene to clean up some warts.
Brett