我正在尝试将从ESP8266获取的数据传递到Google电子表格。我修改了此处的代码,将WiFi扫描中的数据插入电子表格中:
我的问题是我想在新行中输入每个新网络的信息。我猜测问题是case语句太快,无法为每个信号添加新行。我尝试在每个获取的信号之后插入一个新的行函数,但看起来这会导致代码完全脱离switch语句。
var newRange = sheet.getRange(newRow,1,1,rowData.length); newRange.setValues([rowData]);
我是Javascript的新手,所以我不确定我做错了什么。任何提示将不胜感激。
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 =//SpreadSheet ID Here
var sheet = SpreadsheetApp.openById(id).getActiveSheet();
var newRow = sheet.getLastRow() + 1;
var rowData = [];
var colData = [];
//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 'ssid0': //Parameter
rowData[1] = value; //Value in column B
break;
case 'bssid0':
rowData[2] = value;
break;
case 'rssi0':
rowData[3] = value;
//This doesn't work
var newRange = sheet.getRange(newRow, 1, 1, rowData.length);
newRange.setValues([rowData]);
break;
case 'ssid1':
rowData[4] = value;
break;
case 'bssid1':
rowData[5] = value;
break;
case 'rssi1':
rowData[6] = value;
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);
}
}
function stripQuotes( value ) {
return value.replace(/^["']|['"]$/g, "");
}