Robotics‎ > ‎

Internet of Things

To create your own server
  • Create a new Google Spreadsheet
  • Click on Tools
  • Click Script Editor...
  • Copy and paste the following code:
var SpreadSheetID = '1soD-QzPojcVmjHAXLR70KA-EWajrQNGszXvRtW17TaY';
var ss = SpreadsheetApp.openById(SpreadSheetID);

function doGet(e) {
  if(e.parameter.task === 'get') {
    var sheet = ss.getSheetByName('Control Panel');
    var response = sheet.getRange(e.parameter.row,e.parameter.column).getValue();
    return ContentService.createTextOutput(response)
  } else if (e.parameter.task === 'controlpanel') {
    return HtmlService.createHtmlOutputFromFile('index');
  • Click Publish
  • Click Deploy as Web App
    • Execute the app as yourself
    • Allow "Anyone, even anonymous" to access the app.
  • Copy the QR code into a new tab in your browser.
  • Test it by trying to get a value from the Control Panel sheet in your spreadsheet. For example, try:

Once you've tested your doGet function and are sure you are able to get data from your spreadsheet using get requests, copy and paste the following code into your Arduino IDE. You will also need to install my modified version o fthe HTTPSRedirect library. These will allow you to make get requests to Google services (which, prior to this library, was difficult because Google requires a secure connection and redirects to a different web page when sending a response). Pay particular attention to the lines with a yellow background. They indicate code that is specific to the HTTPSRedirect library.

 *  HTTPS with follow-redirect example
 *  Created by Sujay S. Phadke, 2016
 *  Modified by Michael Backus on Jan 29th, 2017
 *  Based on the WifiClientSecure example by
 *  Ivan Grokhotkov
 *  *
 *  This example is in public domain.

#include <ESP8266WiFi.h>
#include "HTTPSRedirect.h"

// Replace with your network credentials
const char* ssid = "DeviceNet";
const char* password = "T333l@nd";

const char* host = "";
const char* googleRedirHost = "";
const char *GScriptId = "AKfycbyEVxRON5dLacSqIFNyQbZUBhFsobjG2DLIyjnufrEsnbm-zFWG";

const int httpsPort = 443;

HTTPSRedirect client(httpsPort);
void setup() {
  Serial.print("Connecting to wifi: ");
  // flush() is needed to print the above (connecting...) message reliably, 
  // in case the wireless connection doesn't go through

  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
  Serial.println("WiFi connected");
  Serial.println("IP address: ");

  Serial.print("Connecting to ");

  bool flag = false;
  for (int i=0; i<5; i++){
    int retval = client.connect(host, httpsPort);
    if (retval == 1) {
       flag = true;
      Serial.println("Connection failed. Retrying...");
  if (!flag){
    Serial.print("Could not connect to server: ");

void loop() {
  if (!client.connected())
    client.connect(host, httpsPort);

  String url = String("/macros/s/") + GScriptId + "/exec?task=get&row=1&column=2";
  String red = client.printRedir(url, host, googleRedirHost);
  Serial.print("Red: ");

  // In my testing on a ESP-01, a delay of less than 1500 resulted 
  // in a crash and reboot after about 50 loop runs.

Once you are able to get a single value back from your webserver, modify it so that it returns several values separated by commas. Below is a demo program that shows how you can store each value into a variable.
String msg = "123,321,312";
String red = "";
String green = "";
String blue = "";

void setup() {
  // put your setup code here, to run once:
  red = msg.substring(0,msg.indexOf(","));
  green = msg.substring(0,msg.indexOf(","));
  blue = msg;

Here is an example that shows how to log data to a Google spreadsheet:
Michael Backus,
Jan 29, 2017, 10:29 PM