Can';t使用Arduino GSM屏蔽上传视频源

Can';t使用Arduino GSM屏蔽上传视频源,arduino,gsm,xively,Arduino,Gsm,Xively,我正试图上传一个Xively提要,其中一个Arduino通过Arduino GSM屏蔽连接 Xively未发布任何Arduino GSM屏蔽的具体示例。我尝试使用Arduino GSM Pachube客户端库,在“xively.com”中更改“Pachube.com”,但没有成功。似乎我的GSM屏蔽能够连接,但无法将数据放入服务器 在我的示例中,我创建了一个名为“Arduino GSM”的设备,其中只有一个通道名为“sensor1”。在请求日志中,我无法读取任何传入的请求,尽管串行监视器显示发生

我正试图上传一个Xively提要,其中一个Arduino通过Arduino GSM屏蔽连接

Xively未发布任何Arduino GSM屏蔽的具体示例。我尝试使用Arduino GSM Pachube客户端库,在“xively.com”中更改“Pachube.com”,但没有成功。似乎我的GSM屏蔽能够连接,但无法将数据放入服务器

在我的示例中,我创建了一个名为“Arduino GSM”的设备,其中只有一个通道名为“sensor1”。在请求日志中,我无法读取任何传入的请求,尽管串行监视器显示发生了与服务器的连接

这是我尝试的代码:

    // Original GSM Pachube client modified for Xively
    // Changes: pachube.com -> xively.com
    // inserted APIKEY, FEEDID, USERAGENT
    // inserted GPRS_APN, login, password

    /*GSM Pachube client

     This sketch connects an analog sensor to Pachube (http://www.pachube.com)
     using a Telefonica GSM/GPRS shield.

     This example has been updated to use version 2.0 of the Pachube.com API. 
     To make it work, create a feed with a datastream, and give it the ID
     sensor1. Or change the code below to match your feed.

     Circuit:
     * Analog sensor attached to analog in 0
     * GSM shield attached to an Arduino
     * SIM card with a data plan

     created 4 March 2012
     by Tom Igoe
     and adapted for GSM shield by David Del Peral

     This code is in the public domain.

     http://arduino.cc/en/Tutorial/GSMExamplesPachubeClient

     */

    // libraries
    #include <GSM.h>

    // Pachube Client data  -> changed in Xively Data
    #define APIKEY         "myapikey"  //                 replace your pachube api key here
    #define FEEDID         111111111                     // replace your feed ID
    #define USERAGENT      "Arduino GSM"              // user agent is the project name

    // PIN Number
    #define PINNUMBER ""

    // APN data
    #define GPRS_APN       "WINDBIZ WEB"  // replace your GPRS APN
    #define GPRS_LOGIN     ""     // replace with your GPRS login
    #define GPRS_PASSWORD  ""  // replace with your GPRS password

    // initialize the library instance:
    GSMClient client;
    GPRS gprs;
    GSM gsmAccess;

    // if you don't want to use DNS (and reduce your sketch size)
    // use the numeric IP instead of the name for the server:
    // IPAddress server(216,52,233,121);    // numeric IP for api.pachube.com
    char server[] = "api.xively.com";      // name address for pachube API

    unsigned long lastConnectionTime = 0;         // last time you connected to the                 server, in milliseconds
    boolean lastConnected = false;                  // state of the connection last         time through the main loop
    const unsigned long postingInterval = 10*1000;  //delay between updates to Pachube.com

    void setup()
    {
      // initialize serial communications and wait for port to open:
      Serial.begin(9600);
      while (!Serial) {
        ; // wait for serial port to connect. Needed for Leonardo only
      }

      // connection state
      boolean notConnected = true;

      // After starting the modem with GSM.begin()
      // attach the shield to the GPRS network with the APN, login and password
      while(notConnected)
      {
        if((gsmAccess.begin(PINNUMBER)==GSM_READY) &
            (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD)==GPRS_READY))
          notConnected = false;
        else
        {
          Serial.println("Not connected");
          delay(1000);
        }
      }
    }

    void loop()
    {  
      // read the analog sensor:
      int sensorReading = analogRead(A0);   

      // if there's incoming data from the net connection.
      // send it out the serial port.  This is for debugging
      // purposes only:
      if (client.available())
      {
         char c = client.read();
         Serial.print(c);
      }

      // if there's no net connection, but there was one last time
      // through the loop, then stop the client:
      if (!client.connected() && lastConnected)
      {
        client.stop();
      }

      // if you're not connected, and ten seconds have passed since
      // your last connection, then connect again and send data:
      if(!client.connected() && ((millis() - lastConnectionTime) > postingInterval))
      {
      sendData(sensorReading);
      }

      // store the state of the connection for next time through
      // the loop:
      lastConnected = client.connected();
    }

    /*
      This method makes a HTTP connection to the server.
    */
    void sendData(int thisData)
    {
      // if there's a successful connection:
      if (client.connect(server, 80))
      {
        Serial.println("connecting...");

        // send the HTTP PUT request:
        client.print("PUT /v2/feeds/");
        client.print(FEEDID);
        client.println(".csv HTTP/1.1");
        client.print("Host: api.xively.com\n");
        client.print("X-ApiKey: ");
        client.println(APIKEY);
        client.print("User-Agent: ");
        client.println(USERAGENT);
        client.print("Content-Length: ");

        // calculate the length of the sensor reading in bytes:
        // 8 bytes for "sensor1," + number of digits of the data:
        int thisLength = 8 + getLength(thisData);
        client.println(thisLength);

        // last pieces of the HTTP PUT request:
        client.print("Content-Type: text/csv\n");
        client.println("Connection: close");
        client.println();

        // here's the actual content of the PUT request:
        client.print("sensor1,");
        client.println(thisData);
      } 
      else
      {
        // if you couldn't make a connection:
        Serial.println("connection failed");
        Serial.println();
        Serial.println("disconnecting.");
        client.stop();
      }
      // note the time that the connection was made or attempted
      lastConnectionTime = millis();
    }

    /*
      This method calculates the number of digits in the
      sensor reading.  Since each digit of the ASCII decimal
      representation is a byte, the number of digits equals
      the number of bytes.
    */
    int getLength(int someValue)
    {
      // there's at least one byte:
      int digits = 1;

      // continually divide the value by ten, 
      // adding one to the digit count for each
      // time you divide, until you're at 0:
      int dividend = someValue /10;
      while (dividend > 0)
      {
        dividend = dividend /10;
        digits++;
      }

      // return the number of digits:
      return digits;
    }
//为Xively修改了原始GSM Pachube客户端
//更改:pachube.com->xively.com
//插入的APIKEY、FEEDID、USERAGENT
//插入GPRS_APN、登录、密码
/*GSM Pachube客户端
此草图将模拟传感器连接到Pachube(http://www.pachube.com)
使用Telefonica GSM/GPRS屏蔽。
此示例已更新为使用Pachube.com API的2.0版。
要使其工作,请使用数据流创建一个提要,并为其提供ID
传感器1。或者更改下面的代码以匹配您的提要。
线路:
*模拟传感器连接到模拟输入0
*连接到Arduino的GSM屏蔽
*带有数据计划的SIM卡
创建于2012年3月4日
汤姆·伊戈
并由David Del Peral改编为GSM shield
此代码位于公共域中。
http://arduino.cc/en/Tutorial/GSMExamplesPachubeClient
*/
//图书馆
#包括
//Pachube客户端数据->在Xively数据中更改
#在此处定义APIKEY“myapikey”//替换pachube api密钥
#定义提要ID 111111111//替换提要ID
#定义用户代理“Arduino GSM”//用户代理是项目名称
//密码
#定义PINNUMBER“”
//APN数据
#定义GPRS_APN“WINDBIZ WEB”//替换您的GPRS APN
#定义GPRS\u登录“”//替换为您的GPRS登录
#定义GPRS_密码“”//替换为您的GPRS密码
//初始化库实例:
GSM客户;
GPRS;
GSM-gsmAccess;
//如果不想使用DNS(并减小草图尺寸)
//使用数字IP而不是服务器的名称:
//IP地址服务器(216,52233121);//api.pachube.com的数字IP
char服务器[]=“api.xively.com”;//pachube API的名称和地址
无符号长lastConnectionTime=0;//上次连接到服务器时,以毫秒为单位
布尔lastConnected=false;//上次通过主循环的连接状态
常量无符号长postingInterval=10*1000//Pachube.com更新之间的延迟
无效设置()
{
//初始化串行通信并等待端口打开:
Serial.begin(9600);
而(!串行){
;//等待串行端口连接。仅Leonardo需要
}
//连接状态
布尔notConnected=true;
//使用GSM.begin()启动调制解调器后
//使用APN、登录名和密码将屏蔽连接到GPRS网络
while(未连接)
{
如果((gsmAccess.begin(PINNUMBER)=GSM\u READY)&
(gprs.attachGPRS(gprs\u APN、gprs\u登录、gprs\u密码)=gprs\u就绪))
notConnected=false;
其他的
{
Serial.println(“未连接”);
延迟(1000);
}
}
}
void循环()
{  
//读取模拟传感器:
int传感器读数=模拟读数(A0);
//如果有来自网络连接的传入数据。
//通过串口发送出去,这是调试用的
//仅用于:
if(client.available())
{
char c=client.read();
连续打印(c);
}
//如果没有网络连接,但有最后一次
//通过循环,然后停止客户端:
如果(!client.connected()&&lastConnected)
{
client.stop();
}
//如果你没有连接,而且十秒钟过去了
//上次连接,然后再次连接并发送数据:
如果(!client.connected()&&((millis()-lastConnectionTime)>postingininterval))
{
发送数据(传感器读取);
}
//通过存储连接状态以备下次使用
//循环:
lastConnected=client.connected();
}
/*
此方法与服务器建立HTTP连接。
*/
void sendData(int thisData)
{
//如果连接成功:
if(客户端连接(服务器,80))
{
Serial.println(“连接…”);
//发送HTTP PUT请求:
client.print(“PUT/v2/feeds/”);
client.print(FEEDID);
client.println(“.csv HTTP/1.1”);
client.print(“主机:api.xively.com\n”);
client.print(“X-ApiKey:”);
client.println(APIKEY);
client.print(“用户代理:”);
client.println(用户代理);
client.print(“内容长度:”);
//计算传感器读数的长度(以字节为单位):
//“传感器1”的8字节+数据位数:
int thisLength=8+getLength(thisData);
client.println(此长度);
//HTTP PUT请求的最后部分:
client.print(“内容类型:text/csv\n”);
client.println(“连接:关闭”);
client.println();
//以下是PUT请求的实际内容:
client.print(“sensor1,”);
client.println(thisData);
} 
其他的
{
//如果无法建立连接:
Serial.println(“连接失败”);
Serial.println();
Serial.println(“断开”);
client.stop();
}
//记下建立或尝试连接的时间
拉斯康内