sending AT commands via code

i have a LoNet GPS GPRS breakout board and there don't seem to be any code samples at all out there for this board. on the website for the board it says fona libraries but they dont seem to work.

it seems the board only responds to AT commands and i can't find anything to help me get this board up and running

has anyone any ideas
the site for the board is
Here

and the only code it gives is

// this sketch is used for testing LoNet with Arduino 

// Connect VIO to +5V
// Connect GND to Ground
// Connect RX (data into SIM808) to Digital 11
// Connect TX (data out from SIM808) to Digital 10

#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11); // RX, TX

void setup()  
{
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  mySerial.begin(9600);

}

void loop() // run over and over
{
  if (mySerial.available())
    Serial.write(mySerial.read());
    
  if (Serial.available())
  { 
    while(Serial.available())
    {
      mySerial.write(Serial.read());
    }
    mySerial.println();
  }
}

just a simple AT window for typing in AT commands which is no good for anything but testing the board

So just send AT commands via SoftwareSerial? See the examples in my signature for examples of how to do this.

Here is a function that takes a character string and a timeout. It displays the command being sent and any characters received during the timeout. You can use it to see if the response you are receiving is what you expect. It also returns a String containing the returned text so you can use the returned text in your code.

SoftwareSerial ATDevice(RXPin, TXPin);
String command(const char *toSend, unsigned long milliseconds) {
  String result;
  Serial.print("Sending: ");
  Serial.println(toSend);
  ATDevice.println(toSend);
  unsigned long startTime = millis();
  Serial.print("Received: ");
  while (millis() - startTime < milliseconds) {
    if (ATDevice.available()) {
      char c = ATDevice.read();
      Serial.write(c);
      result += c;  // append to the result string
    }
  }
Serial.println();  // new line after timeout.
return result;
}

thanks for that i was working on something in that area but it just wasn't returning anything

int8_t sendATcommand(char* ATcommand, char* expected_answer, unsigned int timeout){

    uint8_t x=0,  answer=0;
    char response[100];
    unsigned long previous;

    memset(response, '\0', 100);    // Initialice the string
    
    delay(100);
    
    while( Serial.available() > 0) Serial.read();    // Clean the input buffer
    
    if (ATcommand[0] != '\0')
    {
        Serial.println(ATcommand);    // Send the AT command 
    }


    x = 0;
    previous = millis();

    // this loop waits for the answer
    do{
        if(Serial.available() != 0){    // if there are data in the UART input buffer, reads it and checks for the asnwer
            response[x] = Serial.read();
            Serial.print('x');

            delay(500);
            x++;
            if (strstr(response, expected_answer) != NULL)    // check if the desired answer (OK) is in the response of the module
            {
                answer = 1;
            }
        }
    }while((answer == 0) && ((millis() - previous) < timeout));    // Waits for the asnwer with time out

    return answer;
}

johnwasser im not sure if im using ur sample correctly but i'm just getting the word received do i use it in the same way as i did with mine?

here is my full code. i have been trying samples from other libraries as this dam card doesn't have any or recommend any

here is my full code

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


#define PIN_WAKE  4
#define PIN_PWR   7
#define PIN_TX    10
#define PIN_RX    11
#define BAUDRATE  9600
SoftwareSerial    mySerial(PIN_TX, PIN_RX);


char latitude[6];
char longitude[6];


unsigned long lastMillis;




 


#define MESSAGE_LENGTH 60
char message[MESSAGE_LENGTH];
int messageIndex = 0;

char phone[14];
char datetime[12];


GPRS gprsTest(PIN_TX, PIN_RX, BAUDRATE);
Adafruit_GPS GPS(&mySerial);

void setup() {
  Serial.begin(9600);
  pinMode(PIN_WAKE, OUTPUT);
  pinMode(PIN_PWR, OUTPUT);


  while (!gprsTest.init()) {
    Serial.print("init error\r\n");
    delay(1000);
  }
  delay(3000);
  Serial.println("Init Success.");

  sendATcommand("AT" , 2000);
  sendATcommand("AT+ECHARGE=1" , 2000);
  sendATcommand("AT+CGPSPWR=1" , 2000);
  
  
Serial.print("SetUp Done Board Now Ready For Use");
  
}



void loop() {
      //is the time for a SYS Check? 
    if (millis() - lastMillis >= 1 * 60 * 1000UL)
    {
      lastMillis = millis(); //get ready for the next iteration
      sendATcommand("AT+CBC" , 2000);
      Serial.println();

     
    }

}




void ReadSMS() {
  messageIndex = gprsTest.isSMSunread();
  if (messageIndex > 0) { //At least, there is one UNREAD SMS
    gprsTest.readSMS(messageIndex, message, MESSAGE_LENGTH, phone, datetime);
    //In order not to full SIM Memory, is better to delete it
    gprsTest.deleteSMS(messageIndex);
    Serial.print("From number: ");
    Serial.println(phone);
    Serial.print("Datetime: ");
    Serial.println(datetime);
    Serial.print("Recieved Message: ");
    Serial.println(message);
  }
}

void connectWeb() {
  gprsTest.init();
  // attempt DHCP
  while (false == gprsTest.join(F("cmnet"))) {
    Serial.println("gprs join network error");
    delay(2000);
  }

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





void wake() {
  digitalWrite(PIN_WAKE, LOW);  // Reset the Display via D4
  delay(100);
  digitalWrite(PIN_WAKE, HIGH);  // unReset the Display via D4
  delay (5000); //let the display start up after the reset (This is important)


}

void sleep() {
  sendATcommand("AT+CSCLK=1" , 20000);

}





String sendATcommand(const char *toSend, unsigned long milliseconds) {
  String result;
  Serial.print("Sending: ");
  Serial.println(toSend);
  mySerial.println(toSend);
  unsigned long startTime = millis();
  Serial.print("Received: ");
  while (millis() - startTime < milliseconds) {
    if (mySerial.available()) {
      char c = mySerial.read();
      Serial.write(c);
      result += c;  // append to the result string
    }
  }
Serial.println();  // new line after timeout.
return result;
}

here is the serial output
Init Success.
Sending: AT
Received:
Sending: AT+ECHARGE=1
Received:
Sending: AT+CGPSPWR=1
Received:
SetUp Done Board Now Ready For Use

dannable:
So just send AT commands via SoftwareSerial? See the examples in my signature for examples of how to do this.

sorry guy if i try your examples on the AT serial input if i type AT i get x if i try ati i get xx

and the second sample gives nothing but a ready

mikewitney:
sorry guy if i try your examples on the AT serial input if i type AT i get x if i try ati i get xx

and the second sample gives nothing but a ready

Looks like Adafruit has support info:

PDF: here

no that's a FONA Board and the FONA Libraries don't work either
i already have a fona on another project

not this LoNET board don't seem to work with most libraries i have tried

can anyone help in telling me why i'm not getting any response showing on the serial monitor??

Some devices that use AT commands have to be switched to "command mode" before they interpret text as commands, process them, and send replies. Traditionally with Hayes modems this was done with a one-second delay, the three characters "+++" and a further one second delay. How your breakout board works will depend on the device it uses and how it has been configured.

EXACTLY what model of LoNet GPS GPRS breakout board do you have? Have you studied the datasheet for the device?

well there is no switches on it here is the link to the breakout

without the dam responses it really is useless as i can't get any info from it

http://www.seeedstudio.com/wiki/LoNet_808_-_Mini_GSM/GPRS_+_GPS_Breakout

Did you load the sketch on that page, connect the module as shown in the comments, and try some of the commands in the table?

Try different line endings in Serial Monitor. Is there one line ending choice that works and others that don't? Perhaps the println() is not using the right line ending. What line ending works?

yea i can talk to it ok

I've tried all the AT commands i can think i need to use

i dont understand what u mean by line ending i thought there was only one CR enter command press return

and println for code

can someone look over my code near the top

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


#define PIN_WAKE  4
#define PIN_PWR   7
#define PIN_TX    10
#define PIN_RX    11
#define BAUDRATE  9600
SoftwareSerial    mySerial(PIN_TX, PIN_RX);


char latitude[6];
char longitude[6];


unsigned long lastMillis;




 


#define MESSAGE_LENGTH 60
char message[MESSAGE_LENGTH];
int messageIndex = 0;

char phone[14];
char datetime[12];


GPRS gprsTest(PIN_TX, PIN_RX, BAUDRATE);
Adafruit_GPS GPS(&mySerial);

void setup() {
  Serial.begin(9600);
  pinMode(PIN_WAKE, OUTPUT);
  pinMode(PIN_PWR, OUTPUT);


  while (!gprsTest.init()) {
    Serial.print("init error\r\n");
    delay(1000);
  }
  delay(3000);
  Serial.println("Init Success.");

  sendATcommand("AT" , 2000);
  sendATcommand("AT+ECHARGE=1" , 2000);
  sendATcommand("AT+CGPSPWR=1" , 2000);
  
  
Serial.print("SetUp Done Board Now Ready For Use");
  
}

mikewitney:
i dont understand what u mean by line ending

At the bottom of the Serial Monitor window there are two pop-up menus. The one on the far right is the baud rate. The one just to the left of that is the Line Ending menu. The selections are:

  • No line ending
  • Newline
  • Carriage return
  • Both NL & CR

That is how you select what additional characters the Serial Monitor sends when you hit Return/Enter. That is what I mean by Line Ending.

i don't understand how that would work for trying to get a response from the code

when it works by typing the at commands i just have it on my normal settings

Both NL&CR
and it works fine like that by typing AT commands

but from code nothing.. its really confusing why its not working.. i got the board as its compact and fits nicely in to where i want it to go along side of my Arduino mini pro

but i have also tried it on my arduino Uno and still the same

BINGO got it

well its a start with a return from an AT command
a simple ATI but works with all i have tried so far

void sendATI(){
      char gprsBuffer[32];
    int count = 0;
    sim900_clean_buffer(gprsBuffer,32);
         {
        sim900_send_cmd("ATI\r\n");
        sim900_read_buffer(gprsBuffer,32,DEFAULT_TIMEOUT);
         {
          Serial.print(gprsBuffer);
            
        }

  
}}

Hello ,

I make Vehicle Accident Detection using SIM808 gsm/gprs module for school project. But, I am facing problem that when the accident condition, x,y,z axis are stop running and LCD and Serial Monitor too. When i test the sensors with arduino separately, sensors are okey. sim808 module is not return AT commands on serial monitor ,
How can i do that?