Hello, I'm in search for a guide and not a blogpost about somebody doing a project about data logging.
I saw few projects with pushingbox and Google Sheets, but I'd rather use native doGet (HTTPSRedirect) instead of some middleman service. The example and the script and example seem over complicated and there is no information about expanding the script or modifying it. Many projects using this, just say "copy this" without explanation of code.
My use case is Arduino Nano with ESP8266-01 as a shield using SoftwareSerial. There are about 20 parameters to be logged. Maximal data update rate of Google Sheets seems to be 13,8 per minute (833 per hour, 20 000 per day) if I read the table correctly.
This seems to be the most sane and straight forward example project, but the script lacks meaningful var and function names.
I have no knowledge of the Google Apps script.
This is how I would edit the App script for 3 parameters, don't know if it would work.
function doGet(dataStream){
Logger.log("--- doGet ---");
var param1, param2, param3 = "";
try {
param1 = dataStream.parameters.param1;
param2 = dataStream.parameters.param2;
param3 = dataStream.parameters.param3;
// save the data to spreadsheet
SaveDataToSheet(param1, param2, param3);
}
catch(error) {
Logger.log(error);
}
}
// Function to save given data to a sheet
function SaveDataToSheet(param1, param2, param3){
Logger.log("--- SaveDataToSheet ---");
try {
var dateTime = new Date();
// Paste the URL of the Google Sheets starting from https thru /edit
// For e.g.: https://docs.google.com/..../edit
var spreadSheetRoot = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/---Your-Google-Sheet-ID--Goes-Here---/edit");
var rawDataSheet = spreadSheetRoot.getSheetByName("RawData");
// Get last populated row from RawData sheet
var lastRow = rawDataSheet.getLastRow() + 1;
// Start Populating the data
rawDataSheet.getRange("A" + row).setValue(row - 1); // ID
rawDataSheet.getRange("B" + row).setValue(dateTime); // dateTime
rawDataSheet.getRange("C" + row).setValue(param1);
rawDataSheet.getRange("D" + row).setValue(param2);
rawDataSheet.getRange("E" + row).setValue(param3);
}
catch(error) {
Logger.log(JSON.stringify(error));
}
Logger.log("--- Data saved ---");
}
and the Arduino code
String urlFinal = url + “param1=” + param1 + “¶m2=” + String(param2) + “¶m3=” + String(param3);