electronicsguy / ESP8266

ESP8266 Projects
242 stars 183 forks source link

getLastRow issue #75

Closed Klasth closed 5 years ago

Klasth commented 5 years ago

Hello,

Well thanks for all job of the community and special for electronicsguy

I follow all the steps of the README, add a calendar in the drive.

I have a message when the ESP8266 execute this code:

client->POST(url2, host, payload)

in

Serial.println("POST append memory data to spreadsheet:"); payload = payload_base + "\"" + ESP.getFreeHeap() + "," + ESP.getFreeContStack() + "\"}"; if(client->POST(url2, host, payload)){ ; } else{ ++error_count; DPRINT("Error-count while connecting: "); DPRINTLN(error_count); }

Message in the serial:

<!DOCTYPE html><html><head><link rel="shortcut icon" href="//ssl.gstatic.com/docs/script/images/favicon.ico"><title>Error</title><style type="text/css">body {background-color: #fff; margin: 0; padding: 0;}.errorMessage {font-family: Arial,sans-serif; font-size: 12pt; font-weight: bold; line-height: 150%; padding-top: 25px;}</style></head><body style="margin:20px"><div><img alt="Google Apps Script" src="//ssl.gstatic.com/docs/script/images/logo.png"></div><div style="text-align:center;font-family:monospace;margin:50px auto 0;max-width:600px">TypeError: No se puede llamar al método &quot;getLastRow&quot; de null. (línea 74, archivo &quot;Código&quot;, proyecto &quot;copy&quot;)</div></body></html>

(have google account and arduino IDE in spanish)

Tell that can't call method in line 74 of .gs A problem with getLastRow:

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){ // Common items first // data format: 0 = display value(literal), 1 = object value var flag = parsedData.format;

if (flag === undefined){
  flag = 0;
}

switch (parsedData.command) {
  case "appendRow":
     var tmp = SS.getSheetByName(parsedData.sheet_name);
     var nextFreeRow = tmp.getLastRow() + 1;        <------------------------ LINE 74
     var dataArr = parsedData.values.split(",");

     tmp.appendRow(dataArr);

     str = "Success";
     SpreadsheetApp.flush();
     break;     

}

return ContentService.createTextOutput(str);

} // endif (parsedData !== undefined)

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

}

Finally, the doPost function....

I really don't know what s happen here. The sheet looks like this. sin titulo

Something is wrong and don't know. what do you think?

Klasth commented 5 years ago

i'm sorry for this.

The problem was in the .ino

The name of my spreadsheet must be equal to the .ino

String payload_base = "{\"command\": \"appendRow\", \ \"sheet_name\": \"Hoja 1\", \ \"values\": ";

My sheet name was "Hoja 1" that resolve de problem.

The solution come to me in the pull: https://github.com/electronicsguy/ESP8266/pull/66/files