[solved]help needed to sending data with sim900 ( instead of w5100 )

Hi Profs,
I need some help how to create a sketch to send data to cloud system with sim900.
HW is Mega2560 and Icomsat v1.1 shield.
Before this little project with the help of yours ( especially SurfefTim ) I have created almost the same project with sending data using w5100.
So the GPRS connection is successful with this code ( using library downloaded from gsmlib.org ):

#include "SIM900.h"
#include <SoftwareSerial.h>
#include "inetGSM.h"

InetGSM inet;
char msg[50];
int numdata;
char inSerial[50];
int i=0;
boolean started=false;
int GSMOnPIN = 9;  

void setup()
{
  pinMode(GSMOnPIN, OUTPUT);      // sets the digital pin as output
  Serial.begin(19200);
}

void loop()
{
  Serial.println("GSM Shield starting...");
  digitalWrite(GSMOnPIN, HIGH);   // sets the GSM on
  delay(600);                
  Serial.println("Its now High/On");
  digitalWrite(GSMOnPIN, LOW);    
  delay(10000);       
  if (gsm.begin(4800)){
    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.
    if (inet.attachGPRS("APNNAME", "", ""))
      Serial.println("status=ATTACHED");
    else Serial.println("status=ERROR");
    delay(1000);
    
    //Read IP address.
    gsm.SimpleWriteln("AT+CIFSR");
    delay(5000);
    //Read until serial buffer is empty.
    gsm.WhileSimpleRead();
    
 //*****************************
 numdata=inet.httpGET("www.google.com", 80, "/", msg, 50);
 //Print the results.
 Serial.println("\nNumber of data received:");
 Serial.println(numdata);  
 Serial.println("\nData received:"); 
 Serial.println(msg); 
  //**************************************  
   }
  serialhwread();
  //Read for new byte on NewSoftSerial.
  serialswread(); 
  
  if (inet.dettachGPRS())
      Serial.println("GPRS dettached");
    else Serial.println("GPRS not dettached");
    delay(1000);
    
  Serial.println("GSM Shield stopping...");
  digitalWrite(GSMOnPIN, HIGH);   // sets the GSM off
  delay(600);                 
  Serial.println("Its now High/Off");
  digitalWrite(GSMOnPIN, LOW);  
  delay(10000);
}


void serialhwread(){
  i=0;
  if (Serial.available() > 0){            
    while (Serial.available() > 0) {
      inSerial[i]=(Serial.read());
      delay(10);
      i++;      
    }
    
    inSerial[i]='\0';
    if(!strcmp(inSerial,"/END")){
      Serial.println("_");
      inSerial[0]=0x1a;
      inSerial[1]='\0';
      gsm.SimpleWriteln(inSerial);
    }
    //Send a saved AT command using serial port.
    if(!strcmp(inSerial,"TEST")){
      Serial.println("SIGNAL QUALITY");
      gsm.SimpleWriteln("AT+CSQ");
    }
    //Read last message saved.
    if(!strcmp(inSerial,"MSG")){
      Serial.println(msg);
    }
    else{
      Serial.println(inSerial);
      gsm.SimpleWriteln(inSerial);
    }    
    inSerial[0]='\0';
  }
}

void serialswread(){
  gsm.SimpleRead();
}

I have put starts where I think i would like to send data to cloud ( instead of this google …).
I have attached the sketch with sending data using wiznet shield.
Help me please how to send that pageadd content to the cloud server.

Thank you!

example.ino (7.02 KB)

void loop()
{
  Serial.println("GSM Shield starting...");
  digitalWrite(GSMOnPIN, HIGH);   // sets the GSM on
  delay(600);                
  Serial.println("Its now High/On");
  digitalWrite(GSMOnPIN, LOW);    
  delay(10000);       
  if (gsm.begin(4800)){
    Serial.println("\nstatus=READY");
    started=true;  
  }

Why are you doing this in loop()?

Hi PaulS,
maybe later the system will run from a solar power. In this case I do not want to let the shield eat a lot of power. Of course the delay should be set corretcly, not like this 10 seconds...
I think in case of using power from the wall socket, the shield should be started up in the setup()

Your help would be appreciated, thanks!

update...

using the following httppost method is working ( but help me understand ):

char buff[100];
 numdata=inet.httpPOST("api.server", 80, "/update?key=xxxxxxxx&field1=42", buff, msg, 50);
 //Print the results.
 Serial.println("\nNumber of data received:");
 Serial.println(numdata);  
 Serial.println("\nData received:"); 
 Serial.println(msg);

I have used upon the information if the GSm library from gsmlib.org
What is exactly the buff for? Will it be cleared out or should I take care of it?
Now I have tried as put the 42 value for field1 manually.

inet.httpPost -> int httpPOST(const char* server, int port, const char* path, const char* parameters, char* result, int resultlength);

But I would like to use the value of temp1 variable. &field1="temp1"" is not working.
:~

The third argument to the httpPOST() method is a string. It can be a literal string, as in your example, or it can be a NULL terminated char array, populated by some function like sprintf().

There are roughly 14 bazillion examples around for using sprintf() to populate an array based on the contents of variables. Hit up Google and start learning.

you point me to the right direction...already checked the previous code what attached here as example, and of course I am using there also the sprintf().
Sorry for the stupid question!

Thanks!