How to create a new function within an existing library


Please, Go to : « Reply #5 on: Today at 09:39:57 am » with better explication.

Dear All,

I just get a library with class to use GPRS. There is function send SMS, get a call, make a call, but there is nothing to send data to a remote server.

In my Sketch code, I have thta function

error=gsm.SendSMS(number,text);

I also have a file : GPRS_Shield.h and a file : GPRS_Shield.ccp

In my GRPS_Shield.h, I have a this:

char SendSMS(char *number_str, char *message_str);

and in my GPRS_Shield.ccp, I have this

char GSM::SendSMS(char *number_str, char *message_str) 
{
... code ...
 }

As I would like to have a new function, I did the following: In my Sketch code , I add a new function

error=gsm.SendDATA(data);

In my GRPS_Shield.h, I have a this new:

char SendDATA(char *data);

and in my GPRS_Shield.ccp, I have this new

char GSM::SendDATA(char *data) 
{
... code ...
 }

When I compile my code I got that error message

Users/my/Documents/Arduino/libraries/GSM_Shield/GSM_Shield.cpp: In member function 'char GSM::SendDATA(char*)': /Users/my/Documents/Arduino/libraries/GSM_Shield/GSM_Shield.cpp:1429: error: invalid conversion from 'const char*' to 'char'

Could tell me how to create a new function to send data via http?

Many thank

... code ...

Can we see this mysterious code ?

This is the code of the function SendSMS.

May be I should have say that earler.
I am trying to add the function SendDATA() to that Library:

That possiblity does not exist and I need it

here is the code wich is GPRS_Shield.cpp

char GSM::SendSMS(char *number_str, char *message_str) 
{
  char ret_val = -1;
  byte i;

  if (CLS_FREE != GetCommLineStatus()) return (ret_val);
  
  SetCommLineStatus(CLS_ATCMD);  
  
  ret_val = 0; // still not send
  
  // try to send SMS 3 times in case there is some problem
  for (i = 0; i < 3; i++) {
    // send  AT+CMGS="number_str"
    mySerial.write("AT+CMGS=\"");
    mySerial.write(number_str);  
    mySerial.write("\"\r");

    // 1000 msec. for initial comm tmout
    // 50 msec. for inter character timeout
    if (RX_FINISHED_STR_RECV == WaitResp(1000, 50, ">")) {
      // send SMS text
      mySerial.write(message_str); 
	  
#ifdef DEBUG_SMS_ENABLED
      // SMS will not be sent = we will not pay => good for debugging
      mySerial.write(0x1b);
      if (RX_FINISHED_STR_RECV == WaitResp(7000, 50, "OK")) {
#else 
      mySerial.write(0x1a);
	  //mySerial.flush(); // erase rx circular buffer
      if (RX_FINISHED_STR_RECV == WaitResp(7000, 5000, "+CMGS")) {
#endif
        // SMS was send correctly 
        ret_val = 1;
		#ifdef DEBUG_PRINT
			DebugPrint("SMS was send correctly \r\n", 0);
		#endif
        break;
      }
      else continue;
    }
    else {
      // try again
      continue;
    }
  }

  SetCommLineStatus(CLS_FREE);
  return (ret_val);
}

Below I create this new

char GSM::SendDATA(char *data) 
{
// Future code
  
}

and in GPRS_Shiel.h I added this

char SendDATA(char *data);

Just above the existing class

 // SMS's methods 
    char SendSMS(char *number_str, char *message_str);

My new class need only one variable “data”

If I understand you correctly your sendDATA() function does not yet have any code in it, is that right ? Can you provide an example of how you are trying to use the sendDATA method ?

You say that you want to "send data via http". Are you planning to use the GPRS shield for that ?

Yes for now, my function SendDATA() does not have code yet. It's not ready right now. I building taking from another library. For now I am trying to simply create a function with a simple code, and making it step ba step.

I would like to add that new function SendDATA to that library https://github.com/jgarland79/GSM_Shield (I mentionned it to late)

Yes, I will use the GPRS shield for that, for sure.

Thank

May be you cna help e on that matter,

I have that sketch code working:

void SubmitHttpRequest()
{
 mySerial.println("AT+CSQ");
 delay(100);
 ShowSerialData();// this code is to show the data from gprs shield, 
 //in order to easily see the process of
 //how the gprs shield submit a http request, and the following is for this purpose too.
 mySerial.println("AT+CGATT?");
 delay(100);
 ShowSerialData();
 mySerial.println("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"");//setting the SAPBR, the connection 
 //type is using gprs
 delay(1000);
 ShowSerialData();
 mySerial.println("AT+SAPBR=3,1,\"APN\",\"internet\"");//setting the APN, 
 //the second need you fill in your local apn server
 delay(4000);
 ShowSerialData();
 mySerial.println("AT+SAPBR=1,1");//setting the SAPBR, for detail you can refer to 
 //the AT command mamual
 delay(2000);
 ShowSerialData();
 mySerial.println("AT+HTTPINIT"); //init the HTTP request
 delay(2000); 
 ShowSerialData();
 mySerial.println("AT+HTTPPARA=\"URL\",\"cccc.dyndns.org/opt/updatesql.php\"");// setting the httppara, 
 //the second parameter is the website you want to access
 delay(1000);
 ShowSerialData();
 mySerial.println("AT+HTTPACTION=0");//submit the request 
 delay(8000);//the delay is very important, the delay time is base on the return from the website, 
 //if the return datas are very large, the time required longer.
 //while(!mySerial.available());
 ShowSerialData();
 mySerial.println("AT+HTTPREAD");// read the data from the website you access
 delay(300);
// ShowSerialData();
 checkForResponse();
 mySerial.println("");
 delay(100);
 mySerial.println("AT+HTTPTERM");// read the data from the website you access
 delay(300);
 ShowSerialData();

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

Tha code is on aFile.ino

I would like to include it into a existing library that I inked above https://github.com/jgarland79/GSM_Shield But it does not work

Could you instruct me how to modify my library in order ro have the above code in GPRS_Shield.cpp file, into GPS::?

I tryied from early this morning, and I am still blocked.....

Many thank for your help

Any idea? It will help