LUA Help maybe or something else...

Discussion in 'C-Bus Automation Controllers' started by impact, Mar 9, 2019.

  1. impact

    impact

    Joined:
    Feb 10, 2008
    Messages:
    95
    Likes Received:
    1
    So I have played with variables, scraped some web pages, done some logic and a few other things with this LUA... Thank god for google searches to find formats of date etc.. So I am still playing...

    However web scraping info / reformatting has got me stumped - I can think of about 3 ways to try it, but hoping for advice in advance, of the best way to do it...

    Like most people, weather is always important - and yes there is weatherzone, but the ultimate radar image is always at BOM.... and love to see it on my home screen (android tablet mounted on the wall...)

    The infamous demo page which can be seen here; https://www.cleverhome.com.au/image...C-Wiser-C-Bus-Automation-Controller-House.jpg

    Has this beautiful right hand panel - showing next birthday, top stories from a news website, and of course a weather forecast…. None look like frames - as there are no scroll bars, so the question in my mind where these just hard copy images placed there for good looks or really getting data from a website ????

    I have scraped weather from bom, and placed each into their own separate data field, formatted it to look like BOM - and therefore have current and forecast working... very inefficient - but I needed to get all the data into individual data fields so I could separate it into different lines...

    As a clue - part of the script used - simply did search and string replace...
    local http=require'socket.http'
    body,c,l,h = http.request('http://www.bom.gov.au/')
    strt = string.find(body, '<h3>Melbourne')
    b2 = string.sub(body,strt)
    strt = string.find(b2, 'val">')
    b2 = string.sub(b2,strt+5)
    ends = string.find(b2, '&deg')
    CurrentTemp = string.sub(b2,1,ends-1)

    Then I get wind direction, maximum temperate, outlook etc and populate my data fields through;
    SetUserParam(0, 1, CurrentTemp..'°')
    SetUserParam(0, 2, CurrentWind)
    SetUserParam(0, 3, 'Max '..CurrentMax..'°')

    I find that inefficient - but because I want it displayed on screen over multiple lines - there is no text box, or way to introduce a CR/LF - have not found a better way...

    Of course, Id love to just be able to set a userparam to a html string - to update text size, color and the like including paragraphs to display but not found a way to do that...

    The ultimate goal of course - is to display the rain radar... My thoughts are;
    1. Use http://m.bom.gov.au/vic/melbourne/radar/ the mobile simple site and just display it in a Frame - but thats no good, as the whole web page is displayed - I ony want the map, yes there are scroll bars to move down just to show the radar - but not friendly... So not much good

    2. Could I get access to the HTML returned, and use the scripting language to manipulate it - to remove all the headers, and just display what I want ? Doubt it... As I cant seem to find any properties for the Frame that allows interrogation / manipulation of the HTML returned....

    3. Do I do like I did above with a script using the socket as above - to get the information from BOM, manipulate the HTML - but how can I get that manipulated data to present on the screen ? No HTML data store, and the Frame operates differently - no data store, just a HTML reference....

    4. Do I play with a CSS method to try and get images to hide and display, and obtain the images the BOM FTP site - but again can I manipulate the source of an image from the scripting side...

    5. Or do I plug a small USB drive into the SHAC, use the scripting language to build my own HTML page with what I want, and just have a frame point to that mounted HTML page ?

    Or have I not thought of another way ?

    As much as I am enjoying playing with something new, the SHAC / LUA seems to be restricted a little too much - not having a multi line or HTML field to play with and display data just seems contrary to wanting to build feature rich, colourful web based pages to display...

    HELP - Point me in the right direction, so that I can continue to play, learn, and share stuff in the future!
     
    impact, Mar 9, 2019
    #1
    MarkB likes this.
    1. Advertisements

  2. impact

    Trevor

    Joined:
    Nov 22, 2018
    Messages:
    49
    Likes Received:
    1
    Hi impact,
    I was looking at the script for the BOM page and found this, within it.

    It looks like it reloads the 6 images every 10min to be displayed in the frame. Perhaps you could get these somehow and usee them.

    // Generated by /webmaster/bin/ingest/write.radar.loop.filenames.pl

    // Revised: 2019-03-23T07:50:45Z

    theImageNames = new Array();

    theImageNames[0] = "http://www.bom.gov.au/radar/IDR021.T.201903230717.png";

    theImageNames[1] = "http://www.bom.gov.au/radar/IDR021.T.201903230723.png";

    theImageNames[2] = "http://www.bom.gov.au/radar/IDR021.T.201903230729.png";

    theImageNames[3] = "http://www.bom.gov.au/radar/IDR021.T.201903230735.png";

    theImageNames[4] = "http://www.bom.gov.au/radar/IDR021.T.201903230741.png";

    theImageNames[5] = "http://www.bom.gov.au/radar/IDR021.T.201903230747.png";
     
    Trevor, Mar 23, 2019
    #2
    1. Advertisements

  3. impact

    impact

    Joined:
    Feb 10, 2008
    Messages:
    95
    Likes Received:
    1
    Trevor Thanks
    Yes there is a map you can use, and the overlays are available for each 6 minute period... The FTP server holds more than 6 if you want to have a longer loop.

    So displaying the map and then overlaying each of the png images in turn is a feasible option.

    I probably can write a script to fetch these images using http - that bit is probably the easier part...

    However the issue I think I have is more about whee to put them, not what to do with them.

    As far as I can see the SHAC has limitations in achieving what I want to do... In the Visualisation panel you can create an Object / Link / Text Label / Image / Frame / Gauge / Camera / Graph...

    So the obvious display element I would think of is an Object. But an Object can only be of certain types - Integer / date etc. and the String is limited to 255 characters - and I think that 255 characters is too limiting to do anything with - plus its an image to display not text...

    Next - Link - well that's only links to other pages, Text label - well that's just text...

    Image - can be set to local or remote. Setting it as local only allows, and is mandatory to select something from the library... remote must be http and it does not allow ftp. Even if I used it has http - I still need to write a script determine the 6 images, and have the script change the properties of 6 images that I would have defined in the visualisation, then have each hidden or shown in sequence. Two issues here - I need to display the background map and overlay sequentially each of the rain maps. First issue - images here have no transparency and not possible to overlay an image. Second issue - scripts don't seem to allow manipulation of objects in the visualisation. How do I set the property of the image to display - http path from the script... how can I get the script to hide one or another of the images...

    Best option would be Frame - it shows the content of a URL in the frame - perfect if you want the whole contents of the URL. The contents must be stored somewhere - how can a script manipulate the contents - so I either modify what was fetched... or I can write my own content - my own web page based upon logic in the script. There is no option to use a variable - only an external URL...

    Unless there are properties to these objects, that can be manipulated from a script - the only solution I can see is to write a script to get the info I need, to build a web page of the exact content I want / need - write that to a file, maybe a usb stick on the SHAC, otherwise a http server somewhere on my network - and have the Frame object point to that. Seems so inefficient !

    There must be a better way - and again I wonder how it was done in the sample picture...

    Its not only about BOM Radar - the Clipsal sample also showed news items - breaking news from somewhere - never seen a web page present it exactly like that on the web - so how was that data feed created, and presented.
     
    impact, Mar 23, 2019
    #3
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.