Hi! I am currently having a project that I can measure force from a punch and then send that data to google sheets from an ESP32, but there was a twist, the cell jumped all over the place and I couldn't figure this out. Here's a code in the App Script:
function doGet(e) {
Logger.log(JSON.stringify(e));
var result = 'Ok';
if (e.parameter == 'undefined') {
result = 'No Parameters';
}
else {
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 'forceData':
var ssID = SpreadsheetApp.openById('SHEET_ID');
var sheetName = ssID.getSheetByName('Sheet1');
var newRow = sheetName.getLastRow() + 1;
var rowData = [];
var Curr_Date = new Date();
rowData[1] = Curr_Date; // Date in column A
var Curr_Time = Utilities.formatDate(Curr_Date, "Asia/Bangkok", 'HH:mm:ss');
rowData[2] = Curr_Time; // Time in column B
rowData[3] = value;
result = 'OK';
Logger.log(JSON.stringify(rowData));
var newRange = sheetName.getRange(newRow, 1, 1, rowData.length);
newRange.setValues([rowData]);
break;
case 'forceData2':
var ssID = SpreadsheetApp.openById('1OGZENKSpxyGlRz33WbcSXLVmA7dXGoGw7JDxarpRGY4');
var sheetName = ssID.getSheetByName('Sheet1');
var newRow = sheetName.getLastRow() + 1;
var rowData = [];
rowData[4] = value;
result = 'OK';
Logger.log(JSON.stringify(rowData));
var newRange = sheetName.getRange(newRow, 1, 1, rowData.length);
newRange.setValues([rowData]);
break;
default:
result = "unsupported parameter";
}
}
}
return ContentService.createTextOutput(result);
}
function stripQuotes(value) {
return value.replace(/^["']|['"]$/g, "");
And here's a picture of my problem and also a picture of what I need to do.