Connect to Wunderground Website

Hello, I need help if someone can tell me how can I use the Photon to connect to this website and get specific data from the body of the page like for example: I like to get the data from line (wind_mph)?

Here is the web address.
http://api.wunderground.com/api/deffa85bd0bf64af/conditions/q/CA/San_Francisco.json

Thank You

Exactly what you are looking for, to include using the weatherunderground api. I recommend searching first in the future.

2 Likes

I used a webhook like this which includes wind:

{
	"event": "current_weather",
	"url": "http://api.wunderground.com/api/myAPIkey/conditions/q/{{myState}}/{{myCity}}.json",
	"requestType": "POST",
	"headers": null,
	"query": null,
	"responseTemplate": "{{#response}}{{#current_observation}}{{#estimated}}{{weather}}~{{temp_f}}~{{relative_humidity}}~{{wind_dir}}~{{wind_gust_mph}}~{{dewpoint_f}}~{{/estimated}}{{/current_observation}}{{/response}}",
	"responseTopic": "{{SPARK_CORE_ID}}_current_weather",
	"json": null,
	"auth": null,
	"mydevices": true
}

call it like this:

Particle.publish("current_weather", publishString, 60, PRIVATE);

where:

const String cityLocation = "Austin";  //City for my Photon
const String stateLocation = "TX";     // State for my Photon
//...
String publishString = "{\"my-city\": \"" + cityLocation + "\", \"my-state\": \"" + stateLocation + "\" }"; 

retreived with:

  String responseTopic = System.deviceID();
  Particle.subscribe(responseTopic, webhookHandler, MY_DEVICES);  // responds to events with your unique device ID

sorted with

void webhookHandler(const char *event, const char *data)
{
  DEBUG_PRINTLN("Responding to webhook...");
  DEBUG_PRINTLN(event);  // just for debugging to see how the webhook was actually called
  DEBUG_PRINT("Webhook is ");
  DEBUG_PRINT(strlen(data));  // debug payload length
  DEBUG_PRINT(" bytes and contains: ");
  DEBUG_PRINTLN(data);
  if (strstr(event, "myAccount_gmail/0"))
  {
    gotGmailFeed(event, data);
  }
  else if(strstr(event, "current_weather")) // <<<<<< here!!
  {
    gotWeather(event, data);
  }
  else if (strstr(event, "forecast_weather"))
  {
    gotForecast(event, data);
  }
  else if (strstr(event, "sun_time"))
  {
    gotSunTime(event, data);
  }
}

and parsed here:

void gotWeather(const char *event, const char *data)
{
  lcd->setCursor(19,0);
  lcd->write(0); // indicate icoming message with clock icon
  DEBUG_PRINTLN("Extracting Weather from Webhook:");   //  Clear~74.4~86%~NNW~0~70~
  String weatherBuffer = String(data);             // conditions temp rh winddir windgust dewpoint_f
  char currentBuffer[125] = "";
  weatherBuffer.toCharArray(currentBuffer, 125);
  weatherCondition = strtok(currentBuffer, "\"~");
  outdoorTemp = atoi(strtok(NULL, "~"));
  outdoorHumid = atoi(strtok(NULL, "~"));
  windDirection = strtok(NULL, "~");
  windSpeed = atoi(strtok(NULL, "~"));
  int dewPoint = atoi(strtok(NULL, "~"));
}
2 Likes

Thank You Guys! Let me try…