This tutorial will demonstrate how to log data from ESP32 on a Google sheet using the Waijung2 block-set.
Log in to your Google account and open a blank Google Spread Sheet.
Change the document name and the sheet name as preferred and create the required columns. In this example:
•Document name: ESP32_Data_log
•Sheet name: Sensor_Data
•Columns: Timestamp, Sensor1, Sensor2
Now the Google sheets needs to be published as a web application which will be listening to web requests. For that we use Google Script. Now go to Extensions -> App Script. This will open up a new window to write the script. Copy and paste the code in the g_script_code.txt file to the Google Script editor. Save the script with a preferred name. (Example: ESP32_Data_Log_Script).
Click here to find more information regarding Google Script.
Go to Publish -> Deploy as web app.
In the pop-up window make the configurations as shown in the picture.
Click Deploy.
From the pop-up window click Review Permissions. This will open up a new windows to sign in to your Google account.
After Signing in the page in the new window will re-direct to a warning page. There click Advanced and click Go to yourscriptname (unsafe).
Then the page in the new window will direct to another page where you will be asked for permission to run the app. Click Allow .
Copy and save the URL and click OK .
Your URL will look something like this:
https://script.google.com/macros/s/{yourkey}/exec
The yourkey is a unique key for that specific Google Sheet you created. Therefore do not share this key.
To test the server open a browser and enter the URL below.
https://script.google.com/macros/s/{your-key}/exec?id=Sensor_Data&Sensor1=100&Sensor2=100
If everything is correct, the word 'success' will be shown on your web page.
Now if you go back to your google sheet you will be able to see your data (sensor1 = 100, sensor2 = 100) been logged.
Congratulations you have successfully setup your Google sheet as the server!
Now we just need to replicate what we did in Step 6 using ESP32. Download and open the data_logger.slx and make the following changes.
•In the main system,
1.Edit the WIFI SSID
2.Edit the WIFI password
•In the URL subsystem,
1.Edit the Google sheet name.
2.Edit the column names of the Google sheet.
3.Enter the the unique key of your Google sheet.
Save and upload the code to the ESP32 board.
In this example, as sensors a constant block and a counter block is used to simulate the program. You can replace them with your sensor readings.
After uploading you will be able to see the sensor values being updated every 5 seconds to the Google Sheet.