PDA

View Full Version : readout time from file and run a script at this time



Leroy19
May 31st, 2007, 10:36 AM
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

blubberhoofd
May 31st, 2007, 02:24 PM
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 ;)

Leroy19
June 1st, 2007, 08:31 AM
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)
watcher:print(time)

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

Rob H
June 1st, 2007, 11:26 AM
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?

Leroy19
June 1st, 2007, 03:03 PM
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

Rob H
June 2nd, 2007, 12:19 AM
That does sound odd - I would expect it to work within a couple of seconds. What OS are you running on the Girder PC?

Leroy19
June 2nd, 2007, 12:38 AM
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

Leroy19
June 2nd, 2007, 04:23 AM
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. :-)

Rob H
June 2nd, 2007, 07:47 AM
Looks as though it creates the file from scratch each time in that case, rather than opening it read/write.