Hi All,
I’m a newbie working on a little project - the goal is to visualize busses approaching a particular bus stop using a RGB LED strip.
So far I’ve managed to consult the MBTA API for arrival times, parse the times out of the JSON using mustache, and configure a webhook which provides this data through particle publish.
Example of a single result: http://pasteboard.co/1vdrUMSY.png
I was excited to make it this far, but now I’m a bit stuck. When there is more than one bus approaching, I will receive 1-10 epoch times all in a row.
Result ex with 3 busses: 145524366014552434201455243960
What would be the most effective way of pulling and parsing the webhook result in firmware?
Ideally I would like to light a LED in a specific position on a timeline for each of the 3 results above.
Much thanks from a newbie!
Rob
Example of the JSON result I’m working with:
{
"stop_id": "2152",
"stop_name": "Concord Ave opp Fawcett St",
"mode": [
{
"route_type": "3",
"mode_name": "Bus",
"route": [
{
"route_id": "74",
"route_name": "74",
"direction": [
{
"direction_id": "1",
"direction_name": "Inbound",
"trip": [
{
"trip_id": "29668971",
"trip_name": "9:15 pm from Alexander Ave @ Leonard St to Eliot St @ Bennett St",
"trip_headsign": "Harvard",
"sch_arr_dt": "1455243660",
"sch_dep_dt": "1455243660",
"pre_dt": "1455243628",
"pre_away": "1484"
}
]
}
]
},
{
"route_id": "78",
"route_name": "78",
"direction": [
{
"direction_id": "1",
"direction_name": "Inbound",
"trip": [
{
"trip_id": "29669357",
"trip_name": "9:05 pm from Wadsworth Rd @ Dow Ave to Eliot St @ Bennett St",
"trip_headsign": "Harvard",
"sch_arr_dt": "1455243420",
"sch_dep_dt": "1455243420",
"pre_dt": "1455243420",
"pre_away": "1276"
}
]
}
]
}
]
}
],
"alert_headers": []
}
Example of the mustache code:
{{#mode}}
{{#.}}
{{#route}}
{{#direction}}
{{#trip}}
{{sch_arr_dt}}
{{/trip}}
{{/direction}}
{{/route}}
{{/.}}
{{/mode}}
Example of the webhook definition:
{
"event": "op_fawcett_predict",
"url": "http://realtime.mbta.com/developer/api/v2/predictionsbystop?api_key=5atXWikMk0q8P8RmTMp20Q&stop=2152&format=json",
"requestType": "get",
"headers": null,
"query": null,
"responseTemplate": "{{#mode}}{{#.}}{{#route}}{{#direction}}{{#trip}}{{sch_arr_dt}}{{/trip}}{{/direction}}{{/route}}{{/.}}{{/mode}}",
"json": null,
"auth": null,
"mydevices": true
}
An alternate question would be, how can I get delimiters in my mustache result?