Alex Fionda
Published © CC BY-NC

Cloud-Based Temperature Logger For Homebrew Fermenter

Using battery powered NodeMCU v2 and DS18B20 thermometer to log temperature and system voltage on Google Sheets.

BeginnerWork in progress3 hours2,491
Cloud-Based Temperature Logger For Homebrew Fermenter

Things used in this project

Hardware components

NodeMCU ESP8266 Breakout Board
NodeMCU ESP8266 Breakout Board
NodeMCU v2
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1
DS18B20 Programmable Resolution 1-Wire Digital Thermometer
Maxim Integrated DS18B20 Programmable Resolution 1-Wire Digital Thermometer
×1
USB-A to Micro-USB Cable
USB-A to Micro-USB Cable
×1
18650 Micro USB 1A Charging Board
×1

Software apps and online services

Arduino IDE
Arduino IDE
Google Sheets
Google Sheets
Pushingbox

Story

Read more

Schematics

Connections between NodeMCU v2, DS18B20 and 18650 module

Code

Code for Arduino IDE

Arduino
//Required libraries
#include "ESP8266WiFi.h"
#include "OneWire.h"
#include "DallasTemperature.h"

// Data wire is plugged into pin 2 on the Arduino, which maps to D4 on this board.
#define ONE_WIRE_BUS 2

// Setup a OneWire instance to communicate with any OneWire devices.
  OneWire oneWire(ONE_WIRE_BUS);

// Pass our OneWire reference to Dallas Temperature.
  DallasTemperature sensors(&oneWire);

// Sleep time / logging interval in seconds (accounting shift in data logging).
  const int sleeptime = 935;

// Pushingbox API server.
  const char WEBSITE[] = "api.pushingbox.com";

// Device ID from Pushingbox
  const String devid = "vD1F0274433B664B";

// Wifi SSID
  const char* MY_SSID = "SSID";

// Wifi password
  const char* MY_PWD =  "PASSWORD";

// Used at the beginning of sketch to read VCC voltage (ADC pin must be free)
  ADC_MODE(ADC_VCC);

void setup()
{
// Begin connection to Wireless LAN.
  Serial.begin(115200);
  Serial.println("");
  Serial.println("ESP8266/NodeMCU is awake.");
  Serial.print("Attempting connection to designated Wireless LAN");
  WiFi.begin(MY_SSID, MY_PWD);
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(1000);
    Serial.print(".");
  }
  Serial.println(" connected to Wireless LAN!");

// Issue a global temperature request to all devices on the bus.
  Serial.print("Reading DS18B20 sensor...");
  sensors.requestTemperatures();
  delay (1000);

// Read temperature as celsius (this is the default).
  float celData = sensors.getTempCByIndex(0);

// Read VCC and scale it to match multimeter.
  float voltage = ESP.getVcc() / 1000.0 * 1.53
  ;

// Check if there are any read failures and exit early to try again.
  if (isnan(celData))
  {
    Serial.println("Failed to read from DS18B20 sensor!");
    return;
  }

// Print to serial monitor or terminal of your choice, at 115200 baud.
  Serial.print(" the temperature is ");
  Serial.print(celData);
  Serial.println(" *C ");
  Serial.print("The battery is reading ");
  Serial.print(voltage);
  Serial.println(" volts.");

// Instantiate WiFi object.
  WiFiClient client;

// Start API service using our WiFi client through PushingBox.
  if (client.connect(WEBSITE, 80))
  {
    client.print("GET /pushingbox?devid=" + devid
                 + "&celData="      + (String) celData
                 + "&voltage="      + (String) voltage
                );
    client.println(" HTTP/1.1");
    client.print("Host: ");
    client.println(WEBSITE);
    client.println("User-Agent: ESP8266/1.0");
    client.println("Connection: close");
    client.println();
  }
  Serial.println("Data was sent to Google Sheets via Pushingbox.");

// Sending ESP8266/NodeMCU into deep sleep (requires jumper between RST and D0).
  Serial.println("ESP8266/NodeMCU is now going to sleep.");
  ESP.deepSleep(sleeptime * 1000000, WAKE_RF_DEFAULT);
  delay(1000);

}

void loop()
{
  
}

Google App Script

JavaScript
//-----------------------------------------------
//Originally published by Mogsdad@Stackoverflow
//Modified for jarkomdityaz.appspot.com
//Modified for Hackster.io by Stephen Borsay
//-----------------------------------------------
/*

GET request query:

https://script.google.com/macros/s/<gscript id>/exec?celData=data_here
----------------------------------------------------------------------

GScript, PushingBox and Arduino/ESP8266 Variables in order:

celData
volData
----------------------------------------------------
*/


/* Using spreadsheet API */

function doGet(e) { 
  Logger.log( JSON.stringify(e) );  // view parameters

  var result = 'Ok'; // assume success

  if (e.parameter == undefined) {
    result = 'No Parameters';
  }
  else {
    var id = '1vhIw8N9_N7dHcB3fNVhj1E9cVRg9hRfgyqzK-10kAeI';//docs.google.com/spreadsheetURL/d
    var sheet = SpreadsheetApp.openById(id).getActiveSheet();
    var newRow = sheet.getLastRow() + 1;
    var rowData = [];
    //var waktu = new Date();
    rowData[0] = new Date(); // Timestamp in column A
    
    for (var param in e.parameter) {
      Logger.log('In for loop, param='+param);
      var value = stripQuotes(e.parameter[param]);
      //Logger.log(param + ':' + e.parameter[param]);
      switch (param) {
        case 'celData'://parameter1
          rowData[1] = value;//value1
          break;
        case 'volData'://parameter2
          rowData[2] = value;//value2
          break;
          default:
          result = "unsupported parameter";
      }
    }
    Logger.log(JSON.stringify(rowData));

    // Write new row below
    var newRange = sheet.getRange(newRow, 1, 1, rowData.length);
    newRange.setValues([rowData]);
  }

  // Return result of operation
  return ContentService.createTextOutput(result);
}

/**
* Remove leading and trailing single or double quotes
*/
function stripQuotes( value ) {
  return value.replace(/^["']|['"]$/g, "");
}

Credits

Alex Fionda

Alex Fionda

1 project • 2 followers
Thanks to , Stephen Borsay, and Jason Follas.

Comments