GPRS_ArduinoUno_pachube

Hi,

I am testing out uploading data to pachube using the exmaple on wiki and here is my code snippet.

[code]#include <SoftwareSerial.h>
SoftwareSerial GPRS_Serial(7, 8);

void setup()
{
GPRS_Serial.begin(19200); //GPRS Shield baud rate
Serial.begin(19200);

setup_start:

Serial.println(“Turn on GPRS Modem and wait for 1 minute.”);
Serial.println(“and then press a key”);
Serial.println(“Press c for power on configuration”);
Serial.println(“press any other key for uploading”);
Serial.flush();
while(Serial.available() == 0);
if(Serial.read()==‘c’)
{
Serial.println(“Executing AT Commands for one time power on configuration”);
GPRS_Serial.flush();

GPRS_Serial.println("ATE1"); //Command echo off
Serial.println("ATE0   Sent");

if(GPRS_Serial_wait_for_bytes(4,10) == 0)
{  
  Serial.println("Timeout");
  goto setup_start;
}
else
{
  Serial.print("Received:");
  while(GPRS_Serial.available()!=0)
  {
    Serial.print(GPRS_Serial.read());
    Serial.print("\n");
  }
}

GPRS_Serial.println("AT+CIPMUX=0"); //We only want a single IP Connection at a time.
Serial.println("AT+CIPMUX=0   Sent");
if(GPRS_Serial_wait_for_bytes(4,10) == 0)
{  
  Serial.println("Timeout");
  goto setup_start;
}
else
{
  Serial.print("Received:");
  while(GPRS_Serial.available()!=0)
  {
    Serial.print((unsigned char)GPRS_Serial.read());
    Serial.print("\n");
  }
}

GPRS_Serial.println("AT+CIPMODE=0"); //Selecting "Normal Mode" and NOT "Transparent Mode" as the TCP/IP Application Mode
Serial.println("AT+CIPMODE=0    Sent!");
if(GPRS_Serial_wait_for_bytes(4,10) == 0)
{  
  Serial.println("Timeout");
  goto setup_start;
}
else
{
  Serial.print("Received:");
  while(GPRS_Serial.available()!=0)
  {
    Serial.print((unsigned char)GPRS_Serial.read());
    Serial.print("\n");
  }
}

GPRS_Serial.println("AT+CGDCONT=1,\"IP\",\"<myAPN>\""); //Defining the Packet Data

//Protocol Context - i.e. the Protocol Type, Access Point Name and IP Address
Serial.println(“AT+CGDCONT=1,“IP”,“myAPN”,”",0,0 Sent!");
if(GPRS_Serial_wait_for_bytes(4,10) == 0)
{
Serial.println(“Timeout”);
goto setup_start;
}
else
{
Serial.print(“Received:”);
while(GPRS_Serial.available()!=0)
{
Serial.print((unsigned char)GPRS_Serial.read());
Serial.print("\n");
}
}

GPRS_Serial.println("AT+CSTT=\"<myAPN>\""); //Start Task and set Access Point Name (and username and password if any)
Serial.println("AT+CSTT=\"<myAPN>\"   Sent!");
if(GPRS_Serial_wait_for_bytes(4,10) == 0)
{  
  Serial.println("Timeout");
  goto setup_start;
}
else
{
  Serial.print("Received:");
  while(GPRS_Serial.available()!=0)
  {
    Serial.print((unsigned char)GPRS_Serial.read());
    Serial.print("\n");
  }
}

GPRS_Serial.println("AT+CIPSHUT"); //Close any GPRS Connection if open
Serial.println("AT+CIPSHUT  Sent!");
if(GPRS_Serial_wait_for_bytes(7,10) == 0)
{  
  Serial.println("Timeout");
  goto setup_start;
}
else
{
  Serial.print("Received:");
  while(GPRS_Serial.available()!=0)
  {
    Serial.print((unsigned char)GPRS_Serial.read());
    Serial.print("\n");
  }
}

}

//////Actually a loop but for testing///////////////////
GPRS_Serial.println(“AT+CIPSTART=“TCP”,“api.pachube.com”,“80"”); //Open a connection to Pachube.com
Serial.println(“AT+CIPSTART=“TCP”,“api.pachube.com”,“80” Sent!”);
if(GPRS_Serial_wait_for_bytes(12,255) == 0)
{
Serial.println(“Timeout”);
// goto loop_start;
}
else
{
Serial.print(“Received:”);
while(GPRS_Serial.available()!=0)
{
Serial.print((unsigned char)GPRS_Serial.read());
Serial.print(”\n");
}
}

GPRS_Serial.flush();
GPRS_Serial.println(“AT+CIPSEND”); //Start data through TCP connection
Serial.println(“AT+CIPSEND Sent!”);
if(GPRS_Serial_wait_for_bytes(1,100) == 0)
{
Serial.println(“Timeout”);
// goto loop_start;
}
else
{
Serial.print(“Received:”);
while(GPRS_Serial.available()!=0)
{
Serial.print((unsigned char)GPRS_Serial.read());
Serial.print("\n");
}
}

GPRS_Serial.flush();

//Emulate HTTP and use PUT command to upload temperature datapoint using Comma Seperate Value Method
GPRS_Serial.print(“PUT /v2/feeds/49954.csv HTTP/1.1\r\n”);
Serial.println(“PUT /v2/feeds/49954.csv HTTP/1.1 Sent!”);
delay(300);

GPRS_Serial.print(“Host: api.pachube.com\r\n”);
Serial.println(“Host: api.pachube.com Sent!”);
delay(300);

GPRS_Serial.print(“X-PachubeApiKey: wEOp3yCz6QRaylwvPCOow_iL-rKSAKxZV2JhWUVMTzN6MD0g\r\n”); //REPLACE THIS KEY WITH YOUR OWN PACHUBE API KEY
Serial.println(“X-PachubeApiKey: wEOp3yCz6QRaylwvPCOow_iL-rKSAKxZV2JhWUVMTzN6MD0g Sent!”); //REPLACE THIS KEY WITH YOUR OWN PACHUBE API KEY
delay(300);

GPRS_Serial.print(“Content-Length: 12\r\n”);
Serial.print(“Content-Length: 12 Sent!”);
delay(300);

GPRS_Serial.print(“Content-Type: text/csv\r\n”);
Serial.print(“Content-Type: text Sent!”);
delay(300);

GPRS_Serial.print(“Connection: close\r\n\r\n”);
Serial.print(“Connection: close Sent!”);
delay(300);
GPRS_Serial.print(“TMP102,”); //This is my stream name at pachube
GPRS_Serial.print(“98345”); // This is my data
delay(300);
GPRS_Serial.print("\r\n");
delay(300);
GPRS_Serial.print("\r\n");
delay(300);

GPRS_Serial.write((byte)26);
delay(3000); //Send End Of Line Character to send all the data and close connection
#if 1
if(GPRS_Serial_wait_for_bytes(20,255) == 0)
{
Serial.println(“Timeout”);

}
else
{
Serial.print(“Received:”);
while(GPRS_Serial.available()!=0)
{
Serial.print((unsigned char)GPRS_Serial.read());
Serial.print("\n");
}
}

#endif

#if 1
GPRS_Serial.flush();
GPRS_Serial.println(“AT+CIPSHUT”); //Close the GPRS Connection
Serial.println(“AT+CIPSHUT Sent!”);
if(GPRS_Serial_wait_for_bytes(4,100) == 0)
{
Serial.println(“Timeout”);

}
else
{
Serial.print(“Received:”);
while(GPRS_Serial.available()!=0)
{
Serial.print((unsigned char)GPRS_Serial.read());
Serial.print("\n");
}
}
#endif
//////Actually a loop but for testing///////////////////
}

void loop()
{

}

char GPRS_Serial_wait_for_bytes(char no_of_bytes, int timeout)
{
while(GPRS_Serial.available() < no_of_bytes)
{
delay(200);
timeout-=1;
if(timeout == 0)
{
return 0;
}
}
return 1;
}[/code]

my terminal out is :

Turn on GPRS Modem and wait for 1 minute. and then press a key Press c for power on configuration press any other key for uploading Executing AT Commands for one time power on configuration ATE0 Sent Received:658469491310131079751310AT+CIPMUX=0 Sent Received:65844367738077858861481310131079751310AT+CIPMODE=0 Sent! Received:6584436773807779686961481310131079751310AT+CGDCONT=1,"IP","<myAPN>",,0,0 Sent! Received:658443677168677978846149443473803444348610511410310511073110116101114110101116341310131079751310AT+CSTT="<myAPN>" Sent! Received:6584436783848461348610511410310511073110116101114110101116341310131079751310AT+CIPSHUT Sent! Received:6584436773808372858413101310837285843279751310AT+CIPSTART="TCP","api.pachube.com","80" Sent! Received:65844367738083846582846134846780344434971121054611297991041179810146991111093444345648341310131079751310AT+CIPSEND Sent! Received:658443677380836978681310131069828279821310PUT /v2/feeds/49954.csv HTTP/1.1 Sent! Host: api.pachube.com Sent! X-PachubeApiKey: wEOp3yCz6QRaylwvPCOow_iL-rKSAKxZV2JhWUVMTzN6MD0g Sent! Content-Length: 12 Sent!Content-Type: text Sent!Connection: close Sent!Received:808584324711850471021011011001154752575753524699115118327284848047494649131072111115116583297112105461129799104117981014699111109131088458097991041179810165112105751011215832119697911251121671225481829712110811911880677911111995105764511475836575120908650741048785867784122785477684810313106711111011610111011645761011101031161045832495013106711111011610111011645841211121015832116101120116479911511813106711111011010199116105111110583299108111115101131013108477804948504457565152531310131026AT+CIPSHUT Sent! Received:658443677380837285841310

I think all commands are being returned OK from the ascii code , but i cant find my data “98345” on pachube.com/feeds/49954

Anyhelp is greatly appreciated…

OK i figured out that this issue was with my stream on pachube. I had to recreate the keys and it works now