The same error message keeps popping up. This is the code block
Not correct Anthony - compare the Bluetooth part to my example. Get the IF's right too or your App will keep crashing.
The WEB1 code does not look like TimAI2's either.......
Use the | delimiter in your Sketch and in the Project. Note that, in the example Project, App Inventor is"told" what to expect from Bluetooth on Screen Initialize. I think you may be better off modifying my example to suit your display and Google Sheet requirements as there are many little things that add up to robustness.
I have used your code blocks and made some changes, but i cannot send sensor data to google sheet. I still need assistance to solve my issues.
If you want to test your google apps script try this:
if you get the data in your google sheet, then at least you know that part works, and you can focus on correctly getting the data from your arduino
If it doesn't work we can have a look at that too (e.g. provide full error messages / responseContnet)
therefore, as requested, provide the error messages returned. You will either get app notifications, or a message in your responseContent, or both!
There appear to be a couple of errors in your blocks:
- you need an
&
before Voltage - I am sorry I left this out of my blocks too - in your script you show the parameters e.parameter.Voltage and e.parameter.Sensor (note the capital letters). This is how I put it in the blocks that I posted, but you changed these to lowercase
There actually no error message. Just that nothing saves on the google sheet.
You may not be using Web1.GotText. Add these blocks to your project, and then try to send the data to your google sheet again. What do you see in Label1.Text
I also note that your google apps script does not have a return element, this is usually required. You could, as previously suggested, edit your script to this:
function doPost(e) {
var ss = SpreadsheetApp.openByUrl("YOUR_SHEET_URL");
var sh = ss.getSheetByName("Sheet1");
var Sensor = e.parameter.Sensor;
var Voltage = e.parameter.Voltage;
sh.appendRow([Sensor,Voltage]);
return ContentService.createTextOutput('data appended');
}
This is sad
I have just set up a test project which works for me.
I see you are using the legacy editor.
For the script, when publishing for the first time I set the script to run as Me
(my google account) and for it to be accessible by Anyone, even anonymous
. This is the only way a google apps script will work with AI2.
I used this script:
function doPost(e) {
var ss = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/1si756vNKC8z3cNCKlPcQGlMc1pmn7vuqHtRc2dLUnck/edit#gid=0");
var sh = ss.getSheetByName("Sheet1");
var Sensor = e.parameter.Sensor;
var Voltage = e.parameter.Voltage;
sh.appendRow([Sensor,Voltage]);
return ContentService.createTextOutput('data appended');
}
and these blocks
when I run the app in companion and click Button 1, the data appears in my google sheet
and data appended
appears in label1.Text.
You might also read this:
Ok..I will just try that now.
Note that in the example link above I use doGet(e). In your project we are using doPost(e).
You cannot test doPost(e) in your computer browser
please can you come again. do you mean the script. because i used doGet(e) in the first part. and doPost(e) in the second.
function doPost(e) {
var ss = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/1si756vNKC8z3cNCKlPcQGlMc1pmn7vuqHtRc2dLUnck/edit#gid=0");
var sh = ss.getSheetByName("Sheet1");
var Sensor = e.parameter.Sensor;
var Voltage = e.parameter.Voltage;
sh.appendRow([Sensor,Voltage]);
return ContentService.createTextOutput('data appended');
}
You only need to use the script content I posted above, you do not need the doGet(e).
Yes, just that, and nothing else....
Ok.. I will do that
Remember, every time you change your code in the google apps script, you must republish your web app, selecting New
under Project version: in the dialog, then clicking the Update button.