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.

Member for

16 years 10 months

brett

13 years 1 month ago

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

Brett

Attachments
scene4.lua (4.47 KB)

Member for

14 years 5 months

mark_baldwin

13 years 1 month ago

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=… 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

Member for

16 years 10 months

brett

13 years 1 month ago

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.

Member for

15 years 7 months

garrydwilms

13 years 1 month ago

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

Member for

14 years 5 months

mark_baldwin

13 years 1 month ago

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

Member for

15 years 7 months

garrydwilms

13 years 1 month ago

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.

Member for

14 years 5 months

mark_baldwin

13 years 1 month ago

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

Member for

15 years 7 months

garrydwilms

13 years 1 month ago

This works great for me on the tablet.

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

looks like all handling spaces differently?!

G.

Member for

14 years 5 months

mark_baldwin

13 years 1 month ago

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

Member for

16 years 10 months

brett

13 years 1 month ago

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

Member for

14 years 5 months

mark_baldwin

13 years 1 month ago

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

Member for

15 years 3 months

EJ-Ambient

13 years 1 month ago

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

Member for

14 years 5 months

mark_baldwin

13 years 1 month ago

Hi EJ

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

Member for

15 years 3 months

EJ-Ambient

13 years 1 month ago

Hi  Mark

 

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

Member for

14 years 5 months

mark_baldwin

13 years 1 month ago

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"

 

Member for

15 years 3 months

EJ-Ambient

13 years 1 month ago

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

Member for

15 years 3 months

EJ-Ambient

13 years 1 month ago

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

Member for

13 years 11 months

AndrewJ

12 years 12 months ago

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

Member for

14 years 5 months

mark_baldwin

12 years 6 months ago

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 ;)

scene4.lua (2.9 KB)