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.   



Connect Beam to Particle Photon

Follow the hookup guide here

Register your webhook on Particle Cloud

We're going to use 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 ""
particle webhook GET get_stocks ""

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.  

void loop() {
 if (runNow == 1){
 delay 30 seconds so that weather data gets scrolled
 for a few seconds before being overwritten by stocks data
 runNow = 0;
 updateTimer = millis();

 wait 45 seconds before calling our publish functions again
 if (millis() - updateTimer > 45000){
 runNow = 1;

 // do something else here

Once our webhooks return some data, the callback functions gotWeatherData or gotStocksData is called. Let's use the gotWeatherData as an example. We first try to extract the appropriate data by calling tryExtractString on our data variable. Then we combine the data to a new string that we want to print to Beam. 

String beamWeather = weatherStr + ", " + tempStr + String("'F ");

Then we convert the String to a char array expected by the Beam library and call the Beam library's print and play function. Then bam, the text should appear on Beam.  

char buf[1024];
beamWeather.toCharArray(buf, 1024);

Going further

To take this example further and get your news feeds, you can actually parse any RSS feeds and output to Beam. For more details on the specific Beam library functions, click on this link. The Beam library has more functions that lets you play with the scroll speed, direction, mode, etc. 

Hopefully at this point, your project is working as expecting.  Any easy way to make sure everything is working is to open up your serial monitor and check for debug messages being printed by the Beam library. We highly recommend following the quick start guide here. If it's still not working, double check your wiring or email us at