0% found this document useful (0 votes)
53 views2 pages

Google Sheets Script

This code summarizes an Arduino sketch that sends sensor data from an ESP8266 to a Google Spreadsheet. It parses GET request parameters, strips quotes from values, and writes the data along with a date and time stamp to the spreadsheet. When the code is run, it logs the GET request, handles unsupported parameters, and returns the result of writing the sensor readings and timestamps to the spreadsheet.

Uploaded by

yanuartw7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views2 pages

Google Sheets Script

This code summarizes an Arduino sketch that sends sensor data from an ESP8266 to a Google Spreadsheet. It parses GET request parameters, strips quotes from values, and writes the data along with a date and time stamp to the spreadsheet. When the code is run, it logs the GET request, handles unsupported parameters, and returns the result of writing the sensor readings and timestamps to the spreadsheet.

Uploaded by

yanuartw7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

// Code source: https://create.arduino.

cc/editor/LogMaker360/1104a08f-fb8b-47ff-
8253-1cdc5c11581f/preview
/*
//-----------------------------------------------
// Author: Trieu Le
// Email: [email protected]
// Publish date: 07-Oct-2015
// Description: This code for demonstration send data from ESP8266 into Google
Spreadsheet
// GET request syntax:
// https://script.google.com/macros/s/<gscript id>/exec?header_here=data_here
// Modifyed by Moz for Youtube changel logMaker360 for this video:
https://youtu.be/fS0GeaOkNRw 24-02-2018

//-----------------------------------------------
/**
* Function doGet: Parse received data from GET request,
get and store data which is corresponding with header row in Google Spreadsheet
*/
function doGet(e) {
Logger.log( JSON.stringify(e) ); // view parameters
var result = 'Ok'; // assume success
if (e.parameter == 'undefined') {
result = 'No Parameters';
}
else {
var sheet_id = 'Youre_Spreadsheet_ID'; // Spreadsheet ID
var sheet = SpreadsheetApp.openById(sheet_id).getActiveSheet(); // get
Active sheet
var newRow = sheet.getLastRow() + 1;
var rowData = [];
var Curr_Date = new Date();
rowData[0] = Curr_Date;
// Date in column A
var Curr_Time = Utilities.formatDate(Curr_Date, "Asia/Jakarta", 'HH:mm:ss');
rowData[1] = Curr_Time;
// Time in column B
for (var param in e.parameter) {
Logger.log('In for loop, param=' + param);
var value = stripQuotes(e.parameter[param]);
Logger.log(param + ':' + e.parameter[param]);
switch (param) {
case 'LDR': //Parameter
rowData[2] = value; //Value in column C
break;
case 'Button': //Parameter
rowData[3] = value; //Value in column D
break;
default:
result = "unsupported parameter";
}
}
Logger.log(JSON.stringify(rowData));
// Write new row below
var newRange = sheet.getRange(newRow, 1, 1, rowData.length);
newRange.setValues([rowData]);
}
// Return result of operation
return ContentService.createTextOutput(result);
}
/**
* Remove leading and trailing single or double quotes
*/
function stripQuotes(value) {
return value.replace(/^["']|['"]$/g, "");
}
//-----------------------------------------------
// End of file
//-----------------------------------------------

You might also like