-
Notifications
You must be signed in to change notification settings - Fork 0
/
humidity.gs
48 lines (42 loc) · 1.37 KB
/
humidity.gs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/* Using spreadsheet API */
function doGet(e) {
Logger.log( JSON.stringify(e) ); // view parameters
var result = 'Ok'; // assume success
if (e.parameter == undefined) {
result = 'No Parameters';
}
else {
var id = '16IQP2zjOqVH1qWQJ1IGiygshhNX7mFOuPMxMCBTza-c';
var sheet = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/16IQP2zjOqVH1qWQJ1IGiygshhNX7mFOuPMxMCBTza-c/edit#gid=530749950').getActiveSheet();
var newRow = sheet.getLastRow();
var rowData = [];
//var waktu = new Date();
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 'humiData': //Parameter
rowData[0] = value; //Value in column B
break;
//case 'column_C':
//rowData[2] = value;
//break;
default:
result = "unsupported parameter";
}
}
Logger.log(JSON.stringify(rowData));
// Write new row below
var newRange = sheet.getRange(newRow, 3, 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, "");
}