I am faced with a problem I don't understand... the substring returns 'empty' values.
I use Arduino 1.0.5 with the SoftwareSerial.h included, on an Arduino Uno.
Here is the code :
// csms is a String coming from SIM900 serial : String csms = String("");
Serial.print("CALL WEB WITH : ");
Serial.println(csms);
int i1;
int i2;
i1 = csms.indexOf('"');
i2 = csms.indexOf('"' , i1+1);
// REC UNREAD
i1 = csms.indexOf('"',i2+1);
i2 = csms.indexOf('"' , i1+1);
Serial.println(i1);
Serial.println(i2);
String num = csms.substring(i1+1,i2);
num.replace("+33","0");
Serial.print("CALLING NUMBER : ");
Serial.println(num);
i1 = csms.indexOf('"', i2+1);
i2 = csms.indexOf('"' , i1+1);
Serial.println(i1);
Serial.println(i2);
// EMPTY
i1 = csms.indexOf('"',i2+1);
i2 = csms.indexOf('"' , i1+1);
Serial.println(i1);
Serial.println(i2);
String date = csms.substring(i1+1,i2);
Serial.print("DATE : ");
Serial.println(date);
String psms = "mytel="+mytel+"&num"+num+"&date="+date+"\0";
Serial.print("POST PARAMS : ");
Serial.println(psms);
And here is the log :
CALL WEB WITH :
+CMGR: "REC UNREAD","+33612345678","","14/03/10,17:34:36+04"
21
34
CALLING NUMBER :
36
37
39
60
DATE :
POST PARAMS :
so the i1 and i2 parameters are well computed, but the substrings are empty...
String num = csms.substring(i1+1,i2);
num.replace("+33","0");
Serial.print("CALLING NUMBER : ");
Serial.println(num);
The time to print num is IMMEDIATELY after extracting the sub-strng, not after extracting and diddling with it. Which step is failing? You don't know. Fix that.
I must say I don't understand why it is not possible to modify this parameter before printing it. I've tried to do what you said, and it works... but, if I add it again, it works also... Don't understand, is it a memory allocation problem ?
Moreover, I am still unable to create my psms variable, which is still empty. I've shorten the code as far as I can do :
And, it will continue to do so until you quit using Strings. There is NOTHING that the String class does that can't be done with strings, except piss away resources like you have a terrabyte of memory.
So... you mean String class must not be used ?!
I agree, it looks like it doesn't work indeed... as it looks like I am faced with kind of heisenbugs
If I have to use char[], I can of course, but is there any code to help ? If String class is so buggy, I imagine somebody may have done his own library ? I will have a look on google... and add any relevant code here, if I find any.