Page 1 of 1

Want updating temp.

Posted: Mon Jan 27, 2003 12:49 pm
by fourbit
I want to put a temp and time "reader board" like what is on some banks etc. on a page. But I need it to update every minute or so. Is it possible?

And before I get a bunch of "Yes" or "no" 's and that's all, :P the most important thing is how to do it?

Thanks,
Paul

Posted: Mon Jan 27, 2003 1:40 pm
by Stoker
everything is possible..

where will you be getting the temperature from? You can do it three ways, you can get the data from the sensor/device in realtime when a page is requested, you can create a cron-job (schedule) to pull the temperature from some service every X minutes, or you can have the device/probe/service upload the value every X minutes..

Perhaps you want to use one of the services from weather.com?

Current time is very easy <?php echo date('H-m-s'); ?>

Posted: Tue Jan 28, 2003 6:16 am
by lazy_yogi
would you mind explaining how each of these work briefly.
If any can update in real time .. that'd be great

(the only way i know how to do that right now is to set a refresh every x seconds which I'd prefer to avoid if possible .. it gets annoying)

For example, would it be possible to have a digital clock that actually upadated it's time every time it changed (ie every second) without reloading the whole page every second

Cheers

Posted: Tue Jan 28, 2003 7:56 am
by Stoker
oh, a fourth way which is sort of derived from method 1, as you indicated, automatic updating after page loaded, I guess that was probably the question to begin with...

If you want continuesly updating real-time values you would need to use a java-applet or something like that, using a socket connection to your server (Java applet security would strict the connection to the server it was downloaded from).
For reloading/updating partial content you can use JavaScript and layers, for a text-only clock javascript should be fine.
As for a clock/time/countdown there are already some of those out there, perhaps this page has one you like, otherwise just search around...
As for temperature, it really depends on where the value is coming from, you could potentially put a sensing device on your howm machine or server and upload/push the value to your webserver every X minutes..

My first mentioned "method" of "real-time" was to get the value from the sensing device/service at the time of page requested, could be done either server side or client side depending somewhat on where you are getting the values from.

A scheduled "pull" method would be serverside on your site, a cron-job, running a script every X minutes that fetches the value from some service/device and stores in a file on your site..

A scheduled "push" method would be 3-tiered-serverside, the device/system that measures will upload the value to your server, which in turn serves the web pages/values to the world. This would be a typical approach if you have a sensing device at home, much like many web-cam softwares can do, upload every X minutes..

Posted: Tue Jan 28, 2003 10:47 am
by DaZZleD
for a real tiome clock, use Javascript to make one and customize it as you wish.
main idea is make a layer with a text in it (the time) or a picture, or an iframe that gets updated every second with the javascript setInterval('function',1000) command.

Posted: Tue Jan 28, 2003 5:50 pm
by lazy_yogi
I haven't used javascript at all, so no idea how to use it.

but I currently have a chat board with the messges in an frame below a textare that is where messages are typed. It (the frame) is updated every 5 seconds for new messages by refreshing the frame every 5 seconds.

you can see it at http://www.chat.eli.uni.cc/
it seems ok when u see it briefly, but when u use if for a while ... that refresh can bother some ppl (so I'm told)

Is your javascript setinterval() function the same thing ?
cuz refreshing every second will get even more annoying to users than every 5 seconds ..

cheers

Posted: Wed Jan 29, 2003 6:48 am
by DaZZleD
nope... it's a function that calls another function (given as the first argument) every n(given as second argument) milliseconds.

you have to create a new Date type object inside a javascript tag with the server time at the moment the page is loaded (that can be done using the php date function). once created this object, all you have to do is to use setInterval('update()', 1000) to call the function update() ever second.
inside update() you modify a layer's inner text like this:
document.all.layerContainingTimeName.innerText = current_time;
where current_time is made by concatenating the hour, minute and second of the new date object you just created.

ofc you can always forget about creating a new date object and simply assign 3 variables (hr, min, sec) initial values with PHP's date function and inside update, increment sec (sec++;) then use a series of if clauses to see if sec=59 (meaning sec has to become 0 and minute has to be incremented) and so on. after all incrementations are done, modify the content of the time layer with the new text:
document.all.layerContainingTimeName.innerText = hr + " " + min + " " + sec;

if this still gives you trouble, let me know so i can give you a complete example. :wink:

Posted: Wed Jan 29, 2003 8:46 pm
by lazy_yogi
umm .. I don't know any javascript at all
would you mind showingme an example of a simple script that would update the time every second.

But could you make it generic so that it isn't specific to time.
For example .. say, when a html page is loaded, it displays the contents of a file. And if I wanted to check if a file has new last modified date, but only download the new contents of the file if it does have a new last modified date and otherwise leave it as it currently is in the browser.

btw .. thanks very much for your help.

Posted: Fri Feb 07, 2003 6:55 am
by DaZZleD
you cannot check the date a file was last modified using a client-side script like Javascript. a real-time clock is easy to code.
but to keep reading contents of a file and check to see if it's newer than the content being displayed you need a Java applet or a combination of server sided scripting and javascript (something like a very little frame that has a PHP code to check the date a file was last modified and that keeps reloading every n seconds with help from Javascript). if the file was modified you reload the frame that contains the data that was updating also using javascript.