Skip to content

Instantly share code, notes, and snippets.

@ivanseidel
Last active August 9, 2016 18:10
Show Gist options
  • Save ivanseidel/fffa763b7acd4b5e1e59e8c3625f9226 to your computer and use it in GitHub Desktop.
Save ivanseidel/fffa763b7acd4b5e1e59e8c3625f9226 to your computer and use it in GitHub Desktop.
Sends data to Google Drive with Johnny-five and request

Google Sheets Template:

https://docs.google.com/spreadsheets/d/1RgJ9S52lzCEM05K46xQffEO_QHocIUQ-xvSXac8TJng/edit?usp=sharing

Google Sheets Script:

function salvarDado(valor) {
  var url = "https://docs.google.com/spreadsheets/d/1RgJ9S52lzCEM05K46xQffEO_QHocIUQ-xvSXac8TJng/edit#gid=0";  
  var planilha = SpreadsheetApp.openByUrl(url);
  var dados = planilha.getSheetByName('Dados');
  
  dados.insertRowBefore(2);
  dados.getRange("A2").setValue(new Date());
  dados.getRange("B2").setValue(valor);
}

function doGet(propriedades){
  salvarDado(propriedades.parameter.sensor);
  
  var output = "Valor salvo: "+propriedades.parameter.sensor;
  
  return HtmlService.createHtmlOutput(output);
}
var five = require('johnny-five');
var request = require('request');
var url = 'https://script.google.com/macros/s/YOUR-APP-ID-HERE/exec';
var board = new five.Board();
board.on("ready", function() {
var sensor = new five.Pin("A0");
// Faz leitura unica e loga o valor
function lerSensor(){
sensor.query(function(state) {
console.log(state.value);
request(url + '?sensor=' + state.value);
})
};
// Inicia leitura do sensor a cada 1s
setInterval(lerSensor, 3000);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment