0

HTTP GET to Retrieve and Save Content locally...



Hello,

Situation:

Using HTTP GET, via script, how do you store images locally on the Brightsign's USB Jump Drive to recall, via script, at a latter time.

Thanks,


Matt

12 comments

  • 0
    Avatar
    RokuLyndon


    The object reference guide covers how the roURLTransfer object works. This is what you would use for doing file downloads.



    You can use the GetToFile or AsyncGetToFile command to download a file.



    For a script like you describe, you would need to write a custom script.



    REM sample code

    REM This creates the transfer object, and sets the location of the files



    file_downloaded = false

    imageplayer = CreateObject("roImagePlayer")

    tempURL = "http://192.168.0.1:111/images/"

    xfer = CreateObject("roUrlTransfer")

    xfer.SetUrl (tempURL)





    REM To download a file, you need to specify the file you want to grab

    REM and the file you want the unit to write it to.



    filename = "image1.jpg"

    xfer.SetURL(tempURL + filename)



    REM Now, the URL we're going to grab is:

    REM "http://192.168.0.1:111/images/image1.jpg"



    ok = xfer.GetToFile(filename)

    if ok = 200 then

      file_downloaded = true

      print "file downloaded successfully"

    endif



    REM GetToFile returns 200 if it was able to successfully download the file.



    if file_downloaded then

        imageplayer.DisplayFile(filename)

    else

        print "No Image Downloaded."

    endif



    REM infinite loop at end of script

    while true

    sleep(1000)

    end while



    This code downloads one image, and if that image downloads successfully, it plays it.
  • 0
    Avatar
    tmloving


    How do you store the file locally to USB Drive?
  • 0
    Avatar
    RokuLyndon


    If all you have connected is the USB drive, then that's where this will be stored.
  • 0
    Avatar
    acalleja


    Hi! This is Alvaro from Spain.



    I've tried the "GetToFile" method and it works ok...my question is:

    Is there a way to retrieve files from the HD1010 remotely?



    Thanks in advance,

    Alvaro
  • 0
    Avatar
    RokuLyndon


    Hi,



    Not currently.
  • 0
    Avatar
    Dick Trump


    Rather than opening a new subject line, my question is related enough that I'll tack it on here.



    I have a project that will need to gather some data into a text file from a touchscreen with embedded controller that includes a web server that allows access to a file storage area.  That controller will also be controlling content to be played back on a separate monitor from a Brightsign HD1010, either through network or serial control.



    My question is twofold:



    Is it feasible to use the technique described in this thread to grab the text files from the web server, store them on a removable USB drive while still playing content from the SD card?



    Assuming that is possible, do I need to completely write my own interactive script to handle both the file grabbing AND the control of playback from the CF card?  Or can I use standard authoring procedures to handle the playback functions?



    Thanks



    Dick
  • 0
    Avatar
    RokuLyndon


    Yes, you can use this method to grab a text file.  It might be easier to write a script to do this than trying to add this functionality to the existing autorun.



    There are built-in text manipulation funtions. So, you can grab it, then read the file into the script, and then process it line by line. If you explain a little more about how this will work, I'll check for sample code.
  • 0
    Avatar
    Dick Trump


    I don't need the Brightsign to act on the text file other than retrieving it from the web host device and putting it on the removable USB drive.  So again, the two issues are:



    1.  Having this removable storage at the same time content plays from the SD card



    2.  Having the retrieve and storage process independent of the interactive control script.



    There is one other possible need which would be to also have the HD1010 update itself from a different web server.  I don't know that this would be needed and it wouldn't kill the project if it wasn't possible.



    Dick[/b]
  • 0
    Avatar
    RokuLyndon


    Yes to 1 and 2.



    You can do a gettofile that saves the file to the USB. The following would download the text file to the USB drive every 5 minutes. If you didn't want to overwrite it, you could generate the name each time through the loop.





    p = createobject("roMessagePort")

    st=CreateObject("roSystemTime")

    timer=CreateObject("roTimer")

    timer.SetPort(p)







    REM create URL object, and set the URL of the file to grab

    rssXfer2 = CreateObject("roUrlTransfer")

    rssXfer2.SetUrl("http://www.brightsign.biz/downloads/ba/resources.txt")





    REM Download the text file

    download_text_file:

    ok=rssXfer2.GetToFile("USB1:/file.txt")

    REM you can also do an AsyncGetToFile



    if not ok then print "Unable to get file"





    REM Set a timer for the next time to download file

    REM In this case 5 minutes.

    timeout=st.GetLocalDateTime()

    timeout.AddMinutes(5)

    timer.SetDateTime(timeout)

    timer.Start()



    msg = wait(0,p)

    if type(msg) = "roTimerEvent " then goto download_text_file
  • 0
    Avatar
    Dick Trump


    Great!   Thanks.



    I have to admit that I haven't really dug into brs syntax that much and it is unclear to me whether any brs script completely supercedes the scripts that run from the firmware.



    Maybe if my customers would quit bothering me with jobs, I could get some work done.  <!-- s:) --><img src="{SMILIES_PATH}/icon_smile.gif" alt=":)" title="Smile" /><!-- s:) -->



    Dick
  • 0
    Avatar
    RokuLyndon


    If you were to put a script named autorun.brs on the flash card, of the newer models, it overrides what's in memory.



    But, the code sample I posted can be added into the autorun that's in memory. You can download and edit that autorun, and then place it on the flash card. It will override what's in memory.



    Or, I have script you can use to put a new autorun in memory.



    For example, the normal autorun already has a message port object it uses, and already has a function that waits for events.



    So, we would need to add the url event, add the timer definition, set the message port object that's used already, and insert the code with the file download under the function that processes events. Both standard playlists(waitforbspevent) and internactive playlsts (waitforcsvevent) have a function that process all events.



    It depends on how often you want to grab the file. WE could skip the timer altogether grab the file once through playlist or when a specific file is played.  You can insert this behavior.
  • 0
    Avatar
    Dick Trump


    Thanks



    That gives me enough to go on for the moment.  This job is still speculative but I wanted to make sure the concept could be pulled off before defining the rest of the hardware in the system.  I'm trying to avoid having a Windows based computer in a system that will travel to different sites, have varying connectivity and be subject to getting bounced around in transit.  If I can do everything with embedded controller's, I'm a lot more confident that will be running 3 or 6 months down the road.



    Dick
Please sign in to leave a comment.