i am not very good at programming so i thought i could hack the NOAA script. The script gets the xML feed but i am confused at the code to tell it to get the XML name and value and put it into variables. been trying various ways for the last 2 hours but need some asistance
here is my altered script.
- Code: Select all
do shell script "curl -L " & "http://10.0.1.201:1001/cgi-bin/status.xml"
return true
end
on ParseXML()
try
tell application "System Events"
set windchill_f to value of XML elements of elem1 whose name is "windchill_f"
set windchill_c to value of XML elements of elem1 whose name is "windchill_c"
set visibility_mi to value of XML elements of elem1 whose name is "visibility_mi"
end tell
return true
on error errString number errNum
my LogNOAA("ParseXML", errString, errNum)
return false
end try
end ParseXML
on SendToIndigo()
set arr to {¬
{"Weather_Windchill_F", GetWindchillF, windchill_f}, ¬
{"Weather_Windchill_C", GetWindchillC, windchill_c}, ¬
{"Weather_Visibility_mi", GetVisibility, visibility_mi} ¬
}
repeat with thisArr in arr
try
tell application "IndigoServer"
if (item 2 of thisArr) is true then
if (length of (item 3 of thisArr) = 0) then
set logString to "Variable \"" & (item 1 of thisArr) & "\" is not present in the NOAA data file."
my LogNOAA(logString, "", 0)
else
if not (variable (item 1 of thisArr) exists) then
make new variable with properties {name:(item 1 of thisArr), value:(item 3 of thisArr)}
else
set value of variable (item 1 of thisArr) to (item 3 of thisArr)
end if
end if
else
if (variable (item 1 of thisArr) exists) then delete variable (item 1 of thisArr)
end if
end tell
on error errString number errNum
my LogNOAA("SendToIndigo", errString, errNum)
end try
end repeat
end SendToIndigo
and here is the XML output when i run it in AS editor.
- Code: Select all
tell current application
do shell script "curl -L http://10.0.1.201:1001/cgi-bin/status.xml"
--> "<?xml version=\"1.0\"?>
<status software=\"4.10L_6D11\" hardware=\"1.0\">
<hostname>apex</hostname>
<serial>AC4:04376</serial>
<timezone>-8</timezone>
<date>09/09/2011 10:50:56</date>
<power><failed>none</failed>
<restored>none</restored></power>
<probes>
<probe>
<name>Temp</name> <value>80.0</value>
<type>Temp</type></probe>
<probe>
<name>pH</name> <value>7.91</value>
<type>pH</type></probe>
<probe>
<name>Amp_3</name> <value>0.0 </value>
<type>Amps</type></probe></probes>
<outlets>
<outlet>
<name>SndAlm_I6</name>
<state>AOF</state>
<deviceID>base_Alarm</deviceID>
</outlet>
<outlet>
<name>SndWrn_I7</name>
<state>AOF</state>
<deviceID>base_Warn</deviceID>
</outlet>
<outlet>
<name>EmailAlm_I5</name>
<state>AOF</state>
<deviceID>base_email</deviceID>
</outlet>
<outlet>
<name>BlueLed</name>
<state>AON</state>
<deviceID>3_1</deviceID>
</outlet>
<outlet>
<name>Skimmer</name>
<state>AON</state>
<deviceID>3_2</deviceID>
</outlet>
<outlet>
<name>Rs_Pump</name>
<state>AON</state>
<deviceID>3_3</deviceID>
</outlet>
<outlet>
<name>Heater</name>
<state>AOF</state>
<deviceID>3_4</deviceID>
</outlet>
<outlet>
<name>Vortech</name>
<state>AOF</state>
<deviceID>3_5</deviceID>
</outlet>
<outlet>
<name>Fan</name>
<state>AOF</state>
<deviceID>3_6</deviceID>
</outlet>
<outlet>
<name>spare</name>
<state>OFF</state>
<deviceID>3_7</deviceID>
</outlet>
<outlet>
<name>PCLights</name>
<state>AOF</state>
<deviceID>3_8</deviceID>
</outlet>
</outlets></status>"
end tell
Result:
true
thanks if you can help