X-Ring with Google Calendar

As application for the X-Ring RGB Strip I came up with the following: Querying the next event in my Google Calendar tagged with #wecker and then visualize the remaining time. I have illustrated the structure of all components in the following figure:

Google Calendar

The Wemos D1 mini queries the next event by accessing my Google Calendar. This is done trough a executing a Google Apps Script. Google Apps Script is very powerful because you can use Google Services with ease – everything is well documented, there are so many examples and you can even debug your scripts. Directly accessing the google calendar with read-access as specific user requires authentication (currently with an OAUTH mechanism). I was not able to find a way to register my microcontroller at this OAUTH server easily. So I decided to use a Google Apps Script as proxy – it requires authentication when executing it at the first time. Then it has read-access to your google calendar. This is super simple and flexible.

The script depends on the following libraries:

Moment – https://script.google.com/macros/library/versions/d/15hgNOjKHUG4UtyZl9clqBbl23sDvWMS8pfDJOyIapZk5RBqwL3i-rlCo

QUnit – https://script.google.com/macros/library/versions/d/13agWuzcPH32W4JJvOqOEYqeNHGihS63P2V-a-Vxz-c9WPIzZYBvIhs3m

If you want to run the script you have to add them to your script.

Google Apps Script Libraries

Then you can publish the script as Webapp.

Google Apps Script Publish Webapp

 

The script contains a little testbench to do some unit-tests. You can execute them by adding ?test to the exec URL of the webapp.

You can use your favourite HTTP Client to get the result from your webapp. Please notice that there is a 302 HTTP redirect when you call your webapp. This is visualized in the following figure.

Google Apps Script Webapp Redirect to actual content

You can use curl for example. -L to enable the location header flag to follow redirects

Then you to the final destination which is the output of the Google Apps Script.

Responses are JSON encoded:

No event currently:

Next event:

When you want to query the Google Apps Script from Arduino make sure to use a HTTP Client that follows redirects.

E.g.: https://github.com/cvonk/esp8266-WiFiClientSecureRedirect

MQTT

I like event-driven architectures especially in the IoT-Context. You can build your own eventbus for your home. The MQTT architecture is flexible, adaptive and robust – it perfectly fits my needs. You may ask yourself why MQTT is used at all in this application, because I could just take this event and visualize it on the X-Ring. Of course – but what if I want to add another device using this event information? I would have to refactor my X-Ring Google Calendar Application. I just took this effort already to make it even less coupled and hereby flexible.

Visualization

The app queries for events every 10 minutes. When it does an update it animates a color wheel. Then all LED black. Then it lightens up N LED representing the hours until the next event. I have created two openprocessing script visualizing the colorwheel animation:

 

Result

The is a video of the result. It is not true-color.

I’m looking forward to develop more apps using the X-Ring module. I can recommend it for use with any arduino and microcontroller in general.

Leave a Reply

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