PDA

View Full Version : HAI Temperature display



jnickel
September 10th, 2006, 01:25 PM
Hi,

I am using NR2 with Girder 4 and the HAI plugin.

Being in Canada, I wanted to display my thermostat temperatures on NR in Celsius.

So, I setup the following functions in the System LUA file:

function ontempchange(varname, varvalue)
local tempvar = NetRemote.GetVariable("Security Controller.Thermostat 1.Current");
tempvar = (tempvar - 32)*5/9;
NetRemote.SetVariable("celsiustemp", tempvar);
end;

function OnCCFLoad()
tempvar = NetRemote.GetVariable("Security Controller.Thermostat 1.Current");
tempvar = math.ceil((tempvar - 32)*5/9*10)/10;
NetRemote.SetVariable("celsiustemp", tempvar);
NetRemote.RegisterVariableWatch("Security Controller.Thermostat 1.Current", ontempchange);
end;

Then I put the {celsiustemp} as the display name of a button on a form.

Works fine in Netremote on Windows, but on my Pocket PC (iPAQ 3650), I don't get any display.

What might be wrong?

Jim

Ben S
September 10th, 2006, 05:05 PM
If you put a



NetRemote.MessageBox('tempvar')


After setting the variable, does it work?

Rob H
September 11th, 2006, 12:01 AM
That should be NetRemote.MessageBox(tempvar) no quotation marks

jnickel
September 11th, 2006, 04:02 PM
Well that's interesting.....

On Windows it pops up the message box as soon as the CCF loads....

On Pocket PC it doesn't ever pop up.

That would seem to indicate that the OnCCFLoad doesn't happen/work on Pocket PC.

Is that correct?

Edit:

No that can't be right as I am also monitoring changes in the current mp3 filename, stripping off the leading directory paths and just displaying the file name.
Hmmmmm.....Could it be that a blank line causes problems in Pocket PC?

Full code looks like this:

function OnCCFLoad()
NetRemote.RegisterVariableWatch("MP.Filename", onfilenamechange);
local tempvar = NetRemote.GetVariable("MP.Filename");
tempvar = string.sub(tempvar,13, -1);
NetRemote.SetVariable("mp3file", tempvar);

tempvar = NetRemote.GetVariable("Security Controller.Thermostat 1.Current");
tempvar = math.ceil((tempvar - 32)*5/9*10)/10;
NetRemote.SetVariable("celsiustemp", tempvar);
NetRemote.MessageBox(tempvar);
NetRemote.RegisterVariableWatch("Security Controller.Thermostat 1.Current", ontempchange);
end;


Jim

jnickel
September 11th, 2006, 04:11 PM
Nope....took out the blank line....still doesn't work on the Pocket PC.

It just never popsup the messagebox. Works just fine on Netremote on Windows.

Bizarre. Help.

Jim

hoox
September 11th, 2006, 04:16 PM
Jim, NetRemote.GetVariable should'nt be required with a VariableWatch.
Try with something like this:


function ontempchange(varname, varvalue)
NetRemote.SetVariable("celsiustemp", math.round((tonumber(varvalue) - 32)*5/9, 2));
end;

NetRemote.RegisterVariableWatch("Security Controller.Thermostat 1.Current", ontempchange);

function OnCCFLoad()
--Probably nothing needed here
end;

jnickel
September 11th, 2006, 04:34 PM
K...I am very confused.

If I put the MessageBox in the middle, then it popsup, but it is blank and the title bars says, "Error".

The code looks like this when that happens:

function OnCCFLoad()
NetRemote.RegisterVariableWatch("MP.Filename", onfilenamechange);
local tempvar = NetRemote.GetVariable("MP.Filename");
tempvar = string.sub(tempvar,13, -1);
NetRemote.SetVariable("mp3file", tempvar);
NetRemote.MessageBox(tempvar);
tempvar = NetRemote.GetVariable("Security Controller.Thermostat 1.Current");
tempvar = math.ceil((tempvar - 32)*5/9*10)/10;
NetRemote.SetVariable("celsiustemp", tempvar);
NetRemote.RegisterVariableWatch("Security Controller.Thermostat 1.Current", ontempchange);
end;

Yet the mp3file thing works....but the thermostat thing does not.

I am not sure what to try next.

Jim

jnickel
September 11th, 2006, 04:41 PM
Hoox - thanks!

That is working, but I still don't understand why the other one didn't.

In any case, when does code that is outside of a function like that get run? On startup?

I thought that was the purpose of the OnCCFLoad function, so that you could run stuff when the program was loaded. What do you need this function for then?

Lastly, why do you need the tonumber function in the ontempchange? Doesn't it come in as a number?

Thanks again for your help!

Jim

Ben S
September 11th, 2006, 06:01 PM
Quite right. Sorry about that, Rob.

Jim - Yes, OnCCFLoad gets run immediately after the file loads.

NetRemote stores all values internally as strings, so the return of a NetRemote.GetVariable is a string, which needs to be cast to a number for rounding ,etc.

Additionally, where does this value come from? If the thermostat value comes from Girder it may not be received yet.

You should (ideally) try to get the NetRemote variable, and if either '' or nil set it to '0', and then do a tonumber on it. My guess is that Windows is fast enough that it has the value already, but the PPC doesn't so is barfing (there should be a logfile in the NetRemote directory with the specific error message).