[SOLVED] Issues with the Arduino GPRS Shield

Hi,

I was trying the new GPRS library and it works but I am having an error when I want to post to Ubidots.

Please find attached the code and the error from serial monitor.

I would like to show this application next week in a workshop in Egypt.

Best,
Rodrigo

Code:

/* Basic sketch for GPRS shield sim900 
This is a basic example on how to post a value to Ubidots, with just the function "save_value".

 Pins' connection


Arduino       WiFly
  7    <---->    TX
  8    <---->    RX



created 20 Aug. 2014
 by Mateo Velez - Metavix

 This example code is in the public domain.

*/

//--------------------------------------------------------------
//------------------------------Libraries-----------------------
//--------------------------------------------------------------
#include <SoftwareSerial.h>
#include <String.h>
SoftwareSerial mySerial(7, 8);               //your pins to serial communication
int valor;
//-------------------------------------------------------------
//---------------------Ubidots Configuration-------------------
//-------------------------------------------------------------
String token = "YRWsXoUOptheqaDFNT58o65hyHe4m";      //your token to post a value
String idvariable = "5408256b76254210e3acafbf";      //ID of your variable
void setup()
{

  mySerial.begin(19200);                                                            //the GPRS baud rate
  Serial.begin(19200);                                                              //the serial communication baud rate
   Serial.println("Starting");
  delay(2000);
}

void loop()
{
    int value = analogRead(A0);                                                     //read pin A0 of the Arduino
    Serial.println("Sending to Ubidots Value="+ value);
    save_value(String(value));                                                      //call the save_value function
    if (mySerial.available())
    Serial.write(mySerial.read());
}
//this function is to send the sensor data to Ubidots, you can see the new value in Ubidots after running this function

void save_value(String value)
{
  int num;
  String le;
  String var;
  var="{\"value\":"+ value + "}";
  num=var.length();
  le=String(num);
  for(int i = 0;i<7;i++)
  {
    mySerial.println("AT+CGATT?");                                                   //this is better made repeatedly because it is unstable
    delay(2000);
    ShowSerialData();
  }
  mySerial.println("AT+CSTT=\"web.vmc.net.co\"");                                    //start task and set the APN
  delay(1000);
  ShowSerialData();
  mySerial.println("AT+CIICR");                                                      //bring up wireless connection
  delay(3000);
  ShowSerialData();
  mySerial.println("AT+CIFSR");                                                      //get local IP adress
  delay(2000);
  ShowSerialData();
  mySerial.println("AT+CIPSPRT=0");
  delay(3000);
  ShowSerialData();
  mySerial.println("AT+CIPSTART=\"tcp\",\"things.ubidots.com\",\"80\"");             //start up connection
  delay(3000);
  ShowSerialData();
  mySerial.println("AT+CIPSEND");                                                    //begin sendiing data to the remote server
  delay(3000);
  ShowSerialData();
  mySerial.print("POST /api/v1.6/variables/"+idvariable);
  delay(100);
  ShowSerialData();
  mySerial.println("/values HTTP/1.1");
  delay(100);
  ShowSerialData();
  mySerial.println("Content-Type: application/json");
  delay(100);
  ShowSerialData();
  mySerial.println("Content-Length: "+le);
  delay(100);
  ShowSerialData();
  mySerial.print("X-Auth-Token: ");
  delay(100);
  ShowSerialData();
  mySerial.println(token);
  delay(100);
  ShowSerialData();
  mySerial.println("Host: things.ubidots.com");
  delay(100);
  ShowSerialData();
  mySerial.println();
  delay(100);
  ShowSerialData();
  mySerial.println(var);
  delay(100);
  ShowSerialData();
  mySerial.println();
  delay(100);
  ShowSerialData();
  mySerial.println((char)26);
  delay(7000);
  mySerial.println();
  ShowSerialData();
  mySerial.println("AT+CIPCLOSE");                                                //close communication
  delay(1000);
  ShowSerialData();
}

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

The Serial Monitor output:

Starting
Sending to Ubidots Value=250
AT+CGATT?

+CGATT: 1

OK
AT+CGATT?

+CGATT: 1

OK
AT+CGATT?

+CGATT: 1

OK
AT+CGATT?

+CGATT: 1

OK
AT+CGATT?

+CGATT: 1

OK
AT+CGATT?

+CGATT: 1

OK
AT+CGATT?

+CGATT: 1

OK
AT+CSTT="web.vmc.net.co"

ERROR
AT+CIICR

ERROR
AT+CIFSR

ERROR
AT+CIPSPRT=0

OK
AT+CIPSTART="tcp","things.ubidots.com","80"

ERROR
AT+CIPSEND

ERROR
POST /api/v1.6/variables/5408256b76254210e3acafbf/values HTTP/1.1
Content-Type: application/json

SIM900 R11.0

ERROR
Content-Length: 13
X-Auth-Token: YRWsXoUOptheqaDF2T58o65hyHe4m
Host: things.ubidots.com

{"value":250}



AT+CIPCLOSE

ERROR

Hi Rodrigo,

I was looking at your code and it seems you still have the APN for the original example:

AT+CSTT=“web.vmc.net.co

You should put here the information for the Mobile network of the SIM you are using. The command reference fro the SIM900 is as follows:

AT+CSTT=“apn”,“user”,“pass”

Some networks require a user and password, some other require them to be left in blank, like

AT+CSTT=“internet.claro.com”,“”,“”

Let us know how this works for you.

Best,

Agustín

Hi Agustin, Thank you.
I changed apn for Wind: internet.wind but still not error.

> Starting
> Sending to Ubidots Value=282

> Call Ready
> AT+CGATT?

> +CGATT: 0

> OK
> AT+CGATT?

> +CGATT: 0

> OK
> AT+CGATT?

> +CGATT: 0

> OK
> AT+CGATT?

> +CGATT: 0

> OK
> AT+CGATT?

> +CGATT: 0

> OK
> AT+CGATT?

> +CGATT: 0

> OK
> AT+CGATT?

> +CGATT: 1

> OK
> AT+CSTT="internet.wind"

> OK
> AT+CIICR

> OK
> AT+CIFSR

> 10.56.245.239
> AT+CIPSPRT=0

> OK
> AT+CIPSTART="tcp","things.ubidots.com","80"

> OK
> AT+CIPSEND

> ERROR
> POST /api/v1.6/variables/5408256b76254210e3acafbf/values HTTP/1.1
> Content-Type: application/json

> SIM900 R11.0

> ERROR
> Content-Length: 13
> X-Auth-Token: YRWsXoUOptheqaDFN2T58o65hyHe4m
> Host: things.ubidots.com

> {"value":282}


> STATE: IP STATUS

> CONNECT FAIL

> AT+CIPCLOSE

> ERROR

Hi Agustin,
after sending previous mail it started to work!! I post data to Ubidots with GPRS cool!

Sometimes it fails. Do you know why?

Best,
Rodri

Hi Rodrigo,

Glad to hear it worked! About the errors: the program does AT+CIPSEND and sometimes the delay is not enough to open the port successfully, hence giving error when we try the POST command. Try tweaking that delay, specially when you are in Egypt, because every mobile network behaves differently.

Best of luck!

Great! I will delay longer! Thank you very much