Sending SMS with selecting message

Hi

I’m new in Arduino, but familiard with PLCs code.
However, I’d like to choose message before send it.
I’m able to send using example from library. But after code upgrading, (even compile successful ) not.

Goal is to send SMS. But before sending, with variable t I’d like to choose a message. That works, but SMS is not sended.
(SMS is send after button is pressed → a subrutine for sending SMS is called.)

Can you please help me?

Thank you in advance.
Til


Here is my code:

 This example is in the public domain.

 http://arduino.cc/en/Tutorial/GSMExamplesSendSMS

 */
const int DIn8 = 8;                             //Button
const int LedGN =  10;                        //LED Green
boolean SendSMS = false;
int Din8Stat = 0;                               //Input8 status

int t=1;
char Alarm = 'Sprozen je alarm';


 #include <GSM.h>  // Include the GSM library
 #define PINNUMBER ""

// initialize the library instance
GSM gsmAccess;
GSM_SMS sms;

void setup()
{
 
  pinMode(DIn8, INPUT);                                                       //Mode define
   pinMode(LedGN, OUTPUT);                                                 //Mode define
  // initialize serial communications and wait for port to open:
  Serial.begin(9600);
 // while (!Serial) {
  Serial.println("SMS Messages Sender");
  // connection state
  boolean notConnected = true;
  // Start GSM shield
  // If your SIM has PIN, pass it as a parameter of begin() in quotes
  while (notConnected)
  {
    if (gsmAccess.begin(PINNUMBER) == GSM_READY)
      notConnected = false;
    else
    {
      Serial.println("Not connected");
      delay(1000);
    }
  }
  digitalWrite(LedGN,HIGH);
 Serial.println("GSM initialized");
}
//PROGRAM START  ***************************************************************************
void loop(){

int Din8Stat = digitalRead(DIn8);                           //Read input 8 -Button
int t = 2;                                                           //Choose text to send
if(Din8Stat == HIGH)                                          //Enable: If In8=1 send SMS
SendTextMessage();                                            //call conditionalsubrutine: SendTextMessage
delay(500);                                                        //Pause
Serial.println("Press button to send SMS");
}
//PROGRAM END ****************************************************************************
//********************************************************************************************

void SendTextMessage(){                                                                         //Send SMS
  char* txtMsg[] ={"This is string 1", "This is string 2", "This is string 3",         //Messages
"This is string 4", "This is string 5","This is string 6"}; 
 
 char remoteNum [20] = "123456789";                                     // define phone number to send sms
   Serial.print("To GSM number: ");                                          //Chck phone no.
   Serial.println(remoteNum);
   
   // Serial.println(t);
  
  Serial.print("Message:");                                                      //show msg to be send
  Serial.println(txtMsg[t]);
  
//send the message:
    
  sms.beginSMS(remoteNum);
  sms.print(txtMsg[t]);                                                            //???Is this OK?
  sms.endSMS();

  Serial.println("\nCOMPLETE!\n");

 Prek:
 delay(100);
}
//}

 // Read input serial
 
int readSerial(char result[])
{
  int i = 0;
  while (1)
  {
    while (Serial.available() > 0)
    {
      char inChar = Serial.read();
      if (inChar == '\n')
      {
        result[i] = '\0';
        Serial.flush();
        return 0;
      }
      if (inChar != '\r')
      {
        result[i] = inChar;
        i++;
      }
    }
  }
}

Bonsoir,

Voir ce site peut-être ? See this site maybe?
http://www.upsilonaudio.com/sim900-envoyer-des-sms-avec-une-carte-arduino/

Hi geryko

I tought it would be easyer to write code based on example.

Well, in that case I need to write completely a new code. I'm afraid there is no other option.

Thank you very much for that.

Til

I need to have a string to be variable.
Can string (txtMsg) be changed after it is declaired? I'm trying like this:

char txtMsg[200]="Text"; //Type need it for sending SMS
if (t==1) txtMsg="Tank full"; //Something is wrong// Case 1 to be send
if (t==2) txtMsg="Tank empty"; // Case 2 to be send
if (t==3) txtMsg="Tank level OK"; // Case 3 to be send

But probably the problem is in incompatible types in assignment. How to solve this?

Thanks for any help

Your 'string' methods are a bit like .BASIC, and won't work in C
You could use the Arduino 'string' features, but might be much better off reading how to handle char arrays in C

It's not quite as simple or obvious as BASIC, but is extremely flexible when you get the hang of the various functions.

Start by looking at CPLUSPLUS website - they have good notes.
The functions to start looking at may be - sprintf(). strcpy(). strlen().

If you're still struggling - I'm developing a 3G solution that will probably do everything you want and a bit more. All working today - just waiting for sample of a new 3G modem due in a week or two.
User guide PDF attached. This will be sold as an open-frame PCB, you provide the case and power supply. Expected to be available in mid-May 2016

SMSbox_User_Guide_160404.pdf