Go Down

Topic: Sending SMS with a Sony Ericsson K700i phone (Read 3225 times) previous topic - next topic

BineG

Im trying to send a sms message using arduino and a SE K700i phone but im having big problems.
I wrote a function which builds a pdu text string and sends it to the phone but nothing happens. If i run this snippet i found sms is sent
Code: [Select]
Serial1.println("AT+CMGF=0"); // Set PDU mode
  delay(3000);
  Serial1.println("AT+CMGS=19"); // Number of octets
  delay(3000);
  Serial1.print("0011000B918346555555F50000AA05C8329BFD06"); // Sends "Hello" to "00 46707112233"
  delay(3000);
  Serial1.write(26);
  delay(3000);
 
  Serial.println("Command sent");


But when i try my function.. nothing. Any suggestions?  :~
Here is my code:
http://pastebin.com/zzCXhjAY

power7net

#1
Feb 13, 2012, 06:43 am Last Edit: Feb 22, 2013, 03:11 pm by power7net Reason: 1
Hello.First check your cable connection mobile phone with arduino.You test it with AT commands? AT....ok
Look my code http://www.power7.net and http://www.dreamfabric.com/sms/ i use an old SE K700i check pins...
Web / sms / bluetooth / arduino / android remote control. Home Automation projects.
http://www.power7.net

moustic

Some times ago I made a small libray to build PDU
check on the playground it should still be there (PDU encoder )
I heavily tested it.

spumanti

Why do you want to send it in PDU mode?

Code: [Select]
Serial1.println("AT+CMGF=0"); // Set PDU mode

If you set it to 1 instead, you dont have to encode the SMS to PDU, but instead use clear text ->> much easier IMO.   XD

Code: [Select]
Serial1.println("AT+CMGF=1"); // Set TXT mode

http://www.diafaan.com/sms-tutorials/gsm-modem-tutorial/at-cmgf/

For a more convenient way of handling the comms with the mobile phone, consider using the Sserial2mobile library:
http://code.google.com/p/sserial2mobile/

BineG

#4
Feb 21, 2012, 06:12 pm Last Edit: Feb 21, 2012, 06:51 pm by BineG Reason: 1
Thank you all. I could send sms messages afterwards (although to be honest i dont know why it started working) but i will definitely check out sending it as plain text. Sounds much easier.

mmgserver

Hello,
I was also trying to make this work.
Finally after reading and testing a lot I managed to get a working function that allows you to send sms by translating text to pdu.
The following function is my adaptation to "https://sites.google.com/site/marthalprojects/home/arduino/arduino-sends-SMS" by Martin Thalheimer.
Thanks Martin for creating the original code.




/*
Function to send sms by converting plain text to PDU. Tested with international numbers
Usage: send_sms("Hello from your Arduino !", "+40777777777" );
*/


void send_sms(String message, String phone_nr ) {

byte original_byte;
byte newbyte;
int pdu_length;
int counter;
String newphone_nr;
int numlength;


 delay(3000);
 Serial.begin(9600);  
 delay(3000);
 numlength=phone_nr.length()-1;
 if (numlength% 2 != 0 ) {
   phone_nr += "F";
 }
 for(int x = 0; x < numlength; x = x+2){
   newphone_nr.concat(phone_nr.charAt(x+2));
   newphone_nr.concat(phone_nr.charAt(x+1));
 }

 //start sending SMS
 Serial.println("AT");  //optional: say hello to the modem
 delay(3000);
 Serial.println("AT+CPMS=\"ME\",\"SM\"");//set the phone memeory (ELEMENTE SALVATE)
 delay(3000);
 Serial.println("AT+CMGF=0");//set pdu mode (K700i allows onlyr PDU)
 delay(3000);
// Serial.println("AT+CMGD=1");//delete message from 1 position in phone memory
 //delay(3000);
 int textlength= message.length()*7/8;   // text message length: number of characters*7/8
 if (message.length()*7%8 != 0) {
   textlength++;
 }
 if (numlength%2 != 0) {   //if the length of phone number was uneven, it now increases by 1 because of the added "F"
   pdu_length = (8 + (numlength+1)/2 + textlength);
 }
 else { //8 bytes of parameters + (length of phonenumber)/2 + number of bytes in the text
   pdu_length = (8 + numlength/2 + textlength);
 }

 Serial.print("AT+CMGS="); //.
 Serial.println(pdu_length);
 delay(3000);
 Serial.print("001100");  //these are some parameters which we don't need to bother about
 if (numlength<16){       //now we have to send the byte containing the length of the phone number in HEX format
   Serial.print(0);
 }        //the byte in HEX format needs to be 2 characters long; if needed we add a 0 in front, e.g. "C" will become "0C"
 Serial.print(numlength,HEX); //length telnr - this time any additional F is not to be considered
 Serial.print("91");     //international format of phone number //81 for national format
 Serial.print(newphone_nr); //now we send the rearranged phone number
 Serial.print("0000AA"); //some more parameters
 if (message.length()<16){
   Serial.print(0);
 }       //a byte in HEX format indicating the length of the text. Again the byte needs to be made of 2 characters
 Serial.print(message.length(),HEX);

 counter=0;
 newbyte=0;
 for (int j=0; j<message.length(); j++) {
   original_byte = message.charAt(j); //one by one we take each byte out of the original text

   for (int i=0; i<7; i++) {
     newbyte=newbyte|bitRead(original_byte, i)<<counter;  //take the bits 0 to 6 of the old byte, shift as required for the new byte and add to the new byte
     counter++;
     if (counter==8) {
       counter=0;          //if a new byte is complete, set the counter to 0
       if (newbyte<16){
         Serial.print(0);
       } //each byte in HEX format should consist of 2 characters, if necessary add 0 in front
       Serial.print (newbyte, HEX); //when the new byte is finished, send it to the mobile phone
       newbyte=0; // the next new byte will start again from 0
     }
   }
 }
 if (message.length()*7%8!=0) {    //if there were remaining bits (not enough to form a new byte), these are sent out as the last byte
   if (newbyte<16){
     Serial.print(0);
   } //each byte in HEX format should consist of 2 characters, if necessary add 0 in front
   Serial.print (newbyte, HEX);
 }
 delay(3000);
Serial.println('\x001a'); //ctrl+z
delay(3000);

}

mmgserver

#6
Jul 23, 2015, 05:01 pm Last Edit: Jul 23, 2015, 05:01 pm by mmgserver
Hello,
I was also trying to make this work.
Finally after reading and testing a lot I managed to get a working function that allows you to send sms by translating text to pdu.
The following function is my adaptation to "https://sites.google.com/site/marthalprojects/home/arduino/arduino-sends-SMS" by Martin Thalheimer.
Thanks Martin for creating the original code.


/*
Function to send sms by converting plain text to PDU. Tested with international numbers
Usage: send_sms("Hello from your Arduino !", "+40777777777" );
*/


void send_sms(String message, String phone_nr ) {

byte original_byte;
byte newbyte;
int pdu_length;
int counter;
String newphone_nr;
int numlength;


 delay(3000);
 Serial.begin(9600); 
 delay(3000);
 numlength=phone_nr.length()-1;
 if (numlength% 2 != 0 ) {
   phone_nr += "F";
 }
 for(int x = 0; x < numlength; x = x+2){
   newphone_nr.concat(phone_nr.charAt(x+2));
   newphone_nr.concat(phone_nr.charAt(x+1));
 }

 //start sending SMS
 Serial.println("AT");  //optional: say hello to the modem
 delay(3000);
 Serial.println("AT+CPMS=\"ME\",\"SM\"");//set the phone memeory (ELEMENTE SALVATE)
 delay(3000);
 Serial.println("AT+CMGF=0");//set pdu mode (K700i allows onlyr PDU)
 delay(3000);
// Serial.println("AT+CMGD=1");//delete message from 1 position in phone memory
 //delay(3000);
 int textlength= message.length()*7/8;   // text message length: number of characters*7/8
 if (message.length()*7%8 != 0) {
   textlength++;
 }
 if (numlength%2 != 0) {   //if the length of phone number was uneven, it now increases by 1 because of the added "F"
   pdu_length = (8 + (numlength+1)/2 + textlength);
 }
 else { //8 bytes of parameters + (length of phonenumber)/2 + number of bytes in the text
   pdu_length = (8 + numlength/2 + textlength);
 }

 Serial.print("AT+CMGS="); //.
 Serial.println(pdu_length);
 delay(3000);
 Serial.print("001100");  //these are some parameters which we don't need to bother about
 if (numlength<16){       //now we have to send the byte containing the length of the phone number in HEX format
   Serial.print(0);
 }        //the byte in HEX format needs to be 2 characters long; if needed we add a 0 in front, e.g. "C" will become "0C"
 Serial.print(numlength,HEX); //length telnr - this time any additional F is not to be considered
 Serial.print("91");     //international format of phone number //81 for national format
 Serial.print(newphone_nr); //now we send the rearranged phone number
 Serial.print("0000AA"); //some more parameters
 if (message.length()<16){
   Serial.print(0);
 }       //a byte in HEX format indicating the length of the text. Again the byte needs to be made of 2 characters
 Serial.print(message.length(),HEX);

 counter=0;
 newbyte=0;
 for (int j=0; j<message.length(); j++) {
   original_byte = message.charAt(j); //one by one we take each byte out of the original text

   for (int i=0; i<7; i++) {
     newbyte=newbyte|bitRead(original_byte, i)<<counter;  //take the bits 0 to 6 of the old byte, shift as required for the new byte and add to the new byte
     counter++;
     if (counter==8) {
       counter=0;          //if a new byte is complete, set the counter to 0
       if (newbyte<16){
         Serial.print(0);
       } //each byte in HEX format should consist of 2 characters, if necessary add 0 in front
       Serial.print (newbyte, HEX); //when the new byte is finished, send it to the mobile phone
       newbyte=0; // the next new byte will start again from 0
     }
   }
 }
 if (message.length()*7%8!=0) {    //if there were remaining bits (not enough to form a new byte), these are sent out as the last byte
   if (newbyte<16){
     Serial.print(0);
   } //each byte in HEX format should consist of 2 characters, if necessary add 0 in front
   Serial.print (newbyte, HEX);
 }
 delay(3000);
Serial.println('\x001a'); //ctrl+z
delay(3000);

}


Go Up