//------------------------------------------------------------------------
// Created by: Tauseef Ahmad
// Created on: 17 July, 2022
// Tutorial: [Link]
// ------------------------------------------------------------------------
// Enter Spreadsheet ID here
var SS = [Link]('ENTER_SHEET_ID');
var timezone = "asia/karachi"
var hours = 0
var str = "";
function doPost(e) {
var parsedData;
var result = {};
try {
parsedData = [Link]([Link]);
}
catch(f){
return [Link]("Error in parsing request body: " +
[Link]);
}
if (parsedData !== undefined){
var flag = [Link];
if (flag === undefined){
flag = 0;
}
var sheet = [Link](parsedData.sheet_name); // sheet name to publish
data to is specified in Arduino code
var dataArr = [Link](","); // creates an array of the values
to publish
//var date_now = [Link](new Date(), "CST", "yyyy/MM/dd"); // gets
the current date
//var time_now = [Link](new Date(), "CST", "hh:mm:ss a"); // gets
the current time
var Curr_Date = new Date(new Date().setHours(new Date().getHours() + hours));
var Curr_Time = [Link](Curr_Date, timezone, 'HH:mm:ss');
var value0 = dataArr [0]; // value0 from Arduino code - Student ID
var value1 = dataArr [1]; // value1 from Arduino code - First Name
var value2 = dataArr [2]; // value2 from Arduino code - Last Name
var value3 = dataArr [3]; // value0 from Arduino code - Phone Number
var value4 = dataArr [4]; // value1 from Arduino code - Address
// read and execute command from the "payload_base" string specified in Arduino
code
switch ([Link]) {
case "insert_row":
[Link](2); // insert full row directly below header text
//var range = [Link]("A2:D2"); // use this to insert
cells just above the existing data instead of inserting an entire row
//[Link]([Link]); // use this to insert
cells just above the existing data instead of inserting an entire row
[Link]('A2').setValue(Curr_Date); // publish current date to cell
A2
[Link]('B2').setValue(Curr_Time); // publish current time to cell
B2
[Link]('C2').setValue(value0); // publish Student ID from
Arduino code to cell C2
[Link]('D2').setValue(value1); // publish First Name from
Arduino code to cell D2
[Link]('E2').setValue(value2); // publish Last Name from Arduino
code to cell E2
[Link]('F2').setValue(value3); // publish Phone Number from
Arduino code to cell F2
[Link]('G2').setValue(value4); // publish Address from Arduino
code to cell G2
str = "Success"; // string to return back to Arduino serial console
[Link]();
break;
case "append_row":
var publish_array = new Array(); // create a new array
publish_array [0] = date_now; // add current date to position 0 in
publish_array
publish_array [1] = time_now; // add current time to position 1 in
publish_array
publish_array [2] = value0; // add value0 from Arduino code to position
2 in publish_array
publish_array [3] = value1; // add value1 from Arduino code to position
3 in publish_array
publish_array [4] = value2; // add value2 from Arduino code to position
4 in publish_array
[Link](publish_array); // publish data in publish_array after the
last row of data in the sheet
str = "Success"; // string to return back to Arduino serial console
[Link]();
break;
return [Link](str);
} // endif (parsedData !== undefined)
else {
return [Link]("Error! Request body empty or in
incorrect format.");
}
}