[LIB+TOOL] FCGF : Universal statistic library for Google Form

After the publication of the guide “how to send data to a Google Drive Form”, it has been decided to release a starter kit which allows to save data on a Google Drive Form in a simplified manner.
In this process we will go through the creation of a Form on Google Drive, the explanation of the Array toolkit, needed for this project, the library configuration and a test of the code.
In order to simplify the process, it has been created a library which can send data on Google Drive with few easy steps, no matter the board you are using (the only requirement is to have the Wifi module installed).
We believe in free sharing so the code has been released for free to anyone, hoping that it can be improved by the internet community.
Let’s get started!

1.How to create a form on Google Drive

There are only few easy steps to create a Google Drive form:

First, connect to your Google Drive account and click on New, as reported in figure below:

From the menu, click on tab More 🡪 Google Forms, as reported in the image below:

If the process has been performed correctly, a webpage like the one reported below, should appear:

As shown in the previous figure, add as many fields as you need (depending on the numbers of parameters you want to save on your form) by clicking on the button contained in the yellow box making sure to set the field as Short answer inside the red box.

Make sure to copy the URL of the webpage and paste it somewhere, like in a notepad document:

Now click on the preview button and again copy the URL of the webpage: in this case the URL is related to the public page while the previous is the link of the editor.

2.Array ToolKit

The Array ToolKit is a device, developed by our team, which extracts from the HTML code the arrays needed for the code to save parameters on your online form. 

In particular, the arrays to be stored are three variables: (mymodule_privateid, mymodule_forms, mymodule_contents)  which contains respectively the private id of the Google Form, the id of the html Forms of the module and the last is the array contains all the values which we send to the form. https://www.filoconnesso.it/developers/FCGFToolKit/?lang=en

Starting the ToolKit (https://www.filoconnesso.it/developers/FCGFToolKit/?lang=en), a page like the one reported below will be opened:

Fill the form with the data of your Wi-Fi connection in the first two fields (SSID and password respectively)

In the third field the editor link of the module should be pasted; in the fourth field paste the public link. In the last field it possible to give a prefix to variabiles (e.g. myform):

Click on “PROCESS NOW” to generate the code :

To download the generated sketch click on “Download Vanilla File”; in case you need to change only a small part of code it is also possible to copy a part of it:

3.Download and installation of the library FCGF

LinkName fileVersionHost
DownloadFCGF0.0.1.zip0.0.1 [VANILLA]GitHub
DownloadFCGF0.0.2.zip0.0.2 [VANILLA]GitHub

FCGF can be installed from the Arduino IDE from Sketch tab as shown below:

An example named “Vanilla” is included with the package.

Open “generated_Vanilla-xxxxxxxxx” code downloaded at the previous step from the ToolKit:

4.Code Analysis

In this section the code is analyzed in detail,

The library is included with #include:

Next, GoogleForm class form is called and defined with the acronym “gf”:

Scrolling down the code, there are elements containing Wi-Fi SSID and password:

In which,
your_wifi_ssid contains the SSID of your router;
your_wifi_password contains the password of your router .

Moving on, there are three variables containing the arrays which allows to send data to your form on Google Drive:

In which,
num_of_inputs contains the number of fields of the module;
myform_privateid contains the ID of the Form;
myform_inputs is an array containing all the IDs of the form fields;
myform_values is an array containing all the values containing values to be send to the Form.

As mentioned, prefix “myform_” can be replaced; this modification can be done with the ToolKit.

Let’s now go through two fundamental functions: begin and submit. Since they are relative to this library, it is necessary to recall them with the prefix gf. :

Function begin has as inputs the two variables containing SSID and password of the router with the aim of connecting the board to the Google server. The structure is the following:

gf.begin(SSID,password);

Function submit send data to Google Form. The structure is the following:

gf.submit(ID_form,array_fields,array_values,number_of_fields);

Up to this, all inputs of functions where variables presented at the previous points.

Variable myform_values contains data to be send to Google Form. The code generated by ToolKit shows default values “yourval_x”.

For example, to send as values words “mirko” and “pacioni”, the code should be modified as follows:

5.Testing the code

Let’s test the code: first make sure to connect the board allowing the upload of the code. If you are using an ESP-01, you can adopt this connection scheme.

Now open the Serial Monitor and upload the code on your board.

If submit reply is “correct submission!” as in the image below, the outcome is successful.

Connecting to your form editor from the browser you will find the elements previously submitted:

On the contrary, if submit reply is “failed!”, submit outcome is negative. It may depends on an instability of your internet connection or, if using an Arudino MKR WiFi 1010, host keys certificates for “google.com” and “docs.google.com” may be missing.

6.Sending sensors output or numbers

Sensors output usually are numbers (since many of them are analog) but this library can send only strings. To overcome this problem, it is needed to convert numbers into strings through the command String:

Data can be sent inside the loop with function submit. For example, it is possibile to temperature readings real time of a BMP module.

7. Function recap

In this section, a short recap of the main functions is presented:

begin

gf.begin(const char* wifi_name, const char* wifi_password);

Initializes the library and connects the board to the router

submit

gf.submit(String module_id, String array_forms, String array_contents, int num_inputs);

Send data to your Google Form

delayMinute

gf.delayMinute(int minutes);

It works as standard delay function but input is minutes instead of milliseconds. If empty, default value is unit.

setWebAgent

gf.setWebAgent(String web_agent);

It sets the Web agent.
Default: FCIotDevice

setLanguage

gf.setLanguage(String language);

It sets the language of the Google app (ex.: it, en, fr, etc)

Callback

It confirms that data have been correctly received and saved.

From version Alpha 0.0.2 it is possible to receive confirmation of the correct submission of data to the Form. If data have been submitted correctly, the variable FCGF_SUBMIT_CALLBACK will assume value true and if not, false.

This function gives also the opportunity to realize customized reaction depending on the outcome of submission. A possible usage is explained with example LEDCallback which shows how to switch on a green led for successful submission and a red one on for an incorrect submission.

8.Possible usages

This library allows to develop many applications, from instant polls to data gathering for IoT applications: for this last topic it is also possible to generate spreadsheets updated real time like the one presented below:

Data gathered from a BME280 sensor and elaborated real time on a spreadsheet on Google Drive

9.Terms of usage

This library is available under the Creative Commons Attribution-ShareAlike License

For commercial use contact redazione@filoconnesso.it.

10.Compatibility

This library has been tested compatible with the following boards:

  1. Arduino MRK Wi-Fi 1010
  2. ESP01
  3. Wemos D1 Mini
  4. Wemos D1
  5. Nodemcu ESP8266
  6. Nodemcu 0.9 (ESP-12)
  7. ESP32 Dev Kit v1
  8. ESP32 Wroom32

If your board is not listed here and is compatible with this library, let us know!

11.Support the project

You can support this project joining us on Instagram, Youtube and Facebook and sharing this page with your friends.

This library has been developed by Mirko Pacioni with the help of Manuel Penna and Edoardo Sassi.
This article has been translated from italian by Edoardo Sassi.

Buy on Amazon from this banner to support filoconnesso.it: