Cloud JSON Parsing

@sazp96, the requestType should be POST, not GET. Also, remove the comma at the end of the “mode”: “json” line. The response template looks good so try those change and see what happens. Please make sure you delete your old webhook and your are using the latest version of CLI! :smiley:

The switch from GET to POST worked. Thanks @peekay123!!

Why is POST the right type to use? I though GET is the type to use for retrieving information.

@sazp96, you would think but that’s now quite how RESTFUL API works. I will defer the explanation to @bko or @Moors7 who are a lot smarter than me on this topic. :smiley:

I know this isn’t a real “Particle” question but there seems to be some real knowledge of parsing html data here on the forum. Using the “moustache” format @peekay showed us, for example.

I am looking to capture sports scores. I’ve searched and searched and have found other methods like this.

Ideally, I’d like to set up a webhook that would help me bring in a specific team’s scores from ESPN, however I have no skills for that.

Anyone ever tried to do this?

I’m looking to recreate a typical MLB scoreboard… ‘live’ on a Particle-enabled display.

                R  H  E
Red Sox         5  4  0
Yankees         7  6  0
Bottom of the 7th

@peekay123

any chance you can help me with gmail’s JSON format?

so that I can parse a JSON back from gmail that looks like this in XML?

<feed xmlns="http://purl.org/atom/ns#" version="0.3">
<title>Gmail - Inbox for redacted@gmail.com</title>
<tagline>New messages in your Gmail Inbox</tagline>
<fullcount>1</fullcount>
<link rel="alternate" href="https://mail.google.com/mail" type="text/html"/>
<modified>2015-06-25T21:41:23Z</modified>
<entry>
<title>Free Rides This Weekend in Northwest Miami</title>
<summary>
Passport to Summer lets you explore South Florida with free rides FREE RIDES THIS WEEKEND Passport to
</summary>
<link rel="alternate" href="https://mail.google.com/mail?account_id=redacted@gmail.com&message_id=14e2c99ae8e0ef8b&view=conv&extsrc=atom" type="text/html"/>
<modified>2015-06-25T21:22:25Z</modified>
<issued>2015-06-25T21:22:25Z</issued>
<id>tag:gmail.google.com,2004:1504986892664369035</id>
<author>
<name>Uber Miami</name>
<email>supportMiami@uber.com</email>
</author>
</entry>
</feed>

trying to parse <fullcount>

I am having many problems with the XML parsing in my subscribe function…

@BulldogLowell, ESPN is a website and only offers it API for money. To parse the full webpage via a webhook is not possible.

Instead of XML, can you give me the request that generates the JSON you want to parse so I can see the JSON response?

@peekay123

this is the call:

GET https://www.googleapis.com/gmail/v1/users/yourusername%40gmail.com/labels/INBOX?fields=messagesUnread&key={YOUR_API_KEY}

this is the response:

200 OK

  • SHOW HEADERS -
    {
    “messagesUnread”: 1
    }

oath verification

I’m looking for advice to shorten the size of a JSON return from a WeatherUnderground call:

the webhook:

{
"event": "Vera_controller/nj_forecast",
"url": "http://api.wunderground.com/api/<MyApiKey>/forecast10day/q/NJ/Princeton.json",
"requestType": "POST",
"headers": null,
"query": null,
"responseTemplate": "{{#forecast}}{{#simpleforecast}}{{#forecastday}}{{high.fahrenheit}}~{{low.fahrenheit}}~{{conditions}}~{{pop}}~{{/forecastday}}{{/simpleforecast}}{{/forecast}}",
"json": null,
"auth": null,
"mydevices": true
}

the JSON return:

{
  "response": {
  "version":"0.1",
  "termsofService":"http://www.wunderground.com/weather/api/d/terms.html",
  "features": {
  "forecast10day": 1
  }
	}
		,
	"forecast":{
		"txt_forecast": {
		"date":"10:52 AM EDT",
		"forecastday": [
		{
		"period":0,
		"icon":"chancetstorms",
		"icon_url":"http://icons.wxug.com/i/c/k/chancetstorms.gif",
		"title":"Thursday",
		"fcttext":"Variable clouds with scattered thunderstorms. A few storms may be severe. High 87F. Winds SW at 5 to 10 mph. Chance of rain 50%.",
		"fcttext_metric":"Scattered thunderstorms. A few storms may be severe. High around 30C. Winds WSW at 10 to 15 km/h. Chance of rain 50%.",
		"pop":"50"
		}
		,
		{
		"period":1,
		"icon":"nt_chancetstorms",
		"icon_url":"http://icons.wxug.com/i/c/k/nt_chancetstorms.gif",
		"title":"Thursday Night",
		"fcttext":"Partly to mostly cloudy skies with scattered thunderstorms during the evening. A few storms may be severe. Low 68F. Winds WSW at 5 to 10 mph. Chance of rain 60%.",
		"fcttext_metric":"Scattered thunderstorms during the evening. Partly cloudy skies after midnight. A few storms may be severe. Low around 20C. Winds SW at 10 to 15 km/h. Chance of rain 60%.",
		"pop":"60"
		}
		,
		{
		"period":2,
		"icon":"clear",
		"icon_url":"http://icons.wxug.com/i/c/k/clear.gif",
		"title":"Friday",
		"fcttext":"Mostly sunny. High 86F. Winds NNW at 10 to 15 mph.",
		"fcttext_metric":"Partly cloudy skies. High around 30C. Winds NNW at 10 to 15 km/h.",
		"pop":"0"
		}
		,
		{
		"period":3,
		"icon":"nt_partlycloudy",
		"icon_url":"http://icons.wxug.com/i/c/k/nt_partlycloudy.gif",
		"title":"Friday Night",
		"fcttext":"Partly cloudy skies. Low around 65F. Winds light and variable.",
		"fcttext_metric":"Partly cloudy skies. Low 18C. Winds light and variable.",
		"pop":"0"
		}
		,
		{
		"period":4,
		"icon":"clear",
		"icon_url":"http://icons.wxug.com/i/c/k/clear.gif",
		"title":"Saturday",
		"fcttext":"Sunny. High 88F. Winds light and variable.",
		"fcttext_metric":"Mainly sunny. High 31C. Winds light and variable.",
		"pop":"0"
		}
		,
		{
		"period":5,
		"icon":"nt_clear",
		"icon_url":"http://icons.wxug.com/i/c/k/nt_clear.gif",
		"title":"Saturday Night",
		"fcttext":"Mostly clear skies. Low 66F. Winds light and variable.",
		"fcttext_metric":"Mostly clear skies. Low 19C. Winds light and variable.",
		"pop":"0"
		}
		,
		{
		"period":6,
		"icon":"clear",
		"icon_url":"http://icons.wxug.com/i/c/k/clear.gif",
		"title":"Sunday",
		"fcttext":"Sunny along with a few clouds. High 92F. Winds WNW at 5 to 10 mph.",
		"fcttext_metric":"Generally sunny despite a few afternoon clouds. High 33C. Winds light and variable.",
		"pop":"0"
		}
		,
		{
		"period":7,
		"icon":"nt_clear",
		"icon_url":"http://icons.wxug.com/i/c/k/nt_clear.gif",
		"title":"Sunday Night",
		"fcttext":"Mainly clear skies. Low 69F. Winds light and variable.",
		"fcttext_metric":"Generally fair. Low near 20C. Winds light and variable.",
		"pop":"20"
		}
		,
		{
		"period":8,
		"icon":"chancetstorms",
		"icon_url":"http://icons.wxug.com/i/c/k/chancetstorms.gif",
		"title":"Monday",
		"fcttext":"Rain showers in the morning with scattered thunderstorms arriving in the afternoon. High 88F. Winds S at 10 to 15 mph. Chance of rain 50%.",
		"fcttext_metric":"Showers early then scattered thunderstorms developing later in the day. High 31C. Winds S at 15 to 25 km/h. Chance of rain 50%.",
		"pop":"50"
		}
		,
		{
		"period":9,
		"icon":"nt_chancetstorms",
		"icon_url":"http://icons.wxug.com/i/c/k/nt_chancetstorms.gif",
		"title":"Monday Night",
		"fcttext":"Scattered thunderstorms in the evening. Cloudy skies overnight. Low 69F. Winds S at 5 to 10 mph. Chance of rain 50%.",
		"fcttext_metric":"Scattered thunderstorms during the evening, then cloudy skies overnight. Low around 20C. Winds S at 10 to 15 km/h. Chance of rain 50%.",
		"pop":"50"
		}
		,
		{
		"period":10,
		"icon":"partlycloudy",
		"icon_url":"http://icons.wxug.com/i/c/k/partlycloudy.gif",
		"title":"Tuesday",
		"fcttext":"Partly cloudy. High 87F. Winds W at 5 to 10 mph.",
		"fcttext_metric":"Sunshine and clouds mixed. High around 30C. Winds W at 10 to 15 km/h.",
		"pop":"20"
		}
		,
		{
		"period":11,
		"icon":"nt_partlycloudy",
		"icon_url":"http://icons.wxug.com/i/c/k/nt_partlycloudy.gif",
		"title":"Tuesday Night",
		"fcttext":"Partly cloudy skies. Low around 70F. Winds light and variable.",
		"fcttext_metric":"A few clouds. Low 21C. Winds light and variable.",
		"pop":"20"
		}
		,
		{
		"period":12,
		"icon":"partlycloudy",
		"icon_url":"http://icons.wxug.com/i/c/k/partlycloudy.gif",
		"title":"Wednesday",
		"fcttext":"Intervals of clouds and sunshine. High 88F. Winds W at 5 to 10 mph.",
		"fcttext_metric":"Intervals of clouds and sunshine. High 31C. Winds W at 10 to 15 km/h.",
		"pop":"20"
		}
		,
		{
		"period":13,
		"icon":"nt_partlycloudy",
		"icon_url":"http://icons.wxug.com/i/c/k/nt_partlycloudy.gif",
		"title":"Wednesday Night",
		"fcttext":"Partly cloudy skies. Low 69F. Winds NW at 5 to 10 mph.",
		"fcttext_metric":"Partly cloudy skies. Low near 20C. Winds NW at 10 to 15 km/h.",
		"pop":"20"
		}
		,
		{
		"period":14,
		"icon":"chancerain",
		"icon_url":"http://icons.wxug.com/i/c/k/chancerain.gif",
		"title":"Thursday",
		"fcttext":"Rain showers early with some sunshine later in the day. High 87F. Winds NW at 5 to 10 mph. Chance of rain 40%.",
		"fcttext_metric":"Showers in the morning, then partly cloudy in the afternoon. High 31C. Winds NW at 10 to 15 km/h. Chance of rain 40%.",
		"pop":"40"
		}
		,
		{
		"period":15,
		"icon":"nt_partlycloudy",
		"icon_url":"http://icons.wxug.com/i/c/k/nt_partlycloudy.gif",
		"title":"Thursday Night",
		"fcttext":"A few clouds. Low 68F. Winds light and variable.",
		"fcttext_metric":"Partly cloudy. Low 19C. Winds light and variable.",
		"pop":"20"
		}
		,
		{
		"period":16,
		"icon":"chancetstorms",
		"icon_url":"http://icons.wxug.com/i/c/k/chancetstorms.gif",
		"title":"Friday",
		"fcttext":"Scattered thunderstorms. High 88F. Winds E at 5 to 10 mph. Chance of rain 50%.",
		"fcttext_metric":"Scattered thunderstorms. High 31C. Winds E at 10 to 15 km/h. Chance of rain 50%.",
		"pop":"50"
		}
		,
		{
		"period":17,
		"icon":"nt_chancetstorms",
		"icon_url":"http://icons.wxug.com/i/c/k/nt_chancetstorms.gif",
		"title":"Friday Night",
		"fcttext":"Scattered thunderstorms. Low 67F. Winds E at 5 to 10 mph. Chance of rain 50%.",
		"fcttext_metric":"Variable clouds with scattered thunderstorms. Low 19C. Winds E at 10 to 15 km/h. Chance of rain 50%.",
		"pop":"50"
		}
		,
		{
		"period":18,
		"icon":"chancetstorms",
		"icon_url":"http://icons.wxug.com/i/c/k/chancetstorms.gif",
		"title":"Saturday",
		"fcttext":"Mostly cloudy in the morning with scattered thunderstorms developing later in the day. High 86F. Winds ENE at 5 to 10 mph. Chance of rain 50%.",
		"fcttext_metric":"Mostly cloudy early. Scattered thunderstorms developing later in the day. High around 30C. Winds ENE at 10 to 15 km/h. Chance of rain 50%.",
		"pop":"50"
		}
		,
		{
		"period":19,
		"icon":"nt_chancetstorms",
		"icon_url":"http://icons.wxug.com/i/c/k/nt_chancetstorms.gif",
		"title":"Saturday Night",
		"fcttext":"Mostly cloudy with showers and a few thunderstorms. Low 67F. Winds light and variable. Chance of rain 50%.",
		"fcttext_metric":"Mostly cloudy with showers and a few thunderstorms. Low 19C. Winds light and variable. Chance of rain 50%.",
		"pop":"50"
		}
		]
		},
		"simpleforecast": {
		"forecastday": [
		{"date":{
	"epoch":"1436482800",
	"pretty":"7:00 PM EDT on July 09, 2015",
	"day":9,
	"month":7,
	"year":2015,
	"yday":189,
	"hour":19,
	"min":"00",
	"sec":0,
	"isdst":"1",
	"monthname":"July",
	"monthname_short":"Jul",
	"weekday_short":"Thu",
	"weekday":"Thursday",
	"ampm":"PM",
	"tz_short":"EDT",
	"tz_long":"America/New_York"
},
		"period":1,
		"high": {
		"fahrenheit":"87",
		"celsius":"31"
		},
		"low": {
		"fahrenheit":"68",
		"celsius":"20"
		},
		"conditions":"Chance of a Thunderstorm",
		"icon":"chancetstorms",
		"icon_url":"http://icons.wxug.com/i/c/k/chancetstorms.gif",
		"skyicon":"",
		"pop":50,
		"qpf_allday": {
		"in": 0.29,
		"mm": 7
		},
		"qpf_day": {
		"in": 0.03,
		"mm": 1
		},
		"qpf_night": {
		"in": 0.27,
		"mm": 7
		},
		"snow_allday": {
		"in": 0.0,
		"cm": 0.0
		},
		"snow_day": {
		"in": 0.0,
		"cm": 0.0
		},
		"snow_night": {
		"in": 0.0,
		"cm": 0.0
		},
		"maxwind": {
		"mph": 10,
		"kph": 16,
		"dir": "SW",
		"degrees": 231
		},
		"avewind": {
		"mph": 7,
		"kph": 11,
		"dir": "SW",
		"degrees": 231
		},
		"avehumidity": 71,
		"maxhumidity": 0,
		"minhumidity": 0
		}
		,
		{"date":{
	"epoch":"1436569200",
	"pretty":"7:00 PM EDT on July 10, 2015",
	"day":10,
	"month":7,
	"year":2015,
	"yday":190,
	"hour":19,
	"min":"00",
	"sec":0,
	"isdst":"1",
	"monthname":"July",
	"monthname_short":"Jul",
	"weekday_short":"Fri",
	"weekday":"Friday",
	"ampm":"PM",
	"tz_short":"EDT",
	"tz_long":"America/New_York"
},
		"period":2,
		"high": {
		"fahrenheit":"86",
		"celsius":"30"
		},
		"low": {
		"fahrenheit":"65",
		"celsius":"18"
		},
		"conditions":"Clear",
		"icon":"clear",
		"icon_url":"http://icons.wxug.com/i/c/k/clear.gif",
		"skyicon":"",
		"pop":0,
		"qpf_allday": {
		"in": 0.00,
		"mm": 0
		},
		"qpf_day": {
		"in": 0.00,
		"mm": 0
		},
		"qpf_night": {
		"in": 0.00,
		"mm": 0
		},
		"snow_allday": {
		"in": 0.0,
		"cm": 0.0
		},
		"snow_day": {
		"in": 0.0,
		"cm": 0.0
		},
		"snow_night": {
		"in": 0.0,
		"cm": 0.0
		},
		"maxwind": {
		"mph": 15,
		"kph": 24,
		"dir": "NNW",
		"degrees": 327
		},
		"avewind": {
		"mph": 10,
		"kph": 16,
		"dir": "NNW",
		"degrees": 327
		},
		"avehumidity": 53,
		"maxhumidity": 0,
		"minhumidity": 0
		}
		,
		{"date":{
	"epoch":"1436655600",
	"pretty":"7:00 PM EDT on July 11, 2015",
	"day":11,
	"month":7,
	"year":2015,
	"yday":191,
	"hour":19,
	"min":"00",
	"sec":0,
	"isdst":"1",
	"monthname":"July",
	"monthname_short":"Jul",
	"weekday_short":"Sat",
	"weekday":"Saturday",
	"ampm":"PM",
	"tz_short":"EDT",
	"tz_long":"America/New_York"
},
		"period":3,
		"high": {
		"fahrenheit":"88",
		"celsius":"31"
		},
		"low": {
		"fahrenheit":"66",
		"celsius":"19"
		},
		"conditions":"Clear",
		"icon":"clear",
		"icon_url":"http://icons.wxug.com/i/c/k/clear.gif",
		"skyicon":"",
		"pop":0,
		"qpf_allday": {
		"in": 0.00,
		"mm": 0
		},
		"qpf_day": {
		"in": 0.00,
		"mm": 0
		},
		"qpf_night": {
		"in": 0.00,
		"mm": 0
		},
		"snow_allday": {
		"in": 0.0,
		"cm": 0.0
		},
		"snow_day": {
		"in": 0.0,
		"cm": 0.0
		},
		"snow_night": {
		"in": 0.0,
		"cm": 0.0
		},
		"maxwind": {
		"mph": 5,
		"kph": 8,
		"dir": "N",
		"degrees": 0
		},
		"avewind": {
		"mph": 4,
		"kph": 6,
		"dir": "N",
		"degrees": 0
		},
		"avehumidity": 48,
		"maxhumidity": 0,
		"minhumidity": 0
		}
		,
		{"date":{
	"epoch":"1436742000",
	"pretty":"7:00 PM EDT on July 12, 2015",
	"day":12,
	"month":7,
	"year":2015,
	"yday":192,
	"hour":19,
	"min":"00",
	"sec":0,
	"isdst":"1",
	"monthname":"July",
	"monthname_short":"Jul",
	"weekday_short":"Sun",
	"weekday":"Sunday",
	"ampm":"PM",
	"tz_short":"EDT",
	"tz_long":"America/New_York"
},
		"period":4,
		"high": {
		"fahrenheit":"92",
		"celsius":"33"
		},
		"low": {
		"fahrenheit":"69",
		"celsius":"21"
		},
		"conditions":"Clear",
		"icon":"clear",
		"icon_url":"http://icons.wxug.com/i/c/k/clear.gif",
		"skyicon":"",
		"pop":0,
		"qpf_allday": {
		"in": 0.00,
		"mm": 0
		},
		"qpf_day": {
		"in": 0.00,
		"mm": 0
		},
		"qpf_night": {
		"in": 0.00,
		"mm": 0
		},
		"snow_allday": {
		"in": 0.0,
		"cm": 0.0
		},
		"snow_day": {
		"in": 0.0,
		"cm": 0.0
		},
		"snow_night": {
		"in": 0.0,
		"cm": 0.0
		},
		"maxwind": {
		"mph": 10,
		"kph": 16,
		"dir": "WNW",
		"degrees": 286
		},
		"avewind": {
		"mph": 6,
		"kph": 10,
		"dir": "WNW",
		"degrees": 286
		},
		"avehumidity": 49,
		"maxhumidity": 0,
		"minhumidity": 0
		}
		,
		{"date":{
	"epoch":"1436828400",
	"pretty":"7:00 PM EDT on July 13, 2015",
	"day":13,
	"month":7,
	"year":2015,
	"yday":193,
	"hour":19,
	"min":"00",
	"sec":0,
	"isdst":"1",
	"monthname":"July",
	"monthname_short":"Jul",
	"weekday_short":"Mon",
	"weekday":"Monday",
	"ampm":"PM",
	"tz_short":"EDT",
	"tz_long":"America/New_York"
},
		"period":5,
		"high": {
		"fahrenheit":"88",
		"celsius":"31"
		},
		"low": {
		"fahrenheit":"69",
		"celsius":"21"
		},
		"conditions":"Chance of a Thunderstorm",
		"icon":"chancetstorms",
		"icon_url":"http://icons.wxug.com/i/c/k/chancetstorms.gif",
		"skyicon":"",
		"pop":50,
		"qpf_allday": {
		"in": 0.34,
		"mm": 9
		},
		"qpf_day": {
		"in": 0.26,
		"mm": 7
		},
		"qpf_night": {
		"in": 0.08,
		"mm": 2
		},
		"snow_allday": {
		"in": 0.0,
		"cm": 0.0
		},
		"snow_day": {
		"in": 0.0,
		"cm": 0.0
		},
		"snow_night": {
		"in": 0.0,
		"cm": 0.0
		},
		"maxwind": {
		"mph": 15,
		"kph": 24,
		"dir": "S",
		"degrees": 180
		},
		"avewind": {
		"mph": 10,
		"kph": 16,
		"dir": "S",
		"degrees": 180
		},
		"avehumidity": 62,
		"maxhumidity": 0,
		"minhumidity": 0
		}
		,
		{"date":{
	"epoch":"1436914800",
	"pretty":"7:00 PM EDT on July 14, 2015",
	"day":14,
	"month":7,
	"year":2015,
	"yday":194,
	"hour":19,
	"min":"00",
	"sec":0,
	"isdst":"1",
	"monthname":"July",
	"monthname_short":"Jul",
	"weekday_short":"Tue",
	"weekday":"Tuesday",
	"ampm":"PM",
	"tz_short":"EDT",
	"tz_long":"America/New_York"
},
		"period":6,
		"high": {
		"fahrenheit":"87",
		"celsius":"31"
		},
		"low": {
		"fahrenheit":"70",
		"celsius":"21"
		},
		"conditions":"Partly Cloudy",
		"icon":"partlycloudy",
		"icon_url":"http://icons.wxug.com/i/c/k/partlycloudy.gif",
		"skyicon":"",
		"pop":20,
		"qpf_allday": {
		"in": 0.00,
		"mm": 0
		},
		"qpf_day": {
		"in": 0.00,
		"mm": 0
		},
		"qpf_night": {
		"in": 0.00,
		"mm": 0
		},
		"snow_allday": {
		"in": 0.0,
		"cm": 0.0
		},
		"snow_day": {
		"in": 0.0,
		"cm": 0.0
		},
		"snow_night": {
		"in": 0.0,
		"cm": 0.0
		},
		"maxwind": {
		"mph": 10,
		"kph": 16,
		"dir": "W",
		"degrees": 274
		},
		"avewind": {
		"mph": 8,
		"kph": 13,
		"dir": "W",
		"degrees": 274
		},
		"avehumidity": 65,
		"maxhumidity": 0,
		"minhumidity": 0
		}
		,
		{"date":{
	"epoch":"1437001200",
	"pretty":"7:00 PM EDT on July 15, 2015",
	"day":15,
	"month":7,
	"year":2015,
	"yday":195,
	"hour":19,
	"min":"00",
	"sec":0,
	"isdst":"1",
	"monthname":"July",
	"monthname_short":"Jul",
	"weekday_short":"Wed",
	"weekday":"Wednesday",
	"ampm":"PM",
	"tz_short":"EDT",
	"tz_long":"America/New_York"
},
		"period":7,
		"high": {
		"fahrenheit":"88",
		"celsius":"31"
		},
		"low": {
		"fahrenheit":"69",
		"celsius":"21"
		},
		"conditions":"Partly Cloudy",
		"icon":"partlycloudy",
		"icon_url":"http://icons.wxug.com/i/c/k/partlycloudy.gif",
		"skyicon":"",
		"pop":20,
		"qpf_allday": {
		"in": 0.00,
		"mm": 0
		},
		"qpf_day": {
		"in": 0.00,
		"mm": 0
		},
		"qpf_night": {
		"in": 0.00,
		"mm": 0
		},
		"snow_allday": {
		"in": 0.0,
		"cm": 0.0
		},
		"snow_day": {
		"in": 0.0,
		"cm": 0.0
		},
		"snow_night": {
		"in": 0.0,
		"cm": 0.0
		},
		"maxwind": {
		"mph": 10,
		"kph": 16,
		"dir": "W",
		"degrees": 265
		},
		"avewind": {
		"mph": 8,
		"kph": 13,
		"dir": "W",
		"degrees": 265
		},
		"avehumidity": 66,
		"maxhumidity": 0,
		"minhumidity": 0
		}
		,
		{"date":{
	"epoch":"1437087600",
	"pretty":"7:00 PM EDT on July 16, 2015",
	"day":16,
	"month":7,
	"year":2015,
	"yday":196,
	"hour":19,
	"min":"00",
	"sec":0,
	"isdst":"1",
	"monthname":"July",
	"monthname_short":"Jul",
	"weekday_short":"Thu",
	"weekday":"Thursday",
	"ampm":"PM",
	"tz_short":"EDT",
	"tz_long":"America/New_York"
},
		"period":8,
		"high": {
		"fahrenheit":"87",
		"celsius":"31"
		},
		"low": {
		"fahrenheit":"68",
		"celsius":"20"
		},
		"conditions":"Chance of Rain",
		"icon":"chancerain",
		"icon_url":"http://icons.wxug.com/i/c/k/chancerain.gif",
		"skyicon":"",
		"pop":40,
		"qpf_allday": {
		"in": 0.01,
		"mm": 0
		},
		"qpf_day": {
		"in": 0.01,
		"mm": 0
		},
		"qpf_night": {
		"in": 0.00,
		"mm": 0
		},
		"snow_allday": {
		"in": 0.0,
		"cm": 0.0
		},
		"snow_day": {
		"in": 0.0,
		"cm": 0.0
		},
		"snow_night": {
		"in": 0.0,
		"cm": 0.0
		},
		"maxwind": {
		"mph": 10,
		"kph": 16,
		"dir": "NW",
		"degrees": 319
		},
		"avewind": {
		"mph": 7,
		"kph": 11,
		"dir": "NW",
		"degrees": 319
		},
		"avehumidity": 63,
		"maxhumidity": 0,
		"minhumidity": 0
		}
		,
		{"date":{
	"epoch":"1437174000",
	"pretty":"7:00 PM EDT on July 17, 2015",
	"day":17,
	"month":7,
	"year":2015,
	"yday":197,
	"hour":19,
	"min":"00",
	"sec":0,
	"isdst":"1",
	"monthname":"July",
	"monthname_short":"Jul",
	"weekday_short":"Fri",
	"weekday":"Friday",
	"ampm":"PM",
	"tz_short":"EDT",
	"tz_long":"America/New_York"
},
		"period":9,
		"high": {
		"fahrenheit":"88",
		"celsius":"31"
		},
		"low": {
		"fahrenheit":"67",
		"celsius":"19"
		},
		"conditions":"Chance of a Thunderstorm",
		"icon":"chancetstorms",
		"icon_url":"http://icons.wxug.com/i/c/k/chancetstorms.gif",
		"skyicon":"",
		"pop":50,
		"qpf_allday": {
		"in": 0.23,
		"mm": 6
		},
		"qpf_day": {
		"in": 0.16,
		"mm": 4
		},
		"qpf_night": {
		"in": 0.07,
		"mm": 2
		},
		"snow_allday": {
		"in": 0.0,
		"cm": 0.0
		},
		"snow_day": {
		"in": 0.0,
		"cm": 0.0
		},
		"snow_night": {
		"in": 0.0,
		"cm": 0.0
		},
		"maxwind": {
		"mph": 10,
		"kph": 16,
		"dir": "E",
		"degrees": 87
		},
		"avewind": {
		"mph": 7,
		"kph": 11,
		"dir": "E",
		"degrees": 87
		},
		"avehumidity": 62,
		"maxhumidity": 0,
		"minhumidity": 0
		}
		,
		{"date":{
	"epoch":"1437260400",
	"pretty":"7:00 PM EDT on July 18, 2015",
	"day":18,
	"month":7,
	"year":2015,
	"yday":198,
	"hour":19,
	"min":"00",
	"sec":0,
	"isdst":"1",
	"monthname":"July",
	"monthname_short":"Jul",
	"weekday_short":"Sat",
	"weekday":"Saturday",
	"ampm":"PM",
	"tz_short":"EDT",
	"tz_long":"America/New_York"
},
		"period":10,
		"high": {
		"fahrenheit":"86",
		"celsius":"30"
		},
		"low": {
		"fahrenheit":"67",
		"celsius":"19"
		},
		"conditions":"Chance of a Thunderstorm",
		"icon":"chancetstorms",
		"icon_url":"http://icons.wxug.com/i/c/k/chancetstorms.gif",
		"skyicon":"",
		"pop":50,
		"qpf_allday": {
		"in": 0.21,
		"mm": 5
		},
		"qpf_day": {
		"in": 0.12,
		"mm": 3
		},
		"qpf_night": {
		"in": 0.09,
		"mm": 2
		},
		"snow_allday": {
		"in": 0.0,
		"cm": 0.0
		},
		"snow_day": {
		"in": 0.0,
		"cm": 0.0
		},
		"snow_night": {
		"in": 0.0,
		"cm": 0.0
		},
		"maxwind": {
		"mph": 10,
		"kph": 16,
		"dir": "ENE",
		"degrees": 74
		},
		"avewind": {
		"mph": 7,
		"kph": 11,
		"dir": "ENE",
		"degrees": 74
		},
		"avehumidity": 61,
		"maxhumidity": 0,
		"minhumidity": 0
		}
		]
		}
	}
}

mask obviously cuts this down a lot, but still returns a very long string…

"83~68~Chance of a Thunderstorm~50~86~65~Clear~0~88~65~Partly Cloudy~0~92~68~Partly Cloudy~0~87~69~Chance of a Thunderstorm~50~88~70~Partly Cloudy~20~88~66~Partly Cloudy~20~87~67~Chance of Rain~40~88~69~Chance of a Thunderstorm~50~86~67~Chance of a Thunderstorm~50~\... 

the data runs on and on for 10 days worth which gets broken into more than one webhook return. that makes it hard to parse… because the handler is getting called more than once. I tried filtering with:

if (strstr(event, "Vera_controller/nj_forecast/0"));

but if the JSON is less than one ‘page’ that does not work.

I’m only interested in two days, not 10. Can someone help get this shortened up… somehow use “period” 1 and “period” 2 only perhaps?

so, I just decided to ignore the extra data if it flows over to multiple returns:

  else if (strstr(event, "nj_forecast"))
  {
    if (strstr(event, "nj_forecast/1") || strstr(event, "nj_forecast/2"))
    {
      // don't look at any of these
    }
    else
    {
      gotForecast(event, data);
    }
  }
1 Like

@peekay123 The future is here :smiley:

https://import.io/ looks promising as well.

2 Likes

OK, I just want to read one URL and get two small data items from it. I was confused about how to do this so I read this thread. Now I’m really confused. This is the URL: Sunrise/Sunset times It returns something like this:

{“results”:{“sunrise”:“5:03:21 AM”,“sunset”:“7:25:52 PM”,“solar_noon”:“12:14:36 PM”,“day_length”:“14:22:31”,“civil_twilight_begin”:“4:33:47 AM”,“civil_twilight_end”:“7:55:26 PM”,“nautical_twilight_begin”:“3:57:16 AM”,“nautical_twilight_end”:“8:31:57 PM”,“astronomical_twilight_begin”:“3:17:11 AM”,“astronomical_twilight_end”:“9:12:02 PM”},“status”:“OK”}

All I want is the first two items in there: “sunrise” and “sunset”. It’s not an https page. Could some kind soul please tell me what I need to do on the Photon to get those two values? I don’t want to go through the Spark cloud either. Is this even possible? Thanks.

@Michele, did you see this post?

:smile:

1 Like

Thanks! That looks great. Unfortunately, I can’t get it to compile. The example in the library compiles fine by itself, but when I try to include it in my code, I get

weatherlcd.cpp:337:72: error: ‘IsDST’ was not declared in this scope

I tried adding a forward declaration like this:

bool IsDST (int day, int month, int weekday) ;

but then got this:

Sunrise/Sunrise.cpp: In member function ‘int Sunrise::Compute(unsigned char, unsigned char, int)’:
Sunrise/Sunrise.cpp:101:1: warning: control reaches end of non-void function [-Wreturn-type]
…/…/…/build/target/user/platform-6/libuser.a(weatherlcd.o): In function loop': weatherlcd.cpp:337: undefined reference toIsDST(int, int, int)'
collect2: error: ld returned 1 exit status

Obviously, I don’t know what I’m doing. I’m more of a Matlab programmer. Could you tell me what I’m doing wrong? Thanks.

@Michele, can you post your code, at least the code around line 337.

I don’t want to post the entire program since it’s over 1300 lines. I kept all the relevant parts in the same sections as in the example. Line 337 is the call to IsDST that the compiler seems not to like.

Now that I think of it, where is IsDST defined? I don’t see it in the Sunrise library.

void loop()
{
  //Keep track of which minute it is
  if(millis() - lastSecond >= 1000)
  {
    lastSecond += 1000;
 
  // Set the LCD brightness. 0 = off, 100 = full.  8 is good for night viewing.   
  if (curHour > 20 || curHour < 9)  // Dim the display between 9 PM and 8 AM
     lcd.setBacklight (8) ;
  else
     lcd.setBacklight (18) ;
     
  bool daylightSavings = IsDST(Time.day(), Time.month(), Time.weekday());
  Time.zone(daylightSavings? -4 : -5);

did you include the whole function in your program?

The DST function isn’t a class member function:

bool IsDST(int dayOfMonth, int month, int dayOfWeek)  // North American Algorithm
{
  if (month < 3 || month > 11)
  {
    return false;
  }
  if (month > 3 && month < 11)
  {
    return true;
  }
  int previousSunday = dayOfMonth - dayOfWeek;
  //In march, we are DST if our previous sunday was on or after the 8th.
  if (month == 3)
  {
    return previousSunday >= 8;
  }
  //In november we must be before the first sunday to be dst.
  //That means the previous sunday must be before the 1st.
  return previousSunday <= 0;
}
1 Like

Oops. I guess it helps to scroll all the way down to the end of the code. Doh! Am I ever embarrassed. Thanks.

1 Like

Yu shood bee.

Me nevr make misteaks.

:stuck_out_tongue_winking_eye:

2 Likes

I almost hate to bring this up, but while the code compiles now, the results are wrong. This is the output I get from the unmodified sunriseexample.ino on my Photon:

Solar Noon at 11:55
The sun rises Today at 2:34
The sun sets on Today at 21:17

That doesn’t seem quite right for Princeton, NJ. The Photon is connected to the net, and the Time.whatever() functions are returning correct values.

hmmmm… I cannot figure out what I screwed up there…

Try this and let me know if you are happier, and if you understand what I did:

#include "application.h"
#include "Sunrise/Sunrise.h"
#include "math.h"

// create a Sunrise object
Sunrise winterSunrise(40.3571,-74.6702, -5);//Princeton, New Jersey, USA - Latitude/Longitude and UTC offset
Sunrise summerSunrise(40.3571, -74.6702,-4);//Princeton, New Jersey, USA - Latitude/Longitude and UTC offset

void setup(){
  Serial.begin(9600);
  winterSunrise.Actual(); //Actual, Civil, Nautical, Astronomical
  summerSunrise.Actual();
  while(Time.year() <= 1970)
  {
    Spark.syncTime();  
    Spark.process();
    delay(100);
  }
}

void loop()
{
  Sunrise* currentSetting;
  bool daylightSavings = IsDST(Time.day(), Time.month(), Time.weekday());
  Time.zone(daylightSavings? -4 : -5);
  Serial.println(Time.timeStr());
  Serial.println(daylightSavings? "Currently is DST" : "Currently not DST");
  if(daylightSavings)
  {
    currentSetting = &summerSunrise;
  }
  else
  {
    currentSetting = &winterSunrise;
  }
  byte h,m;
  int t;
  // t= minutes past midnight of sunrise
  t = currentSetting->Rise(Time.month(),Time.day()); // (month,day) - january=1
  if(t >= 0)
  {
    h = currentSetting->sun_Hour();
    m = currentSetting->sun_Minute();
    Serial.print("The sun rises Today at ");
    Serial.print(h, DEC);
    Serial.print(":");
    if(m<10) 
    {
      Serial.print("0");
    }
    Serial.println(m,DEC);
  }
  // t= minutes past midnight of sunset
  t = currentSetting->Set(Time.month(),Time.day()); // (month,day) - january=1
  if(t >= 0)
  {
    h = currentSetting->sun_Hour();
    m = currentSetting->sun_Minute();
    Serial.print("The sun sets on Today at ");
    Serial.print(h, DEC);
    Serial.print(":");
    if(m<10) 
    {
      Serial.print("0");
    }
    Serial.println(m,DEC);
  }
  // t= minutes past midnight of solar noon
  t = currentSetting->Noon(Time.month(),Time.day()); // (month,day) - january=1
  if(t >= 0)
  {
    h=currentSetting->sun_Hour();
    m=currentSetting->sun_Minute();
    Serial.print("Solar Noon at ");
    Serial.print(h, DEC);
    Serial.print(":");
    if(m<10) 
    {
      Serial.print("0");
    }
    Serial.println(m,DEC);
  }
  else
  {
    Serial.println("There are either penguins or polar bears around here!");
  }
  delay(5000);
}


bool IsDST(int dayOfMonth, int month, int dayOfWeek)
{
  if (month < 3 || month > 11)
  {
    return false;
  }
  if (month > 3 && month < 11)
  {
    return true;
  }
  int previousSunday = dayOfMonth - (dayOfWeek - 1); // Spark Sunday = 1
  //In march, we are DST if our previous sunday was on or after the 8th.
  if (month == 3)
  {
    return previousSunday >= 8;
  }
  //In November we must be before the first sunday to be dst.
  //That means the previous sunday must be before the 1st.
  return previousSunday <= 0;
}

seems to work for me this way!