Google-Sheets-Logging icon indicating copy to clipboard operation
Google-Sheets-Logging copied to clipboard

how many cells can we use

Open xcawhy opened this issue 3 years ago • 3 comments

I changed gscript code like that: ` // Enter Spreadsheet ID here var SS = SpreadsheetApp.openById('---------------id--------------); var str = "";

function doPost(e) {

var parsedData; var result = {};

try { parsedData = JSON.parse(e.postData.contents); } catch(f){ return ContentService.createTextOutput("Error in parsing request body: " + f.message); }

if (parsedData !== undefined){ var flag = parsedData.format; if (flag === undefined){ flag = 0; }

var sheet = SS.getSheetByName(parsedData.sheet_name); // sheet name to publish data to is specified in Arduino code
var dataArr = parsedData.values.split(","); // creates an array of the values to publish 
     
var date_now = Utilities.formatDate(new Date(), "Europe/Istanbul", "dd/MM/YYYY"); // gets the current date
var time_now = Utilities.formatDate(new Date(), "Europe/Istanbul", "HH:mm"); // gets the current time

var value0 = dataArr [0]; // value0 from Arduino code
var value1 = dataArr [1]; // value1 from Arduino code
var value2 = dataArr [2]; // value2 from Arduino code
var value3 = dataArr [3]; // value2 from Arduino code
var value4 = dataArr [7]; // value2 from Arduino code
var value5 = dataArr [5]; // value2 from Arduino code
var value6 = dataArr [6]; // value2 from Arduino code
var value7 = dataArr [7]; // value2 from Arduino code
// read and execute command from the "payload_base" string specified in Arduino code
switch (parsedData.command) {
  
  case "insert_row":
     
     sheet.insertRows(2); // insert full row directly below header text
     
     //var range = sheet.getRange("A2:D2");              // use this to insert cells just above the existing data instead of inserting an entire row
     //range.insertCells(SpreadsheetApp.Dimension.ROWS); // use this to insert cells just above the existing data instead of inserting an entire row
     
     sheet.getRange('A2').setValue(date_now); // publish current date to cell A2
     sheet.getRange('B2').setValue(time_now); // publish current time to cell B2
     sheet.getRange('C2').setValue(value0);   // publish value0 from Arduino code to cell C2
     sheet.getRange('D2').setValue(value1);   // publish value1 from Arduino code to cell D2
     sheet.getRange('E2').setValue(value2);   // publish value2 from Arduino code to cell E2
    sheet.getRange('F2').setValue(value3);   // publish value2 from Arduino code to cell F2
    sheet.getRange('G2').setValue(value4);   // publish value2 from Arduino code to cell E2
    sheet.getRange('H2').setValue(value5);   // publish value2 from Arduino code to cell E2
    sheet.getRange('I2').setValue(value6);   // publish value2 from Arduino code to cell E2
    sheet.getRange('J2').setValue(value7);   // publish value2 from Arduino code to cell E2
     str = "Success"; // string to return back to Arduino serial console
     SpreadsheetApp.flush();
     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
    publish_array [5] = value3;   // add value2 from Arduino code to position 4 in publish_array
    publish_array [6] = value4;   // add value2 from Arduino code to position 4 in publish_array
    publish_array [7] = value5;   // add value2 from Arduino code to position 4 in publish_array
    publish_array [8] = value6;   // add value2 from Arduino code to position 4 in publish_array
    publish_array [9] = value7;   // add value2 from Arduino code to position 4 in publish_array
     
     sheet.appendRow(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
     SpreadsheetApp.flush();
     break;     

}

return ContentService.createTextOutput(str);

} // endif (parsedData !== undefined)

else { return ContentService.createTextOutput("Error! Request body empty or in incorrect format."); } }`

My problem is: nodemcu gives no error. Insted it gives "Success". But I can't see any variable in H, I , J cells. There is no data there. I changed the values int to String, rearrange my code and functions but no luck. In my nodemcu code, I am working with 'insert_row' commad. I changed it to append_row to try but it did the same. Is there a limit?

xcawhy avatar Dec 19 '21 11:12 xcawhy

I do not know what the limit is for this method of sending data, but I can confirm that this was working sending a string of 24 integer values from my nodeMCU to Google Sheets and using columns A through Z in the spreadsheet.

Output from the serial monitor:

17:29:03.796 -> Publishing data...
17:29:03.828 -> {"command": "insert_row", "sheet_name": "Sheet1", "values": "50,923,73008,8363,584,73801,3691333,257,35015,57,305,58214,21245,587,887,276079,388,39838,52132,890,617,27313,23968351,364"}
17:29:07.400 -> Success

Spreadsheet output: Screenshot from 2023-01-25 17-31-54

StorageB avatar Jan 25 '23 23:01 StorageB

I do not know what the limit is for this method of sending data, but I can confirm that this was working sending a string of 24 integer values from my nodeMCU to Google Sheets and using columns A through Z in the spreadsheet.

Output from the serial monitor:

17:29:03.796 -> Publishing data...
17:29:03.828 -> {"command": "insert_row", "sheet_name": "Sheet1", "values": "50,923,73008,8363,584,73801,3691333,257,35015,57,305,58214,21245,587,887,276079,388,39838,52132,890,617,27313,23968351,364"}
17:29:07.400 -> Success

Spreadsheet output: Screenshot from 2023-01-25 17-31-54

can u provide your code?

lucasromeiro avatar Feb 07 '23 21:02 lucasromeiro

The ESP8266 code is here:

https://pastebin.com/1ezT7Yqc

The Google Script code is here:

https://pastebin.com/ANJeJhrB

StorageB avatar Feb 10 '23 15:02 StorageB