Hi, im using the sim808 to send coordinates to a http server.
Here i send a AT command using the sim808's library:
gsm.SimpleWriteln("AT+CGNSINF");
Here i use a function thats return char by char from the AT command's answer. I save each one in a char array:
char leu = gsm.jp();
int k = 0;
char teste[70];
while (leu != 0)
{
teste[k] = leu;
k++;
leu = gsm.jp();
}
And here i can have my string for send:
String web = "/pushingbox?devid=XXXXXXXXXXXXXX=" + x + "&y=" + y + '\0';
But the command "inet.httpGET" uses char, so i used the toCharArray with my string:
char wp[100];
teste.toCharArray(wp, sizeof(wp));
Until here its all ok! I tested this code just for add to String and convert to char array, its working!!!
But when a include the command:
inet.httpGET("api.pushingbox.com", 80, website, msg, 50);
A bug shows up... The first time char array is blank, the second works, the third not work and still like that, and sometimes it never returns anything in the string/char. I really don't know what can be, so please help me, thanks for now!!
The full code its here:
#include "SIM900.h"
#include <SoftwareSerial.h>
#include "inetGSM.h"
//#include "sms.h"
//#include "call.h"
//To change pins for Software Serial, use the two lines in GSM.cpp.
//GSM Shield for Arduino
//www.open-electronics.org
//this code is based on the example of Arduino Labs.
//Simple sketch to start a connection as client.
InetGSM inet;
//CallGSM call;
//SMSGSM sms;
char msg[50];
int numdata;
char inSerial[50];
int i = 0;
boolean started = false;
void setup()
{
//Serial connection.
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");
if (started) {
//GPRS attach, put in order APN, username and password.
//If no needed auth let them blank.
while (!inet.attachGPRS("zap.vivo.com", "vivo", "vivo"))
{
Serial.println("status=ERROR");
delay(2000);
}
delay(1000);
Serial.println("status=ATTACH");
//Read IP address.
gsm.SimpleWriteln("AT+CIFSR");
delay(5000);
//Read until serial buffer is empty.
gsm.WhileSimpleRead();
gsm.SimpleWriteln("AT+CGNSPWR=1");
delay(1500);
gsm.WhileSimpleRead();
delay(1000);
numdata = inet.httpGET("api.pushingbox.com", 80, "/pushingbox?devid=xxxxxxxxxxxxxxxx", msg, 50);
//Print the results.
Serial.println("\nNumber of data received:");
Serial.println(numdata);
Serial.println("\nData received:");
Serial.println(msg);
}
};
void loop()
{
String teste = xy();
char wp[100];
teste.toCharArray(wp, sizeof(wp));
Serial.println(wp);
delay(1000);
send_sheets(wp);
};
String xy()
{
gsm.SimpleWriteln("AT+CGNSINF");
delay(3000);
char leu = gsm.jp();
int k = 0;
char teste[70];
while (leu != 0)
{
teste[k] = leu;
k++;
leu = gsm.jp();
}
int flag = 1;
i = 0;
int virg = 0;
String x = "", y = "";
while (flag)
{
if (teste[i] == ',') //HERE IS FOR SEPARATE TWO PARAMETERS OF THE RETURN FROM AT COMMAND
virg++;
else if (virg == 3)
x += teste[i];
else if (virg == 4)
y += teste[i];
else if (virg == 5)
flag = 0;
i++;
}
String web = "/pushingbox?devid=xxxxxxxxxxxxxx=" + x + "&y=" + y + '\0';
return web;
}
void send_sheets(char website[])
{
inet.httpGET("api.pushingbox.com", 80, website, msg, 50);
}