You wake up in the morning. You’re groggy. You grab your phone lazily and start browsing. You check the weather, your stocks, your instagram. Before you know it, you’re running late! Do your mornings look like this too? We’ve been there! We wanted to streamline our mornings so we built a morning feed so that we can get all the info while we brush our teeth. Multitasking FTW! In this example, we’re going to get the daily forecast, temperature and stock update and scroll it on Beam with a Particle Photon.
Connect Beam to Particle Photon
Follow the hookup guide here.
Register your webhook on Particle Cloud
We’re going to use weather.gov and yahoo apis to get our weather and stock feed, respectively. In the Particle CLI, register your weather and stocks webhook with the following code.
particle webhook GET get_weather "http://w1.weather.gov/xml/current_obs/KSFO.xml" particle webhook GET get_stocks "http://finance.yahoo.com/d/quotes.csv?s=AAPL+FB+GOOG+NFLX+TSLA&f=sp2"
If you haven’t setup your Particle CLI, visit this link: Particle CLI Setup. For more info on webhooks, click here: Particle Webhooks.
Download Code from Github and Flash!
Download the library and navigate to the /examples/BeamWeatherStocks folder. Copy the library over as well to the Particle IDE and flash!
A few notes on the code:
The subscribe method registers callback functions called gotWeatherData and gotStocksData to our webhook.
Particle.subscribe("hook-response/get_weather", gotWeatherData, MY_DEVICES); Particle.subscribe("hook-response/get_stocks", gotStocksData, MY_DEVICES);
In the main loop, we first publish our weather webhook. Then we wait 30 seconds so that the weather data is scrolled on Beam. Then we publish our stocks webhook. We set runNow = 0 so that the publish functions are not called on every iteration of the loop — otherwise you’ll reach the max api call limit. So we wait 45 seconds before setting runNow = 1 and then we publish our webhooks in the same sequence again.
For more detail: Get your morning update with Beam