SHARE
TWEET

Untitled

a guest Feb 22nd, 2019 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //1eESQsmS6oo9YgFEo0DnILxtukfNf-5NwUdnqeeP7w4o
  2. //https://script.google.com/macros/s/AKfycby1ForREXO6r45BwcoqWR7dzm6IrESZ6vyoFh0N6cmT9HIgF_Lv/exec?temperature=21&humidity=82&temperature=21&humidity=82&temperature=21&humidity=82&temperature=21&humidity=82&temperature=21&humidity=82&temperature=21&humidity=82&temperature=21&humidity=82&temperature=21&humidity=82&temperature=21&humidity=82&temperature=21&humidity=82
  3. //https://script.google.com/macros/s/AKfycby1ForREXO6r45BwcoqWR7dzm6IrESZ6vyoFh0N6cmT9HIgF_Lv/exec?temperature=1,2&humidity=3,4
  4. //-----------------------------------------------
  5. // Author: Trieu Le
  6. // Email: lethanhtrieuk36@gmail.com
  7. // Publish date: 07-Oct-2015
  8. // Description: This code for demonstration send data from ESP8266 into Google Spreadsheet
  9. // GET request syntax:
  10. // https://script.google.com/macros/s/AKfycby1ForREXO6r45BwcoqWR7dzm6IrESZ6vyoFh0N6cmT9HIgF_Lv/exec
  11. //-----------------------------------------------
  12. /**
  13. * Function doGet: Parse received data from GET request,
  14.   get and store data which is corresponding with header row in Google Spreadsheet
  15. */
  16. function doGet(e) {
  17.   Logger.log( JSON.stringify(e) );  // view parameters
  18.   var result = 'Makker het doet pijn om goed aan het loggen te zijn.'; // assume success
  19.   if (e.parameter == 'undefined') {
  20.     result = 'No Parameters';
  21.   }
  22.   else {
  23.     var sheet_id = '1eESQsmS6oo9YgFEo0DnILxtukfNf-5NwUdnqeeP7w4o';      // Spreadsheet ID
  24.     var sheet = SpreadsheetApp.openById(sheet_id).getActiveSheet();     // get Active sheet
  25.     var newcolumn = sheet.getLastColumn() + 1;                      
  26.     var rowData = [];
  27.     var d = new Date();
  28.     var timeStamp = d.getTime();
  29.    
  30.     var lastRow = sheet.getLastRow(); + 1
  31.     var lastColumn = sheet.getLastColumn(); + 1
  32.    
  33.     rowData[0] = timeStamp;                                             // Timestamp in column A
  34.     for (var param in e.parameter) {
  35.       Logger.log('In for loop, param=' + param);
  36.       var value = stripQuotes(e.parameter[param]);
  37.       Logger.log(param + ':' + e.parameter[param]);
  38.      
  39.       switch (param) {
  40.         case 'temperature': //Parameter
  41.           var arrayT = value.split(",");      
  42.           Logger.log(JSON.stringify(arrayT));
  43.           var newRange = sheet.getRange(1, newcolumn, 1, arrayT.length);
  44.           newRange.setValues([arrayT]);
  45.          
  46.           break;
  47.          
  48.         case 'humidity': //Parameter
  49.           var arrayH = value.split(",");
  50.           Logger.log(JSON.stringify(arrayH));
  51.           var newRange = sheet.getRange(2, newcolumn, 1, arrayH.length);
  52.           newRange.setValues([arrayH]);
  53.           break;
  54.          
  55.         default:
  56.           result = "unsupported parameter";
  57.       }
  58.     }
  59.   }
  60.   // Return result of operation
  61.   return ContentService.createTextOutput(result);
  62. }
  63. /**
  64. * Remove leading and trailing single or double quotes
  65. */
  66. function stripQuotes( value ) {
  67.   return value.replace(/^["']|['"]$/g, "");
  68. }
  69. //-----------------------------------------------
  70. // End of file
  71. //-----------------------------------------------
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top