Hi all,
Am a newbie working with arduino for the first time.I have been experiencing problems sending HTTP post request via at commands to sm5100b cellular sheild.I willl be posting my code below.i feel its a problem with while sending the request with AT + SDATATSEND.
Here s the code..
#include <PString.h>
/*
SparkFun Cellular Shield - Pass-Through Sample Sketch
SparkFun Electronics
Written by Ryan Owens
CC by v3.0
3/8/10
This version - example 26.1a - for Arduino Mega
Run jumpers from GSM shield pin 2 to Mega 19, and shield 3 to Mega 18
Ensure that there is NOT a connection from shield pins RX and TX to anywhere.
*/
#include <string.h> //Used for string manipulations
//#include<PString.h>
char incoming_char=0; //Will hold the incoming character from the Serial Port.
char buffer[1500];
PString myString(buffer,sizeof(buffer));
void setup()
{
//Initialize serial ports for communication.
Serial.begin(9600); // for terminal communication
Serial1.begin(9600); // for GSM module communication
Serial.println("Starting SM5100B Communication...");
}
void loop() {
delay(40000);
Serial.println("Reg!!");
//
Serial1.print("AT+CGATT?\r");
delay(200);
while(Serial1.available() == 0);
//delay(1000);
while(Serial1.available() != 0)
{
incoming_char=Serial1.read(); //Get the character from the cellular serial port.
Serial.print(incoming_char); //Print the incoming character to the terminal.
}
Serial.println("1");
//2
Serial1.print("AT+CGDCONT=1,"IP","www"\r");
delay(200);
while(Serial1.available() == 0);
//delay(1000);
while(Serial1.available() != 0)
{
incoming_char=Serial1.read(); //Get the character from the cellular serial port.
Serial.print(incoming_char); //Print the incoming character to the terminal.
}
Serial.println("2");
//3
Serial1.print("AT+CGPCO=0,"","", 1\r");
delay(200);
while(Serial1.available() == 0);
//delay(1000);
while(Serial1.available() != 0)
{
incoming_char=Serial1.read(); //Get the character from the cellular serial port.
Serial.print(incoming_char); //Print the incoming character to the terminal.
}
Serial.println("3");
//4
Serial1.print("AT+CGACT=1,1\r");
delay(200);
while(Serial1.available() == 0);
// delay(1000);
while(Serial1.available() != 0)
{
incoming_char=Serial1.read(); //Get the character from the cellular serial port.
Serial.print(incoming_char); //Print the incoming character to the terminal.
}
Serial.println("4");
//5
Serial1.print("AT+SDATACONF=1,"TCP","saga143.appspot.com",80\r");
//Serial1.print("AT+SDATACONF=1,"TCP","192.168.9.16",9999\r");
delay(2000);
while(Serial1.available() == 0);
//delay(1000);
while(Serial1.available() != 0)
{
incoming_char=Serial1.read(); //Get the character from the cellular serial port.
Serial.print(incoming_char); //Print the incoming character to the terminal.
}
Serial.println("5");
//6
Serial1.print("AT+SDATASTART=1,1\r");
delay(5000);
while(Serial1.available() == 0);
//delay(1000);
while(Serial1.available() != 0)
{
incoming_char=Serial1.read(); //Get the character from the cellular serial port.
Serial.print(incoming_char); //Print the incoming character to the terminal.
}
Serial.println("6");
delay(5000);
//7
Serial1.print("AT+SDATASTATUS=1\r");
delay(200);
while(Serial1.available() == 0);
//delay(1000);
while(Serial1.available() != 0)
{
incoming_char=Serial1.read(); //Get the character from the cellular serial port.
Serial.print(incoming_char); //Print the incoming character to the terminal.
}
Serial.println("7");
//8
Serial1.print("AT+SDATATSEND=1,50");
Serial1.print(13,BYTE);
delay(100);
while(Serial1.available() == 0);
//delay(1000);
while(Serial1.available() != 0)
{
incoming_char=Serial1.read(); //Get the character from the cellular serial port.
Serial.print(incoming_char); //Print the incoming character to the terminal.
}
Serial1.print("POST /irss HTTP/1.1");
Serial1.print(13,BYTE);
Serial1.print(10,BYTE);
Serial1.print("Host: saga143.appspot.com");
Serial1.print(13,BYTE);
Serial1.print(10,BYTE);
Serial1.print("Content-Type: image/jpeg");
Serial1.print(13,BYTE);
Serial1.print(10,BYTE);
Serial1.print("Content-Length: 5");
Serial1.print(13,BYTE);
Serial1.print(10,BYTE);
Serial1.print(13,BYTE);
Serial1.print(10,BYTE);
Serial1.print("/9j/4");
Serial1.print(13,BYTE);
Serial1.print(26,BYTE);
//Serial1.write("");
// Serial1.write(26);
//delay(500);
while(Serial1.available() == 0);
//delay(1000);
while(Serial1.available() != 0)
{
incoming_char=Serial1.read(); //Get the character from the cellular serial port.
Serial.print(incoming_char); //Print the incoming character to the terminal.
}
Serial.println("8");
Serial1.println("AT+SDATASTATUS=1");
delay(200);
while(Serial1.available() == 0);
//delay(1000);
while(Serial1.available() != 0)
{
incoming_char=Serial1.read(); //Get the character from the cellular serial port.
Serial.print(incoming_char); //Print the incoming character to the terminal.
}
//9
Serial1.print("AT+SDATASTATUS=0\r");
delay(200);
while(Serial1.available() != 0)
{
incoming_char=Serial1.read(); //Get the character from the cellular serial port.
Serial.print("10"+incoming_char); //Print the incoming character to the terminal.
}
//10
Serial1.print("AT+SDATASTART=1,0\r");
delay(200);
while(Serial1.available() == 0);
//delay(1000);
while(Serial1.available() != 0)
{
incoming_char=Serial1.read(); //Get the character from the cellular serial port.
Serial.print(incoming_char); //Print the incoming character to the terminal.
}
Serial.println("9");
while(1);
}
I am able to connect to the server get the pdp context etc..but i get CME error 4 or STCPC:1(socket disconnected) for the AT+SDATATSEND commands.Any sample code that does a http post request would be greatly appreciated.Thank you.Hoping for a quick response. ![]()