Envio de dados via GPRS

791 views
Skip to first unread message

Renan Freitas

unread,
Jan 25, 2012, 7:26:06 AM1/25/12
to ardu...@googlegroups.com
Salve Pessoal....

Caros amigos alguém poderia me dizer como eu faço para enviar dados via GPRS para uma pagina na internet??? Preciso enviar a seguinte instrução: (que foi capturado pelo modulo GPS, segue o código de como conseguir capturar e tratar os dados).

Latitude: 1451.6739
S
Longitude: 04050.9244
---------------


Código GPS:
#include <string.h>
#include <ctype.h>

int ledPin = 13;                  // LED test pin
int rxPin = 0;                    // RX PIN 
int txPin = 1;                    // TX TX
int byteGPS=-1;
char linea[300] = "";
char comandoGPR[7] = "$GPRMC";
int cont=0;
int bien=0;
int conta=0;

int indices[13];

void setup() {
  pinMode(ledPin, OUTPUT);       // Initialize LED pin
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);
  Serial.begin(9600);
  for (int i=0;i<300;i++){       // Initialize a buffer for received data
    linea[i]=' ';
  }   
}

void loop() {
  digitalWrite(ledPin, HIGH);
  byteGPS=Serial.read();         // Read a byte of the serial port
  if (byteGPS == -1) {           // See if the port is empty yet
    delay(100); 
  } 
  else {
    linea[conta]=byteGPS;        // If there is serial port data, it is put in the buffer
    conta++;                      
//   Serial.print(byteGPS, BYTE); 
    if (byteGPS==13){            // If the received byte is = to 13, end of transmission
      digitalWrite(ledPin, LOW); 
      cont=0;
      bien=0;
      for (int i=1;i<7;i++){     // Verifies if the received command starts with $GPR
        if (linea[i]==comandoGPR[i-1]){
          bien++;
        }
      }
      if(bien==6){               // If yes, continue and process the data
        for (int i=0;i<300;i++){
          if (linea[i]==','){    // check for the position of the  "," separator
            indices[cont]=i;
            cont++;
          }
          if (linea[i]=='*'){    // ... and the "*"
            indices[1]=i;
            cont++;
          }
        }
   //     Serial.println("");      // ... and write to the serial port
     //   Serial.println("");
       // Serial.println("---------------");
        for (int i=2;i<5;i++){
          switch(i){
          case 2 :
           Serial.print("Latitude: ");
            break;
          case 4 :
            Serial.print("Longitude: ");
            break;
                    }
         // Serial.print("AT+SSTRSEND=1, \"GET /insere_posicao.php?cod=123&lat=");
          //Serial.print(linea[2]);
          //Serial.print("&lon=");
         // Serial.print(linea[4]);
         // Serial.println(" HTTP/1.0\"");
          
          for (int j=indices[i];j<(indices[i+1]-1);j++){
           Serial.print(linea[j+1]); 
          }
          Serial.println("");
        }
        Serial.println("---------------");
      }
      conta=0;                    // Reset the buffer
      for (int i=0;i<300;i++){    //  
        linea[i]=' ';             
      }                 
    }
    }
}
CODIGO_GPS2.pde

Eduardo Gonçalves

unread,
Jan 25, 2012, 7:44:31 AM1/25/12
to ardu...@googlegroups.com
Renan,

não sei se já falou, mas qual é o modelo do shield GPRS que está utilizando?
Geralmente junto com o shield, com em algum site, existem exemplos dos comandos AT para comunicação via GPRS, envio de SMS, receber e fazer chamadas, etc etc.

Se o seu shield utilizar o SIM900, segue uma página bem interessante.


Abraço

2012/1/25 Renan Freitas <tec....@gmail.com>

Renan Freitas

unread,
Jan 25, 2012, 7:47:35 AM1/25/12
to ardu...@googlegroups.com
Olá amigo, estou utilizando o Shield  GPRS SIM900D, com o Arduino Duemilanove e o módulo GPS da SKYLAB SKM53.

Abraços
--
Att:

T.I - Tecnologia da Informação
Renan Freitas Souza
(77) 8807-9505



"Antes de imprimir pense em sua responsabilidade com o Meio Ambiente"
"Cuidar do meio ambiente também é Tecnologia"

Eduardo Gonçalves

unread,
Jan 25, 2012, 8:25:55 AM1/25/12
to ardu...@googlegroups.com

Viu essa parte na página que te enviei?

Acho que é mais ou menos isso que você está querendo fazer! Nâo se esqueça de adicionar ao seu projeto

a biblioteca do #include "SIM900.h" e a "inetGSM.h" que já tem alguma coisa pronta!


#include "inetGSM.h"


int InetGSM::httpGET(const char* server, int port, const char* path, char* result, int resultlength)
{
  int length_write;

  
  //Status = ATTACHED.
  if(gsm.getStatus()!=GSM::ATTACHED)
    return 0;
  
    
  if(!gsm.connectTCP(server, port))
    return 0;
 
  gsm.write((const uint8_t*)"GET ", 4);
  gsm.write((const uint8_t*)path, strlen(path));
  gsm.write((const uint8_t*)" HTTP/1.0\nHost: ", 16);
  gsm.write((const uint8_t*)server, strlen(server));
  gsm.write((const uint8_t*)"\n\n",2);

  
  int res= gsm.read(result, resultlength);

  gsm.disconnectTCP();
  
  return res;
}

int InetGSM::httpPOST(const char* server, int port, const char* path, const char* parameters, char* result, int resultlength)
{
  char itoaBuffer[8];
  int num_char;
  
  if (!gsm.connectTCP(server, port))
    return 0;

  
  strcpy(_buffer,"POST ");
  strcat(_buffer,path);
  strcat(_buffer," HTTP/1.0\nHost: ");
  strcat(_buffer,server);
  // strcat(_buffer,"\n\rUser-Agent: Mozilla/4.0\n\rContent-Length: ");
  strcat(_buffer,"\nContent-Length: ");
  itoa(strlen(parameters),itoaBuffer,10);
  strcat(_buffer,itoaBuffer);
  strcat(_buffer,"\n\n");
  strcat(_buffer,parameters);
  strcat(_buffer,"\n\n");
  
  
  
  gsm.write((const uint8_t*)_buffer, strlen(_buffer));


// int res= gsm.read(result, resultlength);

  gsm.disconnectTCP();
  //return res;
   return 1;
}

int InetGSM::tweet(const char* token, const char* msg)
{
  // gsm.httpPOST("arduino-tweet.appspot.com",80,"/update", "token=15514242-eWYAlMwjRQfrhnZxQiOfDXUpaYwjbSvMl1Nm5Qyg&status=Spam", buffer, 200);
  char shortbuf[200];
  strcpy(shortbuf,"token=");
  strcat(shortbuf,token);
  strcat(shortbuf,"&status=");
  strcat(shortbuf, msg);
  httpPOST("arduino-tweet.appspot.com",80,"/update",shortbuf, shortbuf, BUFFERSIZE);
}

int InetGSM::openmail(char* server, char* loginbase64, char* passbase64, char* from, char* to, char* subj)
{
if (!gsm.connectTCP(server, 25))
     return 0;
    
    delay(1000);
    gsm.read(_buffer, BUFFERSIZE);
    gsm.write("HELO\n");
    delay(500);
    gsm.read(_buffer, BUFFERSIZE);
    gsm.write("AUTH LOGIN\n");
    delay(500);
    gsm.read(_buffer, BUFFERSIZE);
    gsm.write(loginbase64);gsm.write("\n");
    delay(500);
    gsm.read(_buffer, BUFFERSIZE);
    gsm.write(passbase64);gsm.write("\n");
    delay(500);
    gsm.read(_buffer, BUFFERSIZE);
    gsm.write("MAIL FROM: ");gsm.write(from);gsm.write("\n");
    delay(500);
    gsm.read(_buffer, BUFFERSIZE);
    gsm.write("RCPT TO: ");gsm.write(to);gsm.write("\n");
    delay(500);
    gsm.read(_buffer, BUFFERSIZE);
    gsm.write("Subject: ");gsm.write(subj);gsm.write("\n\n");
    return 1;
}
int InetGSM::closemail()
{
gsm.write("\n.\n");
gsm.disconnectTCP();
return 1;
}


GPRS Client

1 #include "SIM900.h"
2 #include <NewSoftSerial.h>
3 #include "inetGSM.h"
4  
5 //GSM Shield for Arduino
7 //this code is based on the example of Arduino Labs.
8  
9 //Simple sketch to start a connection as client.
10  
11 InetGSM inet;
12 char msg[100];
13 int numdata;
14 char inSerial[30];
15 int i=0;
16  
17 void setup()
18 {
19   //Serial connection.
20   Serial.begin(9600);
21   Serial.println("GSM Shield testing.");
22   //Start configuration of shield with baudrate.
23   //For http uses is raccomanded to use 4800 or slower.
24   if (gsm.begin(4800))
25     Serial.println("\nstatus=READY");
26   else Serial.println("\nstatus=IDLE");
27  
28   //GPRS attach, put in order APN, username and password.
29   //If no needed auth let them blank.
30   if (gsm.attachGPRS("internet.wind", "", ""))
31     Serial.println("status=ATTACHED");
32   else Serial.println("status=ERROR");
33   delay(5000);
34  
35   //TCP Client GET, send a GET request to the server and
36   //save the reply.
37   numdata=inet.httpGET("www.google.com", 80, "/", msg, 100);
38   //Print the results.
39   Serial.println("\nNumber of data received:");
40   Serial.println(numdata);
41   Serial.println("Data received:");
42   Serial.println(msg);
43  
44   //Tweet
45   //inet.tweet("*********************key************", "An Arduino at #cpes15");
46  
47 };
48  
49 void loop()
50 {
51   //Read for new byte on serial hardware,
52   //and write them on NewSoftSerial.
53   serialhwread();
54   //Read for new byte on NewSoftSerial.
55   serialswread();
56 };
57  
58 void serialhwread(){
59   i=0;
60   if (Serial.available() > 0){
61     while (Serial.available() > 0) {
62       inSerial[i]=(Serial.read());
63       delay(10);
64       i++;
65     }
66  
67     inSerial[i]='\0';
68     if(!strcmp(inSerial,"/END")){
69       Serial.println("_");
70       inSerial[0]=0x1a;
71       inSerial[1]='\0';
72       gsm.SimpleWrite(inSerial);
73     }
74     //Send a saved AT command using serial port.
75     if(!strcmp(inSerial,"TEST")){
76       Serial.println("SIGNAL QUALITY");
77       gsm.SimpleWrite("AT+CSQ");
78     }
79     //Read last message saved.
80     if(!strcmp(inSerial,"MSG")){
81       Serial.println(msg);
82     }
83  
84     else{
85       Serial.println(inSerial);
86       gsm.SimpleWrite(inSerial);
87     }   
88  
89     inSerial[0]='\0';
90   }
91 }
92  
93 void serialswread(){
94   gsm.SimpleRead();
95 }
Reply all
Reply to author
Forward
0 new messages