Go Down

Topic: Arduino IoT Cloud communicating with Google Sheets - Error with doPost function (Read 499 times) previous topic - next topic

h0y_

Hi everyone,

I am new to IoT and want to learn how to integrate my new Arduino MKR 1010 with Google Sheets for a project. I have tried to follow this linked tutorial and have come across an error with the doPost function in Google Apps Script.

https://create.arduino.cc/projecthub/Arduino_Genuino/arduino-iot-cloud-google-sheets-integration-71b6bc

I am convinced I have not made a mistake setting up the Google side of the project, copying and pasting the code from the tutorial into the Arduino sketch and I have also tried different COMM speeds to try and see if it is something to do with my wifi. I have started over about 5 times and have tried similar online tutorials and each of them doesn't fill in the spreadsheet with anything. When I press the run or debug button in Google Apps Script, I can't get doPost to work however (apparently because its a translated code rather than compiled code) I can't find the exact line within that function is failing.

I have fixed the issue some other people have mentioned with the tutorial where getActive.Sheet() is supposed to be getActive.Spreadsheet() and when debugging the script then stops at the doPost function.


Within the log of Google App Script:

[20-07-30 17:23:34:237 PDT] TypeError: Cannot read property 'postData' of undefined
    at doPost(Code:35:32)

When using a dashboard to test that the variables change, the Arduino sketch works as expected with the correct variables. I think there is an issue with the webhook but I don't know which side of the puzzle has the issue.

I am not a premium member of Arduino Cloud - only free membership. I have ensured that the webhook within the Arduino Cloud "Things" tab is the same URL as the published webapp. I am running the online version of Arduino Create through Safari on mac.

Thanks if anyone can help with this.

eclipse1985

Hey h0y_!
Probably sometimes the webhook event gets empty for some reason related to google sheet, can you try to add something like

Code: [Select]

if (!e) return;


before the line where you're getting the error?

h0y_

I have tried what you said and I haven't had any change to how the script seems to be working. It doesn't stop at the break point when I put it on this line of code; the whole doPost function isn't working wherever I put the line you suggest.

When I press the button after publishing the App Script "test app for latest code" under the web app link, I get the error message:

Script function not found: doGet

When I try to open the log now the Google App Script just says waiting for logs, please wait. This hasn't updated.

I have read on the comments to this tutorial that Google have changed maybe how the permissions work for Google App Script, is there any basis you know of for this to be the case?

h0y_

I have tried to use debug to look at the code and have found this in the screenshot if this is any further help.

h0y_

I have resolved some of the issue, managed to delete all the code in the tutorial after the point at which the JSON file is interpreted into an array in the script. Instead, I simply appended the contents of the array into sheets to prove that everything is communicating. There is an issue with the Google Sheets part of the Google Apps Script somewhere but I'm not experienced enough to debug exactly where this problem is.

Considering this is an official tutorial, I'm a bit disappointed that the Google Apps Script side of things is almost entirely wrong from my experience. Not sure if the language has changed since publishing.

Go Up