[phpBB Debug] PHP Warning: in file /mnt/forum-shared/ext/sitesplat/BBCore/event/listener.php on line 70: in_array() expects parameter 2 to be array, boolean given
Posting data using Arduino and SIM900 (GPRS/GSM) - SparkFun Electronics

SparkFun Forums 

Where electronics enthusiasts find answers.

Everything pertaining to the data.sparkfun.com service, the phant project which powers it, and user projects which talk to the service.
By wengan
#189154
Hi!

I am using Arduino and a SIM900 shield, in order to have a weather station in a place without wifi connection but with GPRS/GSM

I think I having problems on how a POST or GET request works using AT Commands.

I am also using the phant library, so am I using it right?
Code: Select all
#include <SoftwareSerial.h>
SoftwareSerial mySerial(7, 8); // se utilizan estos pines ya que el shield sim900 requiere los pines 7 y 8 para la comunicacion
// A la playa sim900 se le entregan solo comandos AT

#include <Arduino.h>


/////////////////////////
//                     //
//     PHANT STUFF     //
//                     //
/////////////////////////
#include <Phant.h>

//Phan phant("Ip servidor o dominio", "Clave publica", "Clave privada");
//Phant phant("data.sparkfun.com", "VGb2Y1jD4VIxjX3x196z", "9YBaDk6yeMtNErDNq4YM");
Phant phant("data.sparkfun.com","PUBLIC_KEY","PRIVATE_KEY");

void setup()
{
  mySerial.begin(19200); // baudrate de la comunicacion serial Arduino-SIM900, debe ser 19200   
  Serial.begin(9600);    // Comunicacion serial PC-Arduino, aqui se elige cualquier cosa
  delay(500);
}

void loop()
{

  //Creando lo que se va a postear
  phant.add("humedad",0);
  phant.add("temperatura",0);
  //after start up the program, you can using terminal to connect the serial of gprs shield,
  //if you input 't' in the terminal, the program will execute SendTextMessage(), it will show how to send a sms message,
  //if input 'd' in the terminal, it will execute DialVoiceCall(), etc.
  if (Serial.available())
    switch(Serial.read())
    {
    case 'H':
      Send2Spark();
      // Probar phant 
    } 
  if (mySerial.available())
    Serial.write(mySerial.read());
}

void Send2Spark()
{
  Serial.println("--- Send2Spark ---");
  // Apaga el GPRS y pone la placa en el status IPINIT: 
  mySerial.println("AT+CIPSHUT");
  delay(100);
  ShowSerialData();
  //Check attach status
  mySerial.println("AT+CGATT=1");// Hace la conexion GPRS
  delay(2000);
  ShowSerialData(); 
  mySerial.println("AT+CSTT=\"internet.simple\",\"\",\"\"");//start task and setting the APN,
  delay(1000);
  ShowSerialData();
  mySerial.println("AT+CIICR");//bring up wireless connection
  delay(5000);
  ShowSerialData(); 
  mySerial.println("AT+CIFSR");//get local IP adress
  delay(2000);
  ShowSerialData();
  mySerial.println("AT+CIPSTART=\"tcp\",\"data.sparkfun.com\",\"80\"");//start up the connection
  delay(5000);
  ShowSerialData();
  mySerial.println("AT+CIPSEND=?");//start up the connection
  delay(2000);
  ShowSerialData();
  mySerial.println("AT+CIPSEND");//start up the connection
  delay(2000);
  ShowSerialData();

  // haciendo la request POST
  mySerial.print(phant.post());
  mySerial.write(26);
  delay(3000);
  ShowSerialData();

  // mySerial.print("POST /input/dZ5qYNvA27fAOrZXv50V.txt HTTP/1.1\x1A");
  // ShowSerialData();
  // mySerial.println("Host: data.sparkfun.com");
  // ShowSerialData();
  // mySerial.println("Phant-Private-Key: eEvVD9Rl7mh4N2REd8yY");
  // ShowSerialData();
  // mySerial.println("Connection: close");
  // ShowSerialData();
  // mySerial.println("Content-Type: application/x-www-form-urlencoded");
  // ShowSerialData();
  // mySerial.println("Content-Length: 26");
  // ShowSerialData();
  // mySerial.println("humedad=post&temperatura=0");
  // ShowSerialData();
  delay(4000);
  ShowSerialData();
  mySerial.println("AT+CIPCLOSE");//close the connection
  delay(100);
  ShowSerialData();

  // Las conexiones en ese orden respetan la sucesion de estados planteados en la SIM900
  //  IPINITIAL IPSTART IPCONFIG IPGPRSA.

}
void ShowSerialData()
{
  while(mySerial.available()!=0)
    Serial.write(mySerial.read());
}