You are on page 1of 21

11/07/23, 10.49 IoT: Log Sensor Data to Google Sheets using NodeMCU - Electronics-Lab.

com

ANDROID APP CONTACT US LOG

Search …

TRENDING: TC001 THERMAL CAMERA TOPDON

Home / Projects / Arduino & Raspberry / IoT: Log Sensor Data To Google Sheets Using NodeMCU

IOT: LOG SENSOR DATA TO GOOGLE SHEETS USING NODEMCU

Emmanuel Odunlade https://twitter.com/emmaodunlade emmaodunlade@gmail.com 27.954 Views Tested 

https://www.electronics-lab.com/project/iot-log-sensor-data-google-sheet-using-nodemcu/ 1/21
11/07/23, 10.49 IoT: Log Sensor Data to Google Sheets using NodeMCU - Electronics-Lab.com

Data is regarded as the major value proposition of IoT. The ability to receive real time data from different sources, store it and process it into actionable
insights to transform and optimize processes either in real time or not is of immense value. This is one of the reasons why device cloud is one of the mos
important (and sometimes most expensive) part of the architecture of any IoT solution/Project, since the data must be stored in a place where it can be r
accessed for further analysis. For individuals looking to deploy pilots and prototypes of scalable projects on a budget, coughing up the huge sums require
data storage on platforms like Azure, can be quite the burden, and while there are tons of free IoT platforms that can be used, they sometimes have one
restriction or the other that makes them not suitable in certain situations. For today’s tutorial, we will look at a cheap/free alternative way to store your da
the cloud. We will look at how you can connect your IoT based devices to Google Sheet so to be able to log data.

Google sheet is most commonly used in place of Microsoft Excel to develop spreadsheet documents. It provides a good way to store or process data in
spreadsheet form and it can be integrated with dozens of other services provided by Google like Maps, to create truly innovative solutions. Through APIs
the use of Google script (Gscript), Google made it easy for developers to programmatically fill in data into a google sheet thus making it easy to build solu
using their services and this is what we will use for this tutorial..

As an example to show the use of Google Sheets as the device cloud, we will build a simple temperature and humidity based IoT weather monitor. The
device will obtain temperature and humidity from the environment using DHT11 and upload the data over WiFi to a Google Sheet file.

Ready? let’s jump in.

REQUIRED COMPONENTS

The following components are required to build this project;

1. ESP8266 NodeMCU
2. DHT11 Temperature and Humidity Sensor
3. LED
4. Jumper wires
5. Bread Board

The nodeMCU is being used because of its popularity and robust WiFi implementation. Any of the other ESP-12e based boards can also be used without
modification to the setup and code.

https://www.electronics-lab.com/project/iot-log-sensor-data-google-sheet-using-nodemcu/ 2/21
11/07/23, 10.49 IoT: Log Sensor Data to Google Sheets using NodeMCU - Electronics-Lab.com
SCHEMATICS

The schematics for this project is quite straight forward. We only need to connect the LED and DHT to the Nodemcu as shown in the image below.

Schematics

The pin to pin map of the connection between the NodeMCU and the DHT is also illustrated below to make things clearer.

NodeMCU - DHT
3.3V - VCC
GND - GND
A0 - DO

Go over the connection to ensure everything is as it should be before proceeding to the next section.

Creating and Preparing the Google Sheet.

To send data to a google sheet, we need to first create the sheet and then prepare it to receive data from the device by creating a Gscript (Google Script)
the sheet to our device.

https://www.electronics-lab.com/project/iot-log-sensor-data-google-sheet-using-nodemcu/ 3/21
11/07/23, 10.49 IoT: Log Sensor Data to Google Sheets using NodeMCU - Electronics-Lab.com

Follow the steps below to do this:

1. Point your web browser to docs.google.com.You might need to sign in to your google account or create a new one before you can access the link.

2. When the page opens, click on the menu button and select the Google sheet from the drop-down of applications.

3. The above will launch a new page where you can choose the option of creating a new sheet.

4. When the new Spreadsheet opens, Give it a name (Document title) that is easy to reference. Under every GoogleSheet document you can create multip
sheets, but for this project, we will only use the default sheet 1, also change the sheet name to something that resonates with you. In my case, the docum
title is IoTDanceHall while the sheet is name temphum.

Rename the File and Sheet

5. With the sheet created and the names changed, it is now time to create the google sheet file for the project. Go to Tools on the menu bar and select sc
editor as shown in the image below.

https://www.electronics-lab.com/project/iot-log-sensor-data-google-sheet-using-nodemcu/ 4/21
11/07/23, 10.49 IoT: Log Sensor Data to Google Sheets using NodeMCU - Electronics-Lab.com

Launch Script Editor

6. It will launch a new tab which will open the Google Script Editor. Rename the Google script file to a name you can relate with. For this tutorial, I will be c
the file “temphum_log“.

7. Next, we will borrow the script developed by Sujay which uses the google calendar to create blanks on a designated google sheet for the data being sen
from the device to fill, making it easy to read and write to a GoogleSheet. The script is attached under the download section. Copy the script content and
in the editor.

8. Edit the sheet name and sheet ID in the code to match with your own sheet name (which is “temphum” in my case ) and your own sheet ID.

https://www.electronics-lab.com/project/iot-log-sensor-data-google-sheet-using-nodemcu/ 5/21
11/07/23, 10.49 IoT: Log Sensor Data to Google Sheets using NodeMCU - Electronics-Lab.com

Enter Sheet ID and Name in Script

Your sheet ID is part of your sheet URL. It occupies the position between the backslash after “d” and the one before “edit” highlighted below in the URL

Double-check it before pasting to ensure nothing was omitted as the script will not be able to interact with your sheet if the ID is incorrect. Also Keep this
safe for future use.

9. With the Gscript editing complete, click on the publish button on the top tool bar and select “deploy as web app” from the drop down.

https://www.electronics-lab.com/project/iot-log-sensor-data-google-sheet-using-nodemcu/ 6/21
11/07/23, 10.49 IoT: Log Sensor Data to Google Sheets using NodeMCU - Electronics-Lab.com

10. It will launch an interface where you will need to fill a bunch of information. Fill as shown in the image below with the Project version set to new, your
ID selected, and given anyone, even anonymous access to the app. With that done, click on the deploy button.

11. Deploying will require that you give the script some permissions. Click on review permissions when prompted. Since the script is not a verified google
it will throw a warning as shown below. Review this by clicking the advanced button in the image below.

https://www.electronics-lab.com/project/iot-log-sensor-data-google-sheet-using-nodemcu/ 7/21
11/07/23, 10.49 IoT: Log Sensor Data to Google Sheets using NodeMCU - Electronics-Lab.com

12. Proceed by clicking the goto “your script name”(unsafe) button highlighted below.

13. Ascribe permissions to the script and allow its connection to your google account and the google sheet we created, by clicking on the allow button.

https://www.electronics-lab.com/project/iot-log-sensor-data-google-sheet-using-nodemcu/ 8/21
11/07/23, 10.49 IoT: Log Sensor Data to Google Sheets using NodeMCU - Electronics-Lab.com

Click on allow button to connect script.

14. With this done you should now see the success page. It will provide you with the web app URL. Copy this URL and keep safe as the script ID embedded
the web app URL will be used by the Arduino code to access the google sheet.

With this done, we are now ready to write the code for our ESP8266.

CODE

https://www.electronics-lab.com/project/iot-log-sensor-data-google-sheet-using-nodemcu/ 9/21
11/07/23, 10.49 IoT: Log Sensor Data to Google Sheets using NodeMCU - Electronics-Lab.com

The algorithm behind the sketch for today’s project is quite straightforward, but the implementation, to someone not familiar with https and JSON, migh
require some level of practice. The main task of the code is to obtain temperature and humidity data from the DHT11 and forward the data to the google
sheet via WiFi connection to the internet.

We will develop the code for today’s project using the Arduino IDE as such, if this is the first time you are developing a sketch for the Nodemcu with the
Arduino IDE, you will need to install the ESP8266 board support files for the Arduino IDE. For some help on getting that done, check out this tutorial we di
the topic a while back.

To simplify the code and reduce the amount of work that needs to be done, we will use 4 major libraries including; the ESP8266WiFi library, the
HTTPSRedirect library, the DebugMacros which is part of the HTTPSRedirect library, and the DHT library. The ESP8266WiFi library is installed when the
ESP8266 board support files are installed for the Arduino IDE. It provides an easy way for users to access the robust WiFi implementation on the NodeMC
The HTTPSRedirect library is based on the Wifi library. It provides the user with feature rich easy of communicating with servers via http or https. One of t
requirements for HTTPS communication is connection certificates or in this case SHA-1 fingerprints of the websites. The debug macros library helps store
process request in that line. Finally, ther is the DHT library. It is used to facilitate easy interaction with the DHT11 to pull the temperature and humidity da
with few lines of code.

As usual, I will do a “run through” of the code explaining the parts I feel might be new or difficult to grab.

We start the sketch, as usual, by including the libraries that will be used, followed by the declaration of the pin of the NodeMCU to which the DHT11 is
connected and the creation of an instance of the DHT library.

1. #include <ESP8266WiFi.h>
2. #include "HTTPSRedirect.h"
3. #include "DebugMacros.h"
4. #include <DHT.h>
5.
6. #define DHTPIN D4 // Pin to which DHT is connected
7. #define DHTTYPE DHT11 // Declare DHT Type
8. DHT dht(DHTPIN, DHTTYPE);

Next, define variables that will be used to store temperature and humidity data after which we provide the credentials of the WiFi (router) through whic
device is meant to access the internet.

1. float h;
2. float t;
3. String sheetHumid = "";
4. String sheetTemp = "";
5.
6. const char* ssid = " "; //Put wifi ssid within the quotes
7. const char* password = " "; //Put WiFi password within the quotes

Next, we create variables to hold several google server credentials including the host address, the Gscript ID we obtained earlier and the port number w
is usually 443 for https.

1. const char* host = "script.google.com";


2. const char *GScriptId = "enter your GSCript ID here"; // Replace with your own google script id
3. const int httpsPort = 443; //the https port is same

Next we define the URL to the Google Sheet where the data will be written, using the Gscript ID as the reference. After that we create a payload with
formatted in JSON to specify how the data should be sent to the google sheet.

1. // echo | openssl s_client -connect script.google.com:443 |& openssl x509 -fingerprint -noout
2. const char* fingerprint = "";
3.
4. //const uint8_t fingerprint[20] = {};

https://www.electronics-lab.com/project/iot-log-sensor-data-google-sheet-using-nodemcu/ 10/21
11/07/23, 10.49 IoT: Log Sensor Data to Google Sheets using NodeMCU - Electronics-Lab.com
5.
6. String url = String("/macros/s/") + GScriptId + "/exec?value=Temperature"; // Write Teperature to Google Spreadsheet at cell
7. // Fetch Google Calendar events for 1 week ahead
8. String url2 = String("/macros/s/") + GScriptId + "/exec?cal"; // Write to Cell A continuosly
9.
10. //replace with sheet name not with spreadsheet file name taken from google
11. String payload_base = "{\"command\": \"appendRow\", \
12. \"sheet_name\": \"temphum\", \
13. \"values\": ";
14. String payload = "";

With that done, we then create an Https client which will be managing all the connections and move to the void setup() function.

1. HTTPSRedirect* client = nullptr;

We start the void setup by initializing serial communication to enable us use the serial monitor for debugging.

1. void setup() {
2. delay(1000);
3. Serial.begin(115200);

Next, we initialize the DHT and initiate WiFi connection to the access point provided.

1. dht.begin(); //initialise DHT11


2.
3. Serial.println();
4. Serial.print("Connecting to wifi: ");
5. Serial.println(ssid);
6.
7. WiFi.begin(ssid, password);
8. while (WiFi.status() != WL_CONNECTED) {
9. delay(500);
10. Serial.print(".");
11. }
12. Serial.println("");
13. Serial.println("WiFi connected");
14. Serial.println("IP address: ");
15. Serial.println(WiFi.localIP());

Next, we create a client using the httpsredirect library for connection purposes. One notable thing done within this block of code is that we set the secur
status of the connection as insecure. This is to enable us connect without necessarily verifying the certificate of the server. The connection is retried sever
and its status is displayed on the serial monitor for debug purposes.

1. // Use HTTPSRedirect class to create a new TLS connection


2. client = new HTTPSRedirect(httpsPort);
3. client->setInsecure();
4. client->setPrintResponseBody(true);
5. client->setContentTypeHeader("application/json");
6. Serial.print("Connecting to ");
7. Serial.println(host); //try to connect with "script.google.com"
8.
9. // Try to connect for a maximum of 5 times then exit
10. bool flag = false;
11. for (int i = 0; i < 5; i++) {
12. int retval = client->connect(host, httpsPort);
13. if (retval == 1) {
14. flag = true;
15. break;
16. }
17. else
18. Serial.println("Connection failed. Retrying...");
19. }

https://www.electronics-lab.com/project/iot-log-sensor-data-google-sheet-using-nodemcu/ 11/21
11/07/23, 10.49 IoT: Log Sensor Data to Google Sheets using NodeMCU - Electronics-Lab.com
20.
21. if (!flag) {
22. Serial.print("Could not connect to server: ");
23. Serial.println(host);
24. Serial.println("Exiting...");
25. return;
26. }

If the connection is successful, the client fetches the spreadsheet details as well as the google calendar details to know which row was data last updated t
The buffer is then cleared by deleting the client to reduce the amount of memory being used.

1. Serial.println("\nWrite into cell 'A1'");


2. Serial.println("------>");
3. // fetch spreadsheet data
4. client->GET(url, host);
5.
6. Serial.println("\nGET: Fetch Google Calendar Data:");
7. Serial.println("------>");
8. // fetch spreadsheet data
9. client->GET(url2, host);
10.
11. Serial.println("\nStart Sending Sensor Data to Google Spreadsheet");
12.
13.
14. // delete HTTPSRedirect object
15. delete client;
16. client = nullptr;
17. }

Next, we move to the void loop() function.

We start the function by obtaining temperature and humidity information from the DHT, checking to see if there is any error in the Data and displaying th
data obtained on the serial monitor.

1. h = dht.readHumidity(); // Reading temperature or humidity takes about 250


milliseconds!
2. t = dht.readTemperature(); // Read temperature as Celsius (the default)
3. if (isnan(h) || isnan(t)) { // Check if any reads failed and exit early (to tr
again).
4. Serial.println(F("Failed to read from DHT sensor!"));
5. return;
6. }
7. Serial.print("Humidity: "); Serial.print(h);
8. sheetHumid = String(h) + String("%"); //convert integer humidity to string humidity
9. Serial.print("% Temperature: "); Serial.print(t); Serial.println("°C ");
10. sheetTemp = String(t) + String("°C");

Next, we create connection session variables and add the data obtained from the DHT to the header payload.

1. static int error_count = 0;


2. static int connect_count = 0;
3. const unsigned int MAX_CONNECT = 20;
4. static bool flag = false;
5.
6. payload = payload_base + "\"" + sheetTemp + "," + sheetHumid + "\"}";

The client is created, connected to the host and the new payload is uploaded to the google sheet. If any error is detected, the system retries for 3 times af
which it clears its buffer and automatically restarts the Nodemcu by triggering the watchdog timer.

1. if (!flag) {
2. client = new HTTPSRedirect(httpsPort);

https://www.electronics-lab.com/project/iot-log-sensor-data-google-sheet-using-nodemcu/ 12/21
11/07/23, 10.49 IoT: Log Sensor Data to Google Sheets using NodeMCU - Electronics-Lab.com
3. client->setInsecure();
4. flag = true;
5. client->setPrintResponseBody(true);
6. client->setContentTypeHeader("application/json");
7. }
8.
9. if (client != nullptr) {
10. if (!client->connected()) {
11. client->connect(host, httpsPort);
12. client->POST(url2, host, payload, false);
13. Serial.print("Sent : "); Serial.println("Temp and Humid");
14. }
15. }
16. else {
17. DPRINTLN("Error creating client object!");
18. error_count = 5;
19. }
20.
21. if (connect_count > MAX_CONNECT) {
22. connect_count = 0;
23. flag = false;
24. delete client;
25. return;
26. }
27.
28. Serial.println("POST or SEND Sensor data to Google Spreadsheet:");
29. if (client->POST(url2, host, payload)) {
30. ;
31. }
32. else {
33. ++error_count;
34. DPRINT("Error-count while connecting: ");
35. DPRINTLN(error_count);
36. }
37.
38. if (error_count > 3) {
39. Serial.println("Halting processor...");
40. delete client;
41. client = nullptr;
42. Serial.printf("Final free heap: %u\n", ESP.getFreeHeap());
43. Serial.printf("Final stack: %u\n", ESP.getFreeContStack());
44. Serial.flush();
45. ESP.deepSleep(0);
46. }

A delay of 2 seconds is provided at the end of the code to give a breather to the DHT as specified in its datasheet.

1. delay(2000); // keep delay of minimum 2 seconds as dht allow reading after 2 seconds interval and also for google sheet
2. }

The code runs in a loop so whenever a new data is provided by the DHT, it Is uploaded to the google sheet.

The complete code for the project is provided below and attached under the download section.

1. #include <ESP8266WiFi.h>
2. #include "HTTPSRedirect.h"
3. #include "DebugMacros.h"
4. #include <DHT.h>
5.
6. #define DHTPIN D4 // what digital pin we're connected to
7. #define DHTTYPE DHT11 // select dht type as DHT 11 or DHT22
8. DHT dht(DHTPIN, DHTTYPE);
9.
10. float h;
11. float t;
12. String sheetHumid = "";
13. String sheetTemp = "";

https://www.electronics-lab.com/project/iot-log-sensor-data-google-sheet-using-nodemcu/ 13/21
11/07/23, 10.49 IoT: Log Sensor Data to Google Sheets using NodeMCU - Electronics-Lab.com
14.
15. const char* ssid = " "; //Put wifi ssid within the quotes
16. const char* password = " "; //Put WiFi password within the quotes
17.
18. const char* host = "script.google.com";
19. const char *GScriptId = "enter your GSCript ID here"; // Replace with your own google script id
20. const int httpsPort = 443; //the https port is same
21.
22. // echo | openssl s_client -connect script.google.com:443 |& openssl x509 -fingerprint -noout
23. const char* fingerprint = "";
24.
25. //const uint8_t fingerprint[20] = {};
26.
27. String url = String("/macros/s/") + GScriptId + "/exec?value=Temperature"; // Write Teperature to Google Spreadsheet at cell
28. // Fetch Google Calendar events for 1 week ahead
29. String url2 = String("/macros/s/") + GScriptId + "/exec?cal"; // Write to Cell A continuosly
30.
31. //replace with sheet name not with spreadsheet file name taken from google
32. String payload_base = "{\"command\": \"appendRow\", \
33. \"sheet_name\": \"temphum\", \
34. \"values\": ";
35. String payload = "";
36.
37. HTTPSRedirect* client = nullptr;
38.
39. // used to store the values of free stack and heap before the HTTPSRedirect object is instantiated
40. // so that they can be written to Google sheets upon instantiation
41.
42. void setup() {
43. delay(1000);
44. Serial.begin(115200);
45. dht.begin(); //initialise DHT11
46.
47. Serial.println();
48. Serial.print("Connecting to wifi: ");
49. Serial.println(ssid);
50.
51. WiFi.begin(ssid, password);
52. while (WiFi.status() != WL_CONNECTED) {
53. delay(500);
54. Serial.print(".");
55. }
56. Serial.println("");
57. Serial.println("WiFi connected");
58. Serial.println("IP address: ");
59. Serial.println(WiFi.localIP());
60.
61. // Use HTTPSRedirect class to create a new TLS connection
62. client = new HTTPSRedirect(httpsPort);
63. client->setInsecure();
64. client->setPrintResponseBody(true);
65. client->setContentTypeHeader("application/json");
66. Serial.print("Connecting to ");
67. Serial.println(host); //try to connect with "script.google.com"
68.
69. // Try to connect for a maximum of 5 times then exit
70. bool flag = false;
71. for (int i = 0; i < 5; i++) {
72. int retval = client->connect(host, httpsPort);
73. if (retval == 1) {
74. flag = true;
75. break;
76. }
77. else
78. Serial.println("Connection failed. Retrying...");
79. }
80.
81. if (!flag) {
82. Serial.print("Could not connect to server: ");
83. Serial.println(host);
84. Serial.println("Exiting...");
85. return;
86. }

https://www.electronics-lab.com/project/iot-log-sensor-data-google-sheet-using-nodemcu/ 14/21
11/07/23, 10.49 IoT: Log Sensor Data to Google Sheets using NodeMCU - Electronics-Lab.com
87. // Finish setup() function in 1s since it will fire watchdog timer and will reset the chip.
88. //So avoid too many requests in setup()
89.
90. Serial.println("\nWrite into cell 'A1'");
91. Serial.println("------>");
92. // fetch spreadsheet data
93. client->GET(url, host);
94.
95. Serial.println("\nGET: Fetch Google Calendar Data:");
96. Serial.println("------>");
97. // fetch spreadsheet data
98. client->GET(url2, host);
99.
100. Serial.println("\nStart Sending Sensor Data to Google Spreadsheet");
101.
102.
103. // delete HTTPSRedirect object
104. delete client;
105. client = nullptr;
106. }
107.
108. void loop() {
109.
110. h = dht.readHumidity(); // Reading temperature or humidity takes about 250
milliseconds!
111. t = dht.readTemperature(); // Read temperature as Celsius (the default)
112. if (isnan(h) || isnan(t)) { // Check if any reads failed and exit early (to t
again).
113. Serial.println(F("Failed to read from DHT sensor!"));
114. return;
115. }
116. Serial.print("Humidity: "); Serial.print(h);
117. sheetHumid = String(h) + String("%"); //convert integer humidity to string humidity
118. Serial.print("% Temperature: "); Serial.print(t); Serial.println("°C ");
119. sheetTemp = String(t) + String("°C");
120.
121. static int error_count = 0;
122. static int connect_count = 0;
123. const unsigned int MAX_CONNECT = 20;
124. static bool flag = false;
125.
126. payload = payload_base + "\"" + sheetTemp + "," + sheetHumid + "\"}";
127.
128. if (!flag) {
129. client = new HTTPSRedirect(httpsPort);
130. client->setInsecure();
131. flag = true;
132. client->setPrintResponseBody(true);
133. client->setContentTypeHeader("application/json");
134. }
135.
136. if (client != nullptr) {
137. if (!client->connected()) {
138. client->connect(host, httpsPort);
139. client->POST(url2, host, payload, false);
140. Serial.print("Sent : "); Serial.println("Temp and Humid");
141. }
142. }
143. else {
144. DPRINTLN("Error creating client object!");
145. error_count = 5;
146. }
147.
148. if (connect_count > MAX_CONNECT) {
149. connect_count = 0;
150. flag = false;
151. delete client;
152. return;
153. }
154.
155. Serial.println("POST or SEND Sensor data to Google Spreadsheet:");
156. if (client->POST(url2, host, payload)) {
157. ;

https://www.electronics-lab.com/project/iot-log-sensor-data-google-sheet-using-nodemcu/ 15/21
11/07/23, 10.49 IoT: Log Sensor Data to Google Sheets using NodeMCU - Electronics-Lab.com
158. }
159. else {
160. ++error_count;
161. DPRINT("Error-count while connecting: ");
162. DPRINTLN(error_count);
163. }
164.
165. if (error_count > 3) {
166. Serial.println("Halting processor...");
167. delete client;
168. client = nullptr;
169. Serial.printf("Final free heap: %u\n", ESP.getFreeHeap());
170. Serial.printf("Final stack: %u\n", ESP.getFreeContStack());
171. Serial.flush();
172. ESP.deepSleep(0);
173. }
174.
175. delay(2000); // keep delay of minimum 2 seconds as dht allow reading after 2 seconds interval and also for google sheet
176. }

DEMO

Connect the setup to your computer, launch the Arduino IDE, paste the code, verify and upload to your board. With the upload done, open the serial mon
to ensure the WiFi is connected and there are no issues. Head to the Google sheet, you should now see temperature and humidity data as they stream to
cloud from your device.

Demo

To take things further, you can hook up a python script to parse the data being logged on the google sheet and generate all sort of graphs and insights. O
other thing you could do is to add location data to the spreadsheet, and display it all on Google map.

That’s it for today’s tutorial guys. Thanks for reading and as usual, feel free to reach out to me via the comment section if you get stuck anywhere.

Please follow and like us: Like

https://www.electronics-lab.com/project/iot-log-sensor-data-google-sheet-using-nodemcu/ 16/21
11/07/23, 10.49 IoT: Log Sensor Data to Google Sheets using NodeMCU - Electronics-Lab.com

JLCPCB - Only $2 for PCB Prototype (Any Color)


24 Hours fast turnaround, Excellent quality & Unbeatable prices

$18 Welcome Bonus for new registrations Now https://jlcpcb.com

DOWNLOADS

SCript-Sketch-and-Libraries.zip

Share On Facebook Share On Twitter Share On LinkedIn Email Share On Pinterest 2 Shares Suka 6 Tweet

Add Gerber File

Automatically sets the board size,hole,track/spacing. only accept.rar or .zip & Maximum 20M

Dimensions: Length x Width mm Quantity: Choose Num (pcs)

Layers: 2 Layers Thickness: 1.6mm

Quote Now

Get $5.00-Free Prototype Order

 Subscribe  Connect with     Log

Join the discussion

{} [+]

13 COMMENTS  

https://www.electronics-lab.com/project/iot-log-sensor-data-google-sheet-using-nodemcu/ 17/21
11/07/23, 10.49 IoT: Log Sensor Data to Google Sheets using NodeMCU - Electronics-Lab.com

Saravanan S
 3 years ago

How to include timestamp with this data in separate column?

0 Reply

Emmanuel Odunlade Author

 Reply to Saravanan S  3 years ago

For Accuracy, you could connect a DS3231 to the NodeMCU and add that data to the payload line like:

payload = payload_base + “\”” + timestamp + “,” + sheetTemp + “,” + sheetHumid + “\”}”;

Of course this means you would have obtained the time stamp and formated it into a string

0 Reply

Guilherme
 3 years ago

00:10:55.730 -> …
00:10:56.713 -> WiFi connected
00:10:56.713 -> IP address:
00:10:56.747 -> 192.168.0.106
00:10:56.747 -> Connecting to script.google.com
00:10:57.801 ->
00:10:57.801 -> Write into cell ‘A1’
00:10:57.801 -> ——>
00:10:57.970 -> Error with request. Response status code: 404
00:10:57.970 ->
00:10:57.970 -> GET: Fetch Google Calendar Data:
00:10:57.970 -> ——>
00:10:58.248 -> Error with request. Response status code: 404
00:10:58.282 ->
00:10:58.282 -> Start Sending Sensor Data to Google Spreadsheet
00:10:58.282 -> Humidity: 64.00% Temperature: 30.90°C
00:10:59.576 -> Error with request. Response status code: 404
00:10:59.576 -> Sent : Temp and Humid
00:10:59.576 -> POST or SEND Sensor data to Google Spreadsheet:
00:10:59.643 -> Error with request. Response status code: 0
00:11:01.676 -> Humidity: 68.00% Temperature: 29.50°C
00:11:01.676 -> POST or SEND Sensor data to Google Spreadsheet:
00:11:01.913 -> Error with request. Response status code: 0
00:11:03.957 -> Humidity: 67.00% Temperature: 29.50°C
00:11:03.957 -> POST or SEND Sensor data to Google Spreadsheet:
00:11:04.125 -> Error with request. Response status code: 404
00:11:06.139 -> Humidity: 67.00% Temperature: 29.60°C
00:11:06.139 -> POST or SEND Sensor data to Google Spreadsheet:
00:11:06.479 -> Error with request. Response status code: 0
00:11:06.479 -> Halting processor…
00:11:06.479 -> Final free heap: 49424
00:11:06.479 -> Final stack: 1280

0 Reply

wachira
 Reply to Guilherme  2 years ago

I also had have same error as you. after change Google Script ID by remain only id string (remove url, remained only ID. Ex. only pasted
AKfycbztyMeCrdSmXeypsfbNhAdsafkkQRVkTbI7-x8V0AWZ98kLo and it works !

For all of this, I would like to thanks author for the tutorial.

https://www.electronics-lab.com/project/iot-log-sensor-data-google-sheet-using-nodemcu/ 18/21
11/07/23, 10.49 IoT: Log Sensor Data to Google Sheets using NodeMCU - Electronics-Lab.com
0 Reply

apandi57
 3 years ago

I was succes with project above,but how to add some colomb,in this project data just wite into A1 and B1 how about write data to C1?

0 Reply

Timothy Ultican
 2 years ago

This was a great tutorial. Thanks for sharing

0 Reply

Michael Palermo
 2 years ago

This worked great for me… Is the À in front of ºC intentional?

0 Reply

Pasquale Castelli
 2 years ago

22:15:58.692 -> Errorebody {background-color: #fff; margin: 0; padding: 0;}.errorMessage {font-family: Arial,sans-serif; font-size: 12pt; font-weight: bold; line-heigh
150%; padding-top: 25px;}Funzione script non trovata: doPost

not work.. function script no found

0 Reply

Muhammad Awais
 2 years ago

In this task, you are required to design an IOT based system which is able to represent incoming data on Google Spreadsheet. Your solution should cover the
following course of actions.
a) As you are already familiar with Arduino. Install ESP8266.lib for Arduino IDE in order to get access to Wi-Fi features.
b) Program will send binary numbers ‘1’ and ‘0’ periodically in an infinite loop having a delay of 5 seconds inbetween.
c) Configure Google JavaScript to represent the incoming data in Google Spreadsheet.
d) By creating access points, you will be able to send data to google spreadsheets via Internet.

0 Reply

Christopher Lunsford
 1 year ago

Is this supposed to keep logging? It work for me but stops after it pushes data one time.

0 Reply

ESWAR
 1 year ago

I AM GETTING AN ERROR SAYING, “multiple definition of `host’;”


SAME IS THE CASE FOR PASSWORD,SSID,GSCRIPTID.
PLEASE HELP!!

0 Reply

ESWAR
 1 year ago

I AM GETTING ERRORS SAYING,


multiple definition of GScriptId';
multiple definition ofhost
multiple definition of password,

https://www.electronics-lab.com/project/iot-log-sensor-data-google-sheet-using-nodemcu/ 19/21
11/07/23, 10.49 IoT: Log Sensor Data to Google Sheets using NodeMCU - Electronics-Lab.com
multiple definition ofssid.
PLEASE HELP ASAP. THANKYOU.

0 Reply

rohith
 1 year ago

any one know automatically change data sheets after complete one

0 Reply

RELATED PROJECTS

Introduction to LoRa – Send data between two… Indoor Air Quality Monitoring System ESP8266 based Online Weather Widget using
Wemos D1

READ MORE READ MORE READ MORE

Menu Projects Connect With Us

Community Audio Arduino & Raspberry Facebook Contact Us

Blog MCU Development Microcontroller Twitter Work For U

https://www.electronics-lab.com/project/iot-log-sensor-data-google-sheet-using-nodemcu/ 20/21
11/07/23, 10.49 IoT: Log Sensor Data to Google Sheets using NodeMCU - Electronics-Lab.com
Downloads Miscellaneous Motor Control Linkedin Advertising
     
Articles Power Light – Power Control

Links Oscillators – Timers Sensors – Detectors


email@domain.com

© ELECTRONICS-LAB.COM – 2023, WORK IS LICENCED UNDER CC BY SA 4.0 PRIVACY POLICY TERMS OF SERVICE USE

https://www.electronics-lab.com/project/iot-log-sensor-data-google-sheet-using-nodemcu/ 21/21

You might also like