Skip to content
SodaqMoja edited this page Dec 9, 2014 · 5 revisions

Welcome to the GPRSbee wiki!

The GPRSbee library contains two source modules, GPRSbee.cpp and GPRSbee.h. One instance of the class is already present and it is called gprsbee.

Below there is a list of the most import functions. There is a posibility do monitor the traffic between the MCU and the SIM900. This is described on the diag page.

Main Functions

To power the SIM900 on or off.

bool on();
bool off();

To do HTTP requests.

bool doHTTPPOST(const char *apn, const char *url, const char *postdata, size_t pdlen);

bool doHTTPPOSTWithReply(const char *apn, const char *url, const char *postdata, size_t pdlen, char *buffer, size_t len);

bool doHTTPGET(const char *apn, const char *url, char *buffer, size_t len);

To do TCP

bool openTCP(const char *apn, const char *server, int port, bool transMode=false);
void closeTCP();
bool sendDataTCP(uint8_t *data, int data_len);
bool receiveLineTCP(const char **buffer, uint16_t timeout=4000);

To do FTP

bool openFTP(const char *apn, const char *server, const char *username, const char *password);
bool closeFTP();
bool openFTPfile(const char *fname, const char *path);
bool closeFTPfile();
bool sendFTPdata(uint8_t *data, size_t size);

To send an SMS

bool sendSMS(const char *telno, const char *text);

Examples

Do a http GET

This example reads the result from a GET request. The SIM900 is switched on, the http request is done, the SIM900 is switched off.

// Fill in your own APN here
#define APN "your.apn.com"

#include <GPRSbee.h>
static const uint8_t BEEDTR = 23;
static const uint8_t BEECTS = 8;

void setup()
{
  Serial1.begin(9600);
  gprsbee.init(Serial1, BEECTS, BEEDTR);

  // Make sure the GPRSbee is switched off to begin with
  gprsbee.off();

  char buffer[50];
  memset(buffer, 0, sizeof(buffer));
  retval = gprsbee.doHTTPGET(APN, "http://my.example.com/get_url",
      buffer, sizeof(buffer));
  if (retval) {
    print(F("Post result: "));
    print('"');
    print(buffer);
    println('"');
  }
}
void loop()
{
}

Do a http POST

This example reads the result from a POST request. The SIM900 is switched on, the http request is done, the SIM900 is switched off.

// Fill in your own APN here
#define APN "your.apn.com"

#include <GPRSbee.h>
static const uint8_t BEEDTR = 23;
static const uint8_t BEECTS = 8;

void setup()
{
  Serial1.begin(9600);
  gprsbee.init(Serial1, BEECTS, BEEDTR);

  // Make sure the GPRSbee is switched off to begin with
  gprsbee.off();

  const char testData[] = "testdata3 = hello world with newline\n";
  char buffer[50];
  memset(buffer, 0, sizeof(buffer));
  retval = gprsbee.doHTTPPOSTWithReply(APN, "http://my.example.com/post_url",
      testData, strlen(testData), buffer, sizeof(buffer));
  if (retval) {
    print(F("Post result: "));
    print('"');
    print(buffer);
    println('"');
  }
}
void loop()
{
}

Send an SMS

This is a brief example to show how you can send a text message (SMS)

// Fill in your own APN here
#define APN "your.apn.com"

#include <GPRSbee.h>
static const uint8_t BEEDTR = 23;
static const uint8_t BEECTS = 8;

void setup()
{
  Serial1.begin(9600);
  gprsbee.init(Serial1, BEECTS, BEEDTR);

  // Make sure the GPRSbee is switched off to begin with
  gprsbee.off();

  gprsbee.sendSMS("+31999999999", "Hello world");
}
void loop()
{
}