为什么使用 AT 命令从 Adruino GPRS 连接到 xively 时 TCP 连接一直关闭? [英] Why does TCP connection keep closing while connecting to xively from Adruino GPRS with AT commands?

查看:23
本文介绍了为什么使用 AT 命令从 Adruino GPRS 连接到 xively 时 TCP 连接一直关闭?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 AT 命令将数据从蜂窝连接的 arduino 温度传感器发送到 xively.com.我可以打开 TCP 连接,但它立即关闭.为什么 TCP 连接总是关闭?

I'm trying to send data from a cellular-connected arduino temperature sensor to xively.com using AT commands. I can open the TCP connection, but then it immediately closes. Why does the TCP connection keep closing?

设置:Arduino Uno麦克本Seeedstudio gprs v2.0att gophone sim卡

setup: arduino uno mackbook seeedstudio gprs v2.0 att gophone sim card

这是我的终端读数:

Call Ready
AT

OK
AT+CPIN?

+CPIN: READY

OK
AT+CGATT?

+CGATT: 1

OK
AT+CIPSHUT

SHUT OK
AT+CIPSTATUS

OK

STATE: IP INITIAL
AT+CIPMUX=0

OK
AT+CSTT="wap.cingular"

OK
AT+CIICR

OK
AT+CIFSR

10.52.49.206
AT+CIPSTART="TCP","api.xively.com","80"

OK

STATE: TCP CLOSED

我的设置:SEEEDStudio GPRS 屏蔽Arduino Unomacbook

my setup: SEEEDStudio GPRS shield Arduino Uno macbook

为了向 sheild 发送 AT 命令,我使用以下代码设置了一个串行继电器:

To send AT commands to the sheild, I have set up a serial relay using the following code:

//Serial Relay - Arduino will patch a 
//serial link between the computer and the GPRS Shield
//at 19200 bps 8-N-1
//Computer is connected to Hardware UART
//GPRS Shield is connected to the Software UART 

#include <SoftwareSerial.h>

SoftwareSerial GPRS(7, 8);
unsigned char buffer[64]; // buffer array for data recieve over serial port
int count=0;     // counter for buffer array 
void setup()
{
  GPRS.begin(19200);               // the GPRS baud rate   
  Serial.begin(19200);             // the Serial port of Arduino baud rate.

}

void loop()
{
  if (GPRS.available())              // if date is comming from softwareserial port ==> data is comming from gprs shield
  {
    while(GPRS.available())          // reading data into char array 
    {
      buffer[count++]=GPRS.read();     // writing data into array
      if(count == 64)break;
  }
    Serial.write(buffer,count);            // if no data transmission ends, write buffer to hardware serial port
    clearBufferArray();              // call clearBufferArray function to clear the storaged data from the array
    count = 0;                       // set counter of while loop to zero


  }
  if (Serial.available())            // if data is available on hardwareserial port ==> data is comming from PC or notebook
    GPRS.write(Serial.read());       // write it to the GPRS shield
}
void clearBufferArray()              // function to clear buffer array
{
  for (int i=0; i<count;i++)
    { buffer[i]=NULL;}                  // clear all index of array with command NULL
}

然后我输入命令并使用 CoolTerm 监控串行通信.

I then enter the commands and monitor serial communication with CoolTerm.

推荐答案

这对我有用:

send AT+CGREG? until you get +CGREG: 0,1
send AT+CGATT? response +CGATT: 1
send AT+CSTT="internet","","" response OK
send AT+CIICR response OK
send AT+CIFSR response IP address
send AT+CIPSTART="TCP","api.xively.com","80" response CONNECT OK

这篇关于为什么使用 AT 命令从 Adruino GPRS 连接到 xively 时 TCP 连接一直关闭?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆