Found another web address for weather xml but having problems porting back to the original code. It appears that I am not receiving all the data from the initial GET request and then hangs as its looking for variables. Only a guess as I dont have much experience coding. Would appreciate if someone could look at an give me a push in the right direction. Have included the code below and the debugger output along with the web page.
var debug = true;
System.setDebugMask(debug ? 9 : 0);
// DEFINE GLOBAL VARIABLES
// Check if a value is stored for temporary units for weather
// If not, set it to the one stored in weather parameters page
if (System.getGlobal('TempUnits') == null)
{
System.setGlobal('TempUnits', (CF.widget("Units", "PARAMETERS", "WEATHER_FORECAST").label));
};
// DEFINE ACTIVITY VARIABLES
var socket;
var xmlData; // Stores xml data received from xml.weather.com
var CityCode = CF.widget("City1Code", "PARAMETERS", "WEATHER_FORECAST").label;
var City = 1;
// DEFINE FUNCTIONS
function onConnect()
{
if (socket && socket.connected == false)
{
// Not sure why onConnect() is called when socket is not connected
return;
}
var request = "GET /wxdata/weather/local/";
request += CityCode;
request += "?cc=*&dayf=5"; // 5-day forecast
request += "&unit=" + System.getGlobal('TempUnits'); //Use units stored in TempUnits variable
request += "&prod=bd_select";
request += "&par=yahoowidgetxml HTTP/1.0 \r\n"
// Write request to get weather forecast
socket.write(request);
socket.write("HOST:wxdata.weather.com \r\n");
socket.write("\r\n");
socket.write("\r\n");
};
// This function is called when the xml data has been received
function onData()
{
xmlData += socket.read();
};
// This function is called when the socket is closed
function onClose()
{
var ut;
System.print("XML Data Received Raw =====================> " +xmlData);
// Trim the XML tag off if it was included.
if (xmlData.indexOf("{C}{C}{C}<!--?xml"))
xmlData = xmlData.substring(xmlData.indexOf("?>")+2);
var weather = new XML(xmlData);
System.print("Weather variable ============================>" +weather);
// Get units of measure - standard or metric
ut = weather.head.ut;
// Display temperature units
CF.widget("Degrees").label = ut;
// Display name of city based on city code data
CF.widget("CityName").label = weather.loc.dnam;
// Display current temperature
// (remove ';//" and the text between the brackets below if you want to display C or F)
CF.widget("Temp").label = weather.cc.tmp + "°"; // + weather.head.ut;
// Update today's forecast
var text = weather.cc.t;
var hi = weather.dayf.day[0].hi;
var low = weather.dayf.day[0].low;
var icon = ""+weather.dayf.day[0].part[0].icon; // Force it to be a string
// Display Severe Weather Alert
try {
var swa0 = weather.swa.a[0].t;
var swa1 = weather.swa.a[1].t;
var swa2 = weather.swa.a[2].t;
}
catch (e) {
var swa0 = "";
var swa1 = "";
var swa2 = "";
}
CF.widget("SWA0").label = swa0;
CF.widget("SWA1").label = swa1;
CF.widget("SWA2").label = swa2;
//System.print("Severe Weather Alert: " +swa);
CF.widget("Text").label = weather.dayf.day[0].part[0].t;
// Update high temperature; if not available, omit temperature unit
// (remove ';//" and the text between the brackets below if you want to display C or F)
CF.widget("tp00").label = hi + "°"; // + weather.head.ut;
if (hi == "N/A")
{
CF.widget("tp00").label = hi;
icon = ""+weather.dayf.day[0].part[1].icon;
CF.widget("Text").label = weather.dayf.day[0].part[1].t;
}
// Update low temperature
// (remove ';//" and the text between the brackets below if you want to display C or F)
CF.widget("tp01").label = low + "°"; // + weather.head.ut;
// Set icon
var w = CF.widget("tp02");
w.setImage(CF.widget(icon, icon, "WEATHER_FORECAST").getImage());
w.label = "";
// Once weather data is updated, change activity label back to standby
CF.activity().label = "standby mode...";
// Note that the socket is killed after it has been closed and
// will need to be recreated.
socket = null;
};
function onIOError(e)
{
System.print(e);
};
function connectWeather(City)
{
CityCode = CF.widget("City" + City + "Code", "PARAMETERS", "WEATHER_FORECAST").label;
if(socket == null) // socket was cleared by onClose()
{
// create new asynchronous TCP socket
socket = new TCPSocket(false);
// setup socket functions
socket.onConnect = onConnect;
socket.onData = onData;
socket.onClose = onClose;
socket.onIOError = onIOError;
xmlData = "";
socket.connect('wxdata.weather.com', 80, 3000);
}
}
==================================
Note * sub for <
Offending line #62: " var weather = new XML(xmlData);"
Offending activity script: Tag: 'HOME'
ProntoScript error: SyntaxError: syntax error
*t>Fire Weathe
*/a><a id="740981" uc="3">
*l>[Link: weather.com];
*t>Special Weather Statement</t>
*a id="736147" uc="2">
*swa>
*/loc>
*zone>-5</zone>
*suns>4:59 PM</suns>
*sunr>6:47 AM</sunr>
*lon>-77.29</lon>
*lat>39.00</lat>
*tm>2:24 PM</tm>
*dnam>Great Falls, VA</dnam>
*loc id="USVA0324">
*/head>
*ur>in</ur>
*up>in</up>
*us>mph</us>
*ud>mi</ud>
*ut>F</ut>
*form>MEDIUM</form>
*locale>en_US</locale>
*head>
*weather ver="2.0">
Connection: close
Content-Length: 5078
Date: Sun, 10 Nov 2013 19:24:16 GMT
Cache-Control: max-age=278
X-Cache-Hits: 0
X-Varnish: 2194322075
Content-Type: text/xml;charset=UTF-8
Server: Apache-Coyote/1.1
XML Data Received Raw =====================> HTTP/1.0 200 OK
adding dns 192.168.1.1
route: SIOCDELRT: No such process
deleting routers
Lease of 192.168.1.15 obtained, lease time 86400
Sending select for 192.168.1.15...
=============================
//[Link: wxdata.weather.com]
Last edited by pjjameso on November 10, 2013 14:50.