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.

Get your morning update with Beam

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


About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.