Seeed-Studio / GPRS_SIM900

library for GPRS shield with sim900 module.
MIT License
138 stars 96 forks source link

Connect Error #28

Closed rishabhrpg closed 4 years ago

rishabhrpg commented 6 years ago

I have tested all other funcationality they work fine but when trying to connect to gprs services its returning connect error and then fetch over message. I guess I am misssing something APN setting or something like that. I didn't find any method to APN though in the Source Code though.


#include <GPRS_Shield_Arduino.h>
#include <SoftwareSerial.h>
#include <Wire.h>

#define PIN_TX    2
#define PIN_RX    3
//make sure that the baud rate of SIM900 is 9600!
//you can use the AT Command(AT+IPR=9600) to set it through SerialDebug
#define BAUDRATE  9600

char http_cmd[] = "GET /hello.txt HTTP/1.0\r\n\r\n";
char buffer[512];
GPRS gprs(PIN_TX, PIN_RX, BAUDRATE);
void setup(){
  gprs.checkPowerUp();
  Serial.begin(9600);
  Serial.print("Start TCP demostration...\r\n");

  // use DHCP
  while(!gprs.init()) {
      delay(1000);
      Serial.print("Initializing...\r\n");
  }

  while(!gprs.isNetworkRegistered())
  {
    delay(1000);
    Serial.println("Network has not registered yet!");
  }

  delay(3000);    
  // attempt DHCP
  while(!gprs.join(F("cmnet"))) {
      Serial.println("gprs join network error");
      delay(2000);
  }

  // successful DHCP
  Serial.print("IP Address is ");
  Serial.println(gprs.getIPAddress());

  if(!gprs.connect(TCP,"hpledmis.com", 80)) {
      Serial.println("connect error");
  }else{
      Serial.println("connect mbed.org success");
  }

  Serial.println("waiting to fetch...");
  gprs.send(http_cmd, sizeof(http_cmd)-1);
  while (true) {
      int ret = gprs.recv(buffer, sizeof(buffer)-1);
      if (ret <= 0){
          Serial.println("fetch over...");
          break; 
      }
      buffer[ret] = '\0';
      Serial.print("Recv: ");
      Serial.print(ret);
      Serial.print(" bytes: ");
      Serial.println(buffer);
  }
  gprs.close();
  gprs.disconnect();
}

void loop(){

}
lanselambor commented 6 years ago

You can try this repo, change these two pins.

image

APN setting functionality: https://github.com/Seeed-Studio/Seeeduino_GPRS/blob/master/gprs.cpp#L64

And you may have to modify power on function: https://github.com/Seeed-Studio/Seeeduino_GPRS/blob/master/sim800.cpp#L33