Your Universal Remote Control Center
RemoteCentral.com
Philips Pronto Professional Forum - View Post
Up level
Up level
The following page was printed from RemoteCentral.com:

Login:
Pass:
 
 

Original thread:
Post 1 made on Saturday April 17, 2010 at 12:05
ScottGrimes
Long Time Member
Joined:
Posts:
April 2007
78

I've been trying to get Paul Spee's weather module to display today's weather info on my Home screen. I am a complete newbie when it comes to ProntoScript, but I have learned a few tricks, albiet quite basic. With the help of individuals from this forum it is now functioning properly. Thanks guys.

I've modeled my Home/Splash screen after the HTC Hero phone. The clock is working beautifully and I have the graphics pretty much complete. You can go to the full 5-day forecast (located in a different activity) by pressing on the weather icon area.

My Home/Splash Screen
My Splash Page

Note: I've remove some comments and the copyright info here to shorten the post.

Note: I've edited the scipts below to reflect the current working version. The OnWake() function is working now. This function will refresh the weather data whenever the remote wakes up. There may be a more elegant way to write this... but it works. Also, you may have noticed I am starting to make some new weather icons.

Home - Activity Level Script
var socket;
var xmlData; // Stores xml data received from xml.weather.com
var CityCode = CF.widget("City1Code", "PARAMETERS", "LOCAL_WEATHER").label;

function onConnect()
{

  if (socket && socket.connected == false) {
    // Not sure why onConnect() is called when socket is not connected
    return;
  }

  var request = "GET /weather/local/";
  request += CityCode;
  request += "?cc=*&dayf=1";
  request += "&unit=" +  CF.widget("Unit", "PARAMETERS", "LOCAL_WEATHER").label;
  request += "&prod=bd_select";
  request += "&par=yahoowidgetxml HTTP/1.0 \r\n"

  // Write request to get weather forecast
  socket.write(request);
  socket.write("HOST:xml.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(5000,1000);
};

// This function is called when the socket is closed
function onClose()
{
  var ut;

  // Trim the XML tag off if it was included.
  if (xmlData.indexOf("<!--l"))  <-->       xmlData = xmlData.substring(xmlData.indexOf("?>")+2);

  var weather = new XML(xmlData);

  // Get units
  ut = weather.head.ut;

  // Display location
  CF.widget("CityName").label = weather.loc.dnam;

  // Display text
  CF.widget("Text").label = weather.cc.t;

  // Display current temperature
  CF.widget("Temp").label = weather.cc.tmp + "°"; // + weather.head.ut; (remove '; //' and this text if you wish to display C or F units)

  // Update weather
    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

    // Update high temperature; if not available, omit temperature unit
    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;
    }

    // Update low temperature
    CF.widget("tp01").label = low + "°"; // + weather.head.ut; (remove '; //' and this text if you wish to display C or F units)

    // Set icon
    var w = CF.widget("tp02");
    w.stretchImage = true;
    w.setImage(CF.widget(icon, "GALLERY", "LOCAL_WEATHER").getImage());
    w.label = "";

  // 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", "LOCAL_WEATHER").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('xml.weather.com', 80, 3000);
  }
}


Home - Page Level Script
System.setGlobal('currentActivity', 'SPLASH');

function wifiConnected()
{
    if (System.getNetlinkStatus() == "wifi-disconnected")
    {
        Activity.scheduleAfter(1000, wifiConnected);
    }
    else
    {
        setClock();
        setDate();
        connectWeather(1);
        CF.activity().label = "standby mode...";
    }
}

onWake = function()
{
    Activity.scheduleAfter(1000, wifiConnected);
}

function setClock()
{
    currentTime = GUI.getDisplayTime().split(':');
    currentMinutesAndMeridiem = currentTime[1].split('');
    CF.widget('hour').label = currentTime[0];
    CF.widget('minutes').label = currentMinutesAndMeridiem[0] + currentMinutesAndMeridiem[1];
    CF.widget('meridiem').label = (currentMinutesAndMeridiem[2] + currentMinutesAndMeridiem[3]).toUpperCase();
    scheduleAfter(1000, setClock);
}

function setDate()
{
    currentDate = GUI.getDisplayDate().split(" ");
    CF.widget('date').label = currentDate[0] + ", " + currentDate[1] + " " + currentDate[2];
    scheduleAfter(1000, setDate);
}

wifiConnected();

Last edited by ScottGrimes on April 29, 2010 09:14.
Scott Grimes
Liquid Designs
[email protected]


Hosting Services by ipHouse