Get your morning update with Beam
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.
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"
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
EasyEDA: Ideas for Circuit Design, Innovation for Electronics Access
Free Circuit Design: Schematic – Simulation – PCB Layout – Gerber Viewer
JLCPCB Prototype: Only $2 for 10pcs 10×10cm, 24 hours Quick Turn, DHL Delivery in 3 days