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:
    117
    Likes Received:
    13
    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.
  2. impact

    Trevor

    Joined:
    Nov 22, 2018
    Messages:
    298
    Likes Received:
    22
    Location:
    Melbourne Victoria
    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
  3. impact

    impact

    Joined:
    Feb 10, 2008
    Messages:
    117
    Likes Received:
    13
    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
  4. impact

    tassiebean

    Joined:
    Dec 24, 2018
    Messages:
    30
    Likes Received:
    6
    Hi Impact,

    You need to create an object for your weather image display. In the Visualisation screen you will see a box for "Additional Icons". You can set an icon (image) for any value of the object. If you have 6 weather images, assign them to values 1 to 6. Set the object to be Display Icon Only, and Read Only (so nothing happens if someone touches it). Changing the value of the object in your script to the values 1 to 6 magically changes the icon image to your beautiful weather icons. Size the images/icons to suit your display. Have fun!

    Cheers, TB
     
    tassiebean, Jul 4, 2019
    #4
  5. impact

    impact

    Joined:
    Feb 10, 2008
    Messages:
    117
    Likes Received:
    13
    TB you may be a master... and I am so low down on grading scale - Not sure on how this would be done...

    I understand how a script could just increment and change an object property from 1 through 6 - love that idea. That's so simple... but in the SHAC world I am still a newbie and not sure of all the context your referring to...

    You say I need to create an Object... Is that under the object tab ? What kind of object is it - a user parameter or unit parameter - or are you referring to something else... I have created user parameters and manipulated them to show date, time, temperature amongst other things - but I do not see anything about showing an image when creating an object - so not sure how that is done....

    Your next point is on the Visualisation screen you will see a box for 'additional icons'... I am not sure where the additional icons box is... I must be so blind... Certainly I can go to the Vic. graphics tab and that would allow me to Add Icons... I could then use these in visualisation and possibly cycle them.

    But that questions me - how would I then obtain an image from an external source somewhere to store it here...

    SO I like what you say, I can see most of it in theory - but I am struggling to fully understand it...

    What will it take - a slab of beer or bottle of scotch.... I want to learn more master! Please give me some more info!
     
    impact, Jul 6, 2019
    #5
  6. impact

    impact

    Joined:
    Feb 10, 2008
    Messages:
    117
    Likes Received:
    13
    OK TB - I am a step further... I find 'additional icons' So I can see how it would work a bit better... Its just like having an icon on alight or fan or something that dims or picks up speed showing low through to high...

    Got that bit - and I can see how to change the value in the script... That bits all good...

    But how would I write a script to obtain the images from an external web source and place them where in the SHAC, so that they could be used.... You do realise that these are radar images that there is a new one every 6 minutes to cycle through....

    I have found how to write scripts to get external data - so I can find the filename needed to obtain - but how do I store that from a script where... or what properties can I use on an object to point to an external image....
     
    impact, Jul 7, 2019
    #6
  7. impact

    tassiebean

    Joined:
    Dec 24, 2018
    Messages:
    30
    Likes Received:
    6
    You are right. I thought you were using static images - sunny, cloudy, rain, showers, etc. Great work on your other thread!
     
    tassiebean, Jul 13, 2019
    #7
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.