cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! X

Open weather app tutorial problem

msutton
7-Bedrock

Open weather app tutorial problem

Hi Everyone

I am having a problem with the open weather app tutorial. I have followed the tutorial but i get an error when testing the code. I have created my own API key using the link in the tutorial. I didn't know if there may be an issue with having copied the code from the PDF and whether formatting has been lost.

See error below

Wrapped org.apache.http.conn.HttpHostConnectException: Connect to api.openweathermap.org:80 [api.openweathermap.org/178.62.207.82, api.openweathermap.org/178.62.223.38] failed: Connection timed out: connect Cause: Connect to api.openweathermap.org:80 [api.openweathermap.org/178.62.207.82, api.openweathermap.org/178.62.223.38] failed: Connection timed out: connect

And the code i'm using below

var stringLocation=location+" ";

var arrayLocations=stringLocation.split(",");

var lat=arrayLocations[0];

var long=arrayLocations[1];

//Modify the open weather url here if you are using your own API key

var params = {

  url: "http://api.openweathermap.org/data/2.5/forecast?lat="+lat+"&lon="+long+"&units=imperial" +"&type=accurate&mode=xml&APPID=75239107b41bd2c2a72e2e3c7b89b550" /* STRING*/,

  timeout: 160 /* NUMBER */

};

// result: XML

var xmlPage = Resources["ContentLoaderFunctions"].LoadXML(params);

var params = {

  infoTableName : "InfoTable",

  dataShapeName : "OpenWeatherFeed"

};

// CreateInfoTableFromDataShape(infoTableName:STRING("InfoTable"),dataShapeName:STRING:INFOTABLE(OpenWeatherFeed)

var result = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(params);

  var from_today_value=xmlPage.forecast.time[0].@from.substring(0,10);

  a.logger.warn("from_today_value= "+from_today_value);

for each (var item in xmlPage.forecast.time) {

  var row = new Object();

  var from_current_value=item.@from.substring(0,10);

  row.WindDirection = item.windDirection.@name;

  row.WindSpeed=item.windSpeed.@mps;

  row.WeatherTemp=parseFloat(item.temperature.@value);

  row.WeatherHumidity=parseFloat(item.humidity.@value);

  row.From=item.@from;

  row.To=item.@to;

  row.Title=xmlPage.location.name+" "+xmlPage.location.country;

  row.Precipitation=(item.precipitation.@type+" "+item.precipitation.@value)==" "?"NoPrecipitation":item.precipitation.@type;

  result.AddRow(row);

}

Thanks Matt

ACCEPTED SOLUTION

Accepted Solutions
msutton
7-Bedrock
(To:msutton)

Hello Everyone

Turned out the issue was with the firewall blocking access to the open internet here at work

Thanks Matt 

View solution in original post

3 REPLIES 3
ttielebein
14-Alexandrite
(To:msutton)

Are you sure that is the right API Key? Also, have you made sure that everything rendered right, like even newlinee characters? I have had issues copying from PDFs into ThingWorx in the past

msutton
7-Bedrock
(To:msutton)

Hello Everyone

Turned out the issue was with the firewall blocking access to the open internet here at work

Thanks Matt 

ttielebein
14-Alexandrite
(To:msutton)

Can you mark this answer as correct to help others find the answer to their problems more easily? Thanks, and glad to hear you got it working!

Announcements


Top Tags