Parsing web pages/data to control servos/leds?

As @peekay123 mentionned, the best way to debug this is take it step by step.

I put this in a webhook JSON template surf.json (except that I used a real API key):

{
  "event": "surf_hook",
  "url": "http://magicseaweed.com/api/apikey/forecast?spot_id=1253",
  "requestType": "POST",
  "headers": null,
  "query": null,
  "json": null,
  "auth": null,
  "mydevices": true
}

Created a webhook with particle webhook create surf.json while monitoring with particle subscribe mine in one terminal I published the event with particle publish surf_hook in another terminal.

I got this in the particle subscribe mine

{"name":"surf_hook","data":"undefined","ttl":"60","published_at":"2015-12-09T03:09:28.264Z","coreid":"001"}
{"name":"hook-sent/surf_hook","data":"undefined","ttl":"60","published_at":"2015-12-09T03:09:28.266Z","coreid":"particle-internal"}
{"name":"hook-response/surf_hook/0","data":"{\"error_response\":{\"code\":119,\"error_msg\":\"Path or method restricted for your API key.\"}}","ttl":"60","published_at":"2015-12-09T03:09:28.372Z","coreid":"particle-internal"}

I then noticed that the webhook JSON you posted said to POST the request instead of doing a GET. POST is usually for submitting a form or creating a resource on a web server. GET is for retrieving a page.

I switched surf.json to:

{
  "event": "surf_hook",
  "url": "http://magicseaweed.com/api/apikey/forecast?spot_id=1253",
  "requestType": "GET",
  "headers": null,
  "query": null,
  "json": null,
  "auth": null,
  "mydevices": true
}

Deleted the 1st webhook and tried again. I got a huge amount of output

{"name":"surf_hook","data":"undefined","ttl":"60","published_at":"2015-12-09T03:10:17.851Z","coreid":"001"}
{"name":"hook-sent/surf_hook","data":"undefined","ttl":"60","published_at":"2015-12-09T03:10:17.854Z","coreid":"particle-internal"}
{"name":"hook-response/surf_hook/0","data":"[{\"timestamp\":1449619200,\"localTimestamp\":1449619200,\"issueTimestamp\":1449597600,\"fadedRating\":4,\"solidRating\":1,\"swell\":{\"minBreakingHeight\":8,\"absMinBreakingHeight\":8.2,\"maxBreakingHeight\":13,\"absMaxBreakingHeight\":12.81,\"unit\":\"ft\",\"components\":{\"combined\":{\"height\":11.5,\"period\":12,\"direction\":67.52,\"compassDirection\":\"WSW\"},\"primary\":{\"height\":11.5,\"period\":12,\"direction\":71.17,\"compassDirection\":\"WSW\"}}},\"wind\":{\"speed\":19,\"direction\":66,\"compassDirection\":\"WSW\",\"chill\":39,\"gusts\":23,\"unit\":\"mph\"},\"co","ttl":"60","published_at":"2015-12-09T03:10:17.986Z","coreid":"particle-internal"}
{"name":"hook-response/surf_hook/1","data":"ndition\":{\"pressure\":1032,\"temperature\":53,\"weather\":12,\"unitPressure\":\"mb\",\"unit\":\"f\"},\"charts\":{\"swell\":\"http:\\/\\/hist-1.msw.ms\\/wave\\/750\\/1-1449619200-1.gif\",\"period\":\"http:\\/\\/hist-1.msw.ms\\/wave\\/750\\/1-1449619200-2.gif\",\"wind\":\"http:\\/\\/hist-1.msw.ms\\/gfs\\/750\\/1-1449619200-4.gif\",\"pressure\":\"http:\\/\\/hist-1.msw.ms\\/gfs\\/750\\/1-1449619200-3.gif\",\"sst\":\"http:\\/\\/hist-1.msw.ms\\/sst\\/750\\/1-1449619200-10.gif\"}},{\"timestamp\":1449630000,\"localTimestamp\":1449630000,\"issueTimestamp\":1449597600,\"fadedRating\"","ttl":"60","published_at":"2015-12-09T03:10:18.239Z","coreid":"particle-internal"}
...

I then put the responseTemplate I mentioned above:

{
  "event": "surf_hook",
  "url": "http://magicseaweed.com/api/apikey/forecast?spot_id=1253",
  "requestType": "GET",
  "headers": null,
  "query": null,
  "responseTemplate": "{{#0}}{{#swell}}{{#components}}{{#combined}}{{period}}~{{height}}{{/combined}}{{/components}}{{/swell}}{{/0}}",
  "json": null,
  "auth": null,
  "mydevices": true
}

Tried again and got:

{"name":"surf_hook","data":"undefined","ttl":"60","published_at":"2015-12-09T03:10:57.815Z","coreid":"001"}
{"name":"hook-sent/surf_hook","data":"undefined","ttl":"60","published_at":"2015-12-09T03:10:57.816Z","coreid":"particle-internal"}
{"name":"hook-response/surf_hook/0","data":"12~11.5","ttl":"60","published_at":"2015-12-09T03:10:57.940Z","coreid":"particle-internal"}

That should do it for you @surfershort

2 Likes