Original nucleus/templates/page.html

Here are some ideas for how you can use Ob2SS for quick prototypes or workflow enhancements. Before we begin any of these tasks, let's go over some boilerplate process: How to set up a new spreadsheet and attach a script to it with Ob2SS running.

Setting up Ob2SS

First, create a new spreadsheet however you like (I do it through Drive).

Create a new Google Spreadsheet.

Go ahead and edit your sheet to suit your needs: give it some headers and a meaningful title.

Next, in the Menu bar, click Tools > Edit Script... to open the script editor.

Edit a new script for this Spreadsheet.

Last, let's addd Ob2SS as a library so you can access the tools it has. In the Menu bar, click Resources > Libraries... and add the Ob2SS Project ID to the box. Select the latest version, but leave Development Mode turned off.

Select to add a new Library from the Menu bar.

Add the latest version of Ob2ss.

Easy Data Logger

Here's a fun simple example of what's possible.

Suppose that you have a collection of Arduino-powered devices over a large area; like a park or a field. You want to record the temperature and humidity for that day in that location and at that time. You could record the data locally and pull it down later or you could set yourself up with some kind of cloud logging solution, but why not record your first round of data easily with a live-updating spreadsheet?

Let's build it with Ob2ss in just a few minutes! After you've created your spreadsheet and script combo like above, let's set it up as a Web App so we can write data to it with a simple GET web request; the same as if you were visiting a webpage. You can read more about Apps Script Web Apps here.

You should follow the Web Apps documentation closely to make sure your application is accessible from the web.

In your new script, write a new function called doPost. It will take in an event parameter that will contain the data your device(s) are trying to write to your handy spreadsheet.

For reference, below is an screenshot of my spreadsheet, and you can see a copy of it here.

My example spreadsheet and its headers.

The headers I'm using here are what I'm looking to record from my network of devices. But how do we get Apps Script to write those objects to the sheet? There're several ways to do it, and it really just depends on your preferences:

  • POST the data as JSON content to be unpacked with JSON.parse().
  • Make a GET request with the data as query string parameters to be read from the event object.

The first option is definitely easier to write as code, but the second option is easier to write about here so we'll be using that.

Here's my code below:

// Manages the submission of data to our new tracker.
function doGet(e) {
  var table = Ob2SS.getTable('data');
  var dataPoint = {
    'Timestamp': new Date(),
    'Lat': e.parameter['Lat'],
    'Long': e.parameter['Long'],
    'Temperature': e.parameter['Temperature'],
    'Humidity': e.parameter['Humidity']
  }

  table.add(dataPoint);
  return HtmlService.createHtmlOutput('<html>Message received.</html>');
}

And that's it! Now this application will take in data via requests from the internet and record the data directly into the sheet. If you want to get clever about it, you can make charts in Google Sheets, then embed those charts in web pages and you can watch your data report in live.

Easy Asset Tracker