Send sensor data to Google BigQuery

In this tutorial we'll show you how to use your microcontroller to send data to Google BigQuery. This will enable you to store and query large amounts of sensor data extremely efficiently.

This sketch uses our Google > BigQuery > InsertAll Choreo.

Get Set Up

1Make sure you have a Temboo account. If you don't already have one, you can register for a free account here.

2Next, make sure that you've got the latest version of the Energia IDE installed.

3Since this sketch uses Google BigQuery, you'll need a BigQuery account and you'll need to go through the OAuth process so that you can programmatically send sensor data to your BigQuery account. Head over to our BigQuery Choreo instructions and get set up. Here's one helpful tip: when you get to the BigQuery OAuth process, it's sufficient to specify the following scope as an input to the InitializeOAuth Choreo:


4As you're going through the BigQuery setup process, make sure to save the ProjectID, ClientID, ClientSecret, and RefreshToken that you generate while setting up your BigQuery app and running through the OAuth process - you'll need them while generating code in the next section.

Create Your Dataset & Table

5Now, log into the BigQuery console and create a new dataset called TembooSensorReadings.

BigQuery create dataset

6Next, create a table within your dataset called SensorReadings. Here's the details for your table:

Here's a screenshot showing you how everything should look.

BigQuery create table

Generate your BigQuery Code

7Now, go to the BigQuery > TableData > InsertAll Choreo. Make sure that IoT Mode is turned on and that you've selected the microcontoller device that you're generating code for.

8Next, fill out all the required inputs. You'll need to use the project ID for the BigQuery app you set up earlier, along with its ClientID and ClientSecret. You'll also need your OAuth refresh token, the name of your dataset (TembooSensorReadings) for the DatasetID, and your sensor data table name (SensorReadings) for the TableID. Finally, add some JSON describing the sensor data that you want to send to BigQuery. Here's some you can use that matches the schema that we set up earlier:

    "json": {
      "Temperature": 30,
      "Humidity": 35

BigQuery Choreo inputs

9Once you've got all of your inputs filled in, you can run the Choreo and add a row of data to BigQuery. This will prove that everything is working correctly and we can move on to trying out our generated code. To check that your data is adding to BigQuery successfully, you can compose a SELECT * ... query in the BigQuery query composer and you should see the two rows of data the we've added so far.

BigQuery results

Run The Code

10Scroll down and copy the LaunchPad code from the Code section and paste it into your Energia IDE.

11The auto-generated sketch references the TembooAccount.h header file, which contains your Temboo account information and internet shield details. You'll find the code for this file beneath your generated sketch. Create a new tab in Energia called TembooAccount.h and copy in the header file information.

Extending The Sketch

You'll notice that your sketch always sends the same value to BigQuery - the values we were testing with. Of course, it's far more interesting to send dynamic values i.e., sensor values.

12We outline how to extend any Temboo sketch so that it's sending dynamic sensor data in the "Extending the sketch" section of our Google Spreadsheets tutorial, so take a look at that one to see how you can extend your sketch to send real sensor values to BigQuery. Take care when substituting dynamic variables into the JSON string that you're sending to BigQuery.

13Once you've extended your sketch, you can run it again and you'll be sending live sensor values to BigQuery from your Launchpad. Head back over to your BigQuery console and run the SELECT * ... query again to see the live sensor data.

What's Next?

Now that you've mastered working with BigQuery, why not check out the rest of the 2000+ Choreos in our Library and get inspired for your next project.

Need Help?

We're always happy to help. Just email us at support@temboo.com, and we'll answer your questions.