Results 1 to 9 of 9

Thread: readout time from file and run a script at this time

  1. #1
    Join Date
    Oct 2005
    Posts
    25

    Default readout time from file and run a script at this time

    Hello,

    I am not sure if this is possible. My Weatherstation write down all the information in a file. The period of writing down to file depends on the windspeed and can change every time. The next file update time is written down to the file. So i want read out this time and give it to girder and say girder at this time run my script.

    I hope someone understand my intend

    Leroy

  2. #2
    Join Date
    Jul 2005
    Location
    Uithuizen, The Netherlands
    Posts
    575

    Default

    hi,

    I would actually recommend using Girder's folderwatcher function to watch for changed files.
    This way an event is generated every time the file is updated.

    hope this helps

  3. #3
    Join Date
    Oct 2005
    Posts
    25

    Default

    That's it, thank you. But can you explain me what is wrong on my code?

    function watchfunc()

    local currdat = {}
    local file = io.open("C:/Programme/HeavyWeather/currdat.lst","r")
    local content = file:read("*a") .. '\n\n'
    file:close()
    time = string.sub (content, 387, 394)

    for section, data in string.gfind(content, '%[(.-)%]\n(.-)\n\n') do
    currdat[section] = {}
    for item, value in string.gfind(data, '(.-) = \"(.-)\"\n?') do
    currdat[section][item] = value
    end
    end

    NetRemote.SetVariable('time', time)
    NetRemote.SetVariable('intemp', currdat.indoor_temperature.deg_C)
    NetRemote.SetVariable('outtemp', currdat.outdoor_temperature.deg_C)
    NetRemote.SetVariable('windspd', currdat.wind_speed.kmh)
    NetRemote.SetVariable('rain24', currdat.rain_24h.mm)
    NetRemote.SetVariable('rain1', currdat.rain_1h.mm)
    NetRemote.SetVariable('press', currdat.pressure_relative.hpa)


    end

    watcher = win.CreateFolderWatcher([[C:\Programme\HeavyWeather\]], watchfunc, 32, 1)
    watcherrint(time)

    I get a new variable "time" but not at the moment, the file changes

  4. #4
    Join Date
    May 2004
    Location
    Cardigan, UK
    Posts
    9,278

    Default

    Not sure what you mean by :-
    I get a new variable "time" but not at the moment, the file changes
    Is your watchfunc being called?
    --Rob

  5. #5
    Join Date
    Oct 2005
    Posts
    25

    Default

    Yes, the watchfunc is being called, so i get a new value to my variable time. If the file was changed on 22:00, I should get the result within a few seconds on my PPC running Netremote as a refreshed variable. I get the refreshed variable, but it could be 22:59 or 23:15 till I get the new result on my netremote client. Is this a normal working period of netremote and girder or could be something wrong with my script. I know my problem is a little bit strange, but i can't explain it better to you.

    Leroy

  6. #6
    Join Date
    May 2004
    Location
    Cardigan, UK
    Posts
    9,278

    Default

    That does sound odd - I would expect it to work within a couple of seconds. What OS are you running on the Girder PC?
    --Rob

  7. #7
    Join Date
    Oct 2005
    Posts
    25

    Default

    I am running Win XP home on the girder machine. I try to explain the problem again. I build a skin on my netremote device looking like this:

    10:21:34 ---> actual time (NR.clockTime)

    10:22:00 ---> the variable 'time' shown in the code I wrote

    This show me that the next update of the file, watcherfolder is looking for, will be updated at 10:22:00.
    So I should see the new updated time when the actual time is around 10:22:00 (+/- a few seconds).

    In my case it looks like this:

    10:22:56

    10:22:00

    then the variable is updated. Why isn't it updated at that time the file changes.

    I hope this explanation is more clear.

    Leroy

  8. #8
    Join Date
    Oct 2005
    Posts
    25

    Default

    It works !!!!! But i don't know why. I changed this:

    watcher = win.CreateFolderWatcher([[C:\Programme\HeavyWeather\]], watchfunc, 32, 1)
    watcherrint(time)

    to this:

    watcher = win.CreateFolderWatcher([[C:\Programme\HeavyWeather\]], watchfunc, 64, 1)

    Now it works perfect. :-)

  9. #9
    Join Date
    May 2004
    Location
    Cardigan, UK
    Posts
    9,278

    Default

    Looks as though it creates the file from scratch each time in that case, rather than opening it read/write.
    --Rob

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •