#10 — Publish Sensor Readings to Google Sheets

Carissa Aurelia
I learn ESP32 (and you should too).
5 min readApr 25, 2020

What??? Really??? How???

Just a spreadsheet :)

If you asked those questions then congrats!! Soon enough we’ll figure out just how we can do it :)

According to randomnerdtutorials.com’s website, integrating ESP32 directly to google sheets will have to bypass HTTPS authentication. To make things easier for our lives, we’re gonna be using IFTTT, a third party service.

OK, what is IFTTT?

If this then that.

Wait — what??

Yep, you heard it right. It’s a freeware web-based service serves to connect services through a “simple” conditional statement called applet. Services are basically apps and devices that we use every day such as social media, productivity apps, or hardware devices like smart speakers and lights. For example, we can create an applet that sends an email every time we tweet something on Twitter. In this case, the services are our email provider and Twitter.

In a nutshell, we’ll create an applet that connects Webhooks and Google Spreadsheet. I think I don’t have to explain Google Spreadsheet to you — it’s pretty self-explanatory, really.

Yea, but what kind of thing is Webhooks?

Technically, webhooks are user-defined callbacks made with HTTP. They are data and executable commands sent from one app to another over HTTP instead of through the command line in the computer. Don’t get your head in a twist now. Basically, it’s just a way in which apps can send automated messages or information to other apps.

When an event happens on the “trigger” application, the app will serialize data about that event and sends it to a webhook URL from the “action” application (the application that processes the data from the “trigger” application). The action application can then send a callback message, often with an HTTP status code like 302 to let the trigger application know if the data was received successfully or 404 if not.

You probably have heard of APIs — actually, webhooks are APIs similar counterpart with a much simpler mechanism. If you build an application that connects to another with an API, your application will need to have ways to ask the other app for new data when it needs it. Webhooks, on the other hand, are automated — the app won’t have to ask for data over and over again. It’s a simple, one-to-one connection that runs automatically.

Roughly, the program will work as follows:

  • The ESP32 connects to nearby Wi-Fi network;
  • The BMP180 takes the temperature and pressure readings;
  • The ESP32 then communicates with the IFTTT Webhooks service that publishes the readings to a spreadsheet on Google Sheets that is saved in your Google Drive’s folder;
  • After that, the ESP32 goes into deep sleep mode for 30 minutes;
  • The ESP32 wakes up after 5 minutes and the process repeats.

Let’s jump right in!

1. The Ingredients and the wiring

:)

Same ‘ol ESP32 board, same ‘ol laptop, same ‘ol jumper wires and BMP180 sensor. You’re probably tired of reading this. But you know the drill, mijo. Follow the wiring in this post and you’re good to go.

2. The thing with the IFTTT

Sign yourself up for an account in the IFTTT website. Follow the diagram below to create an applet that connects Webhooks and Google Spreadsheet.

How to make applet: a diagram.

When the applet is done, head to the Webhooks Service page and click on Documentation on the top right corner beside Settings. You’ll find this page displayed.

Webhooks service page

There is a unique API key to authorize the service that makes a web request to the maker.ifttt.com. Don’t share this key with anyone!

To test whether our applet is functional or not, we can type in the event name and the values at the given boxes then hit the “Test It” button.

Testing it

A notification will appear that the test is successful. We can check the Google Sheet to make sure. If you follow the diagram, the sheet will be located in the IFTTT folder in your Google Drive.

Where the sheets are

And bam! You can see our test data there!! Honestly, I’m so excited the first time I see it — so cool!!

!!!

3. Code, code

My partner, Kevin Cahyadi Giri, works to change a few bits of the code so that it’s compatible with BMP180. Basically, what you need to change is the ssid and password variables, as well as the resource variable. The resource should contain the unique IFTTT URL resource like /trigger/<event name>/with/key/<your key here> . Also, because the BMP180 can’t read humidity, we changed it with a comment string.

4. The step we’ve all been waiting for

Moment of truth… (drumrolls please).

After making all the necessary changes, upload the code to the ESP32. Press enable on the board and lookie, lookie!

IT WORKS! IT WOOORKS!!

--

--