View Full Version : Get variables into an HTTP page?
Todd Reed
March 14th, 2007, 08:03 AM
I use the following script to get two of my Ocelot variables, and OSD them, and write them to a text file.
Ocelot:GetVariables(function()
filedirectory = "c:\\My Documents\\"
filename = "OcelotTempLog.txt"
saveasname = filedirectory .. filename
fout = io.open(saveasname,'a+')
local data={}
airtemp=ADI.Var[8]
h2otemp=ADI.Var[7]
osd.StatusMessage("Air = "..ADI.Var[8] .."\n".."Water = "..ADI.Var[7])
d=os.date("%b %d %X %p")
fout:write(d .. " " .. airtemp .. " " .. h2otemp .. "\n")
print (d);
print (airtemp);
print (h2otemp);
fout:close()
end)
How would I get these to show up on a webserver HTML page when it is opened?
Thanks!
Ron
March 14th, 2007, 08:53 AM
Would this be the built in webserver? If so then just put lua script in the webpages. Have a look at the manual page for the webserver, it has examples. For example the Girder 5 DM webpages use this extensively.
Todd Reed
March 14th, 2007, 12:36 PM
Maybe like this?
<%
Ocelot:GetVariables(function() Print ("Airtemp = "..ADI.Var[8] end)
%>
Ron
March 14th, 2007, 01:15 PM
Close! print actually prints to the lua console not the webpage.
<%
Ocelot:GetVariables(function() webserver:print ("Airtemp = "..ADI.Var[8] end)
%>
Todd Reed
March 14th, 2007, 08:33 PM
Actually, after 45 minutes... this worked!
<%
Ocelot:GetVariables(function() end)
webserver:print("<H2>".." Current Air Temperature is = "..ADI.Var[8].."</H2>")
%>
Any tips on formating and concatenating using webserver:print?
hoox
March 15th, 2007, 01:54 AM
Todd,
Note that you'll have to put a delay in there or it will display old values...
<%
ADI.Var[8] = 'Unknown'
Ocelot:GetVariables(function() end)
local i = 0
while ADI.Var[8] == 'Unknown' and i < 3 do
win.Sleep(700)
i = i+1
end
webserver:print("<H2>".." Current Air Temperature is = "..ADI.Var[8].."</H2>")
%>
Todd Reed
March 15th, 2007, 06:01 AM
Thanks, I could not get it to work with "webserver:print" inside the "end" statement, and when I took it out, then it displayed, but in fact it may be old data.
Ron
March 15th, 2007, 08:38 AM
That seems like an odd way to do things. Is there no other way to get the data? Blocking a webpage for 700ms is an eternity and will not scale very well :-)
Todd Reed
March 15th, 2007, 03:29 PM
I could not get the "webserver: print" to work inside the function/end statements. I will try a few more things... But checking again, it seems to be up to date! Maybe it updates, before the "end" statement, before it continues to next line??
Maybe Hoox and Ron can review the Ocelot:GetVariables function inside the Serial plugin. There may be a better way!!
:)
hoox
March 16th, 2007, 06:07 AM
Unfortunately, I have no idea how GetVariables could return the values, without blocking Girder during the time that the reponse is pending.
The callback function is used to avoid this with most Girder scripts, but it won't work with the webserver.
You could try making periodic Ajax requests, but I don't know if it's easy to do...
Ron
March 16th, 2007, 08:37 AM
Ajax is not hard. Check out my examples in the httpd directory.
Todd Reed
March 16th, 2007, 04:12 PM
:o
Okay, 45 minutes to figure out my solution so far is... well, kinda hard....! :(
I consider myself decent in HTML and without a full manual, the AJAX looks totally Greek!
Or should I say GEEK! (At least that's what my kids call me :))
So which example file would help us the most? G5 or G4 directory?
Ron
March 16th, 2007, 07:41 PM
Have a look at the httpd directory in the Girder directory. You'll find several HTML files there. If you look at events.html it shows you how to send events to Girder from HTML using AJAX. Hopefully this will get you started. Javascript is not too bad, just use a browser that gives you feedback on errors. I really like to use Firefox for that. Though IE has an addition somewhere that allows you to debug pages as well. Best thing as always is to have specific questions :-)
Powered by vBulletin® Version 4.1.8 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.