Arduino GSM Gboard Sim900:无法连接到服务器

时间:2016-12-27 19:52:05

标签: arduino gsm

在以下源代码中,我使用带有跳线tsData GBoard Itead Sim900 ST->D2, SR->D3的内容发送到服务器 GSMShield库(GSM_GPRSLibrary_AT,GSM_GPRSLibrary_Call,GSM_GPRSLibrary_Client,GSM_GPRSLibrary_GPS,GSM_GPRSLibrary_Server,GSM_GPRSLibrary_SMS)

但是, GBoard似乎无法连接到 ThingSpeak 服务器

你能帮我修理bevahiour吗?

我有这段代码:

const byte DATA = 8;
int cont1=0;
int cont2=0;
int cont3=0;
int connectTCP;
unsigned long time;

#include "SIM900.h"
#include <SoftwareSerial.h>
#include "inetGSM.h"
//#include <GSM.h>
//#include <SPI.h>
//#include <Ethernet.h>
//#include "sms.h"
//#include "call.h"    
InetGSM inet;   
#define PINNUMBER ""           
// APN data
#define GPRS_APN       "-"  // replace your GPRS APN
#define GPRS_LOGIN     "-"     // replace with your GPRS login
#define GPRS_PASSWORD  "-"  // replace with your GPRS password        
char serverAddress[] = "server.com";
String writeAPIKey = "---";   
long lastConnectionTime = 0;
boolean lastConnected = false;
boolean started=false;
int failedCounter = 0;  
void setup()
{
// Start Serial for debugging on the Serial Monitor
Serial.begin(9600);
Serial.println("GSM Shield testing.");
  //Start configuration of shield with baudrate.
  //For http uses is raccomanded to use 4800 or slower.
  if (gsm.begin(2400)){
    Serial.println("\nstatus=READY");
    started=true;  
  }
  else Serial.println("\nstatus=IDLE");
  // 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(inet.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD))
      notConnected = false;
    else
    {
      Serial.println("Not connected");
      delay(1000);
    }
  }
}  
void loop()
{ 
time = millis()/999;      
  }     
  // if there's incoming data from the net connection.
  // send it out the serial port.  This is for debugging
  // purposes only:
if (gsm.available())
{
char c = gsm.read();
Serial.print(c);
}
// Disconnect from server
if (!gsm.available() && lastConnected)
{
Serial.println("...disconnected");
Serial.println();
int disconnectTCP();
}

// Update server
if(!gsm.available() && (millis() - lastConnectionTime > 120000))
{         
 funtcion a();//[Example]

}
}
// Check if gsmboard needs to be restarted
//if (failedCounter > 3 ) {startEthernet();}
//lastConnected = client.connected();

void updateServer(String tsData)
{
if (inet.connectTCP(serverAddress, 80))
{
gsm.SimpleWrite("POST /update HTTP/1.1\n");
gsm.SimpleWrite("Host: server.com\n");
gsm.SimpleWrite("Connection: close\n");
gsm.SimpleWrite("SERVER: ");
gsm.SimpleWrite("writeAPIKey");
gsm.SimpleWrite("\n");
gsm.SimpleWrite("Content-Type: application/x-www-form-urlencoded\n");
gsm.SimpleWrite("Content-Length: ");
gsm.SimpleWrite(tsData.length());
gsm.SimpleWrite("\n\n");
gsm.SimpleWrite(tsData.c_str());//----IN THIS LINE I THINK IS THE PROBLEM----
lastConnectionTime = millis();
if (inet.connectedClient())
{
Serial.println("Connecting to SERVER...");
Serial.println();
failedCounter = 0;
}
else
{
failedCounter++;
Serial.println("Connection to SERVERfailed ("+String(failedCounter, DEC)+")");
Serial.println();
}
}
else
{
failedCounter++;
Serial.println("Connection to SERVERFailed ("+String(failedCounter, DEC)+")");
Serial.println();
lastConnectionTime = millis();
}
}

, 这是控制台中的输出:

 GSM Shield testing.
ATT: OK
RIC: AT

OK

DB:ELSE
ATT: OK
RIC: AT

OK

DB:ELSE
ATT: OK
RIC: AT

OK

DB:ELSE
ATT: OK
RIC: AT

OK

DB:CORRECT BR
ATT: OK
RIC: AT

OK

ATT: OK
RIC: AT&F

OK

ATT: OK
RIC: ATE0

OK

ATT: OK
RIC: 
OK

ATT: OK
RIC: 
OK

ATT: OK
RIC: 
OK

ATT: OK
RIC: 
OK

ATT: +CPMS:
RIC: 
+CPMS: 30,30,30,30,30,30

OK

ATT: OK
RIC: 
OK

ATT: SHUT OK
RIC: 
SHUT OK


status=READY
ATT: ERROR
RIC: 
ERROR

DB:STARTING NEW CONNECTION
ATT: SHUT OK
RIC: 
SHUT OK

DB:SHUTTED OK
ATT: OK
RIC: 
OK

DB:APN OK
ATT: OK
RIC: 
OK

DB:CONNECTION OK
ATT: ERROR
RIC: 
--.--.--.--

DB:ASSIGNED AN IP
1//----------------Counter--------------
ATT: OK
RIC: 
OK

DB:RECVD CMD
ATT: CONNECT OK
RIC: 
OK

ATT: OK
RIC: 
CONNECT OK

DB:OK TCP
ATT: >
RIC: 
> 
DB:>
Connecting to Server...


CLOSED

ERROR

0 个答案:

没有答案