UrlFetchApp带有IP地址的错误请求

时间:2014-07-22 04:43:56

标签: json google-apps-script arduino webserver wifi

我正在尝试使用Google Apps脚本将来自我的Arduino Uno的模拟输入数据存储在Google电子表格中。但是,当我运行我的脚本时,我收到一个错误的请求错误。以下是底部调试窗格的错误屏幕截图:Error screenshot.

我正在按照教程编写脚本:Daviom.com Arduino wi-fi server to Google Drive storage。我知道我的Arduino运行正常,因为根据教程,我可以通过浏览器导航到我的Arduino WiFi Shield的IP地址和端口,将模拟输入数据视为JSON对象。

以下是我正在使用的代码:

/**

Google Drive Arduino fetcher

Query an Arduino Board and receive some data in JSON format: store everything
in a Spreadsheet

Author: Edoardo Scalafiotti edoardo.s@daviom.com

*/

var spreadsheetId, arduinoIp;

spreadsheetId = '1m6KjZaAuFoj6nQOnPCzHQxSpCiGL-yNB4PcZrTfCzOU';
arduinoIp = 'http://192.168.1.103:8080';

function getData()
{

  var response, options, dataReceived, ss, sheet;

  options =
  {
    // Ensure we get a fresh copy of the site every time.
    headers : {'Cache-Control' : 'max-age=0'}
  };

  response = UrlFetchApp.fetch(arduinoIp,options);
  dataReceived = Utilities.jsonParse(response.getContentText());
  Logger.log(response.getContentText()); //comment out this line if you don't want debug

  ss = SpreadsheetApp.openById(spreadsheetId); // open the Spreadsheet
  sheet = ss.getSheetByName(dataReceived.sheet); // select the right sheet 
  sheet.getRange(sheet.getLastRow()+1, 1, 1, 3).setValues([[new Date(),dataReceived.projectid,dataReceived.value]]);
}

我对Google Apps脚本编程(以及一般的编程)非常缺乏经验,所以我不确定会出现什么问题。我尝试在函数循环中定义arduinoIp和spreadsheetId,但这似乎没有解决问题。我也尝试过查看以前的stackoverflow问题,但我找不到任何似乎可以解决这个问题的答案。任何帮助,将不胜感激。谢谢,如果您需要任何进一步的信息,请告诉我。

1 个答案:

答案 0 :(得分:1)

您尝试访问的本地IP地址因为Apps脚本在Google服务器上执行而无法正常工作。

您需要将路由器上的端口转发到您当地的arduino IP地址,以便可以从互联网访问。

您在"调整网络设置"

后面的教程中介绍了它