PDA

View Full Version : 2 way communication from devices to Girder



jamiehutton
March 21st, 2015, 06:14 AM
Hi there,

I am trying to get Girder to receive the current status from my amplifier. In my LUA script I have the following:

local onDataReceived = function(self, data)
print("Received: ", data)
if string.sub(data, 1,3) == "VOL" then
volume=string.sub(data, 4,6)
print("Volume: ", volume)
end
end

I can see in the Lua console that this is working:

Fri Feb 20 20:15:35 2015 Received: VOL130
Fri Feb 20 20:15:35 2015 Volume: 130

However I cannot get this into a javascript variable in my LHTML web page. In fact I cannot get the volume variable to resolve at all. My test lhtml file had the following:

<%
print(volume)
%>
<%
test="Hello World!"
print(test)
%>

The script successfully prints Hello World! which tells me the LUA parsing is happening, but I get nothing output for the volume variable - it seems like it isnt able to be seen by the lhtml script? is there a way to make it global? or is there something i am missing

Ron
March 21st, 2015, 08:43 AM
It's possible that "volume" is local to the module it is in. Where does your onDataReceived live? If in a separate Lua file then export volume like this:



-- at the top of the file before module (...)
local _G = _G


then your code




local onDataReceived = function(self, data)
print("Received: ", data)
if string.sub(data, 1,3) == "VOL" then
volume=string.sub(data, 4,6)
_G.volume = volume
print("Volume: ", volume)
end
end