send GET text as SMS

Hi,

I will like to send the GET txt as SMS…
Example http://192.168.2.66\text-to-send?

I am stock on extracting the text from get and pars it to Send Message function
can someone guide me?

##############
here i have to read someone the get and call sms with that string… but no idea how to …
if(readString.indexOf(“sms”) >0)
{
SendMessage();

}
################

#include <SoftwareSerial.h>
#include <Ethernet.h>
#include <SPI.h>
byte mac[] = {
  0x90, 0xA2, 0xBA, 0x26, 0x26, 0x36
}; //MAC address found on the back of your ethernet shield.
IPAddress ip(192, 168, 2, 66); // IP address dependent upon your network addresses.
EthernetServer server(80);

String readString = String(30); //string 
char sms;


SoftwareSerial mySerial(8, 9);

void setup()
{
  Ethernet.begin(mac, ip);
  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());
  mySerial.begin(9600);   // Setting the baud rate of GSM Module  
  Serial.begin(9600);    // Setting the baud rate of Serial Monitor (Arduino)
  delay(100);
}


void loop()
{
EthernetClient client = server.available();
  if (client) {
  while (client.connected()) {
   if (client.available()) {
    char c = client.read();
     //read char by char HTTP request
    if (readString.length() < 20)
      {
        //store characters to string
        readString += c; //replaces readString.append(c);
      }
        //output chars to serial port
        Serial.print(c);
        //if HTTP request has ended
        if (c == '\n') {
                 //dirty skip of "GET /favicon.ico HTTP/1.1"
                  if (readString.indexOf("?") <0)
                  {
            //skip everything
          }
          else
          //- PROCESARE GET
if(readString.indexOf("sms") >0)
      {
           SendMessage();
           
    }
client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();
      
  client.println("</html>");
          //clearing string for next read
          readString="";
          //stopping client
          client.stop();  

  }}}}}

 void SendMessage()
{
  mySerial.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
  delay(1000);  // Delay of 1000 milli seconds or 1 second
  mySerial.println("AT+CMGS=\"+XXXXXX\"\r"); // Replace x with mobile number
  delay(1000);
  mySerial.println("I am SMS from GSM Module");// The SMS text you want to send
  delay(100);
   mySerial.println((char)26);// ASCII code of CTRL+Z
  delay(1000);
}
String readString = String(30); //string

That line is equivalent to:

String readString = "30"; //string

How is THAT a useful initial value?

SoftwareSerial mySerial(8, 9);

Can you post a picture of the mySerial that is connected to those pins? If it isn’t a mySerial, why the dumb name?

  client.println("</html>");

Why are you sending a close html tag without sending an open one?

client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();

Why are you telling the client that you will send text, in hrml format, when you don’t?

  }}}}}

Horseshit. ONE close curly brace per line. Use Tools + Auto Format while you are at it. Your code looks like it was typed by a drunken monkey.

What does you Serial output look like? We can’t help you parse the data you collected without seeing the data you collected.

Hi Paul,

Thank you for replay, I am not expert or having experience with C++ but I am trying my best to understand and to create a workable code.

  • on Pin 8 and 9 I have connected GSM Sim900 Module
  • code was taken from different examples and for sure is full of bug

If i open in browserver " http://192.168.2.66/text-to-send?"

I have on serial"

GET /text-to-send? HTTP/1.1 GET /favicon.ico HTTP/1.1 "


from a unix server i do [root@localhost ~]# wget http://192.168.2.66/test2 -O /dev/null --2017-09-21 09:03:38-- http://192.168.2.66/test2 Connecting to 192.168.2.66:80... connected. HTTP request sent, awaiting response... 200 OK

serial output is GET /test2 HTTP/1.1

I've notice that line client.println("HTTP/1.1 200 OK"); is required to send code 200 back, I've comment the other lines.


I am not understanding what readString = String(30); //string is doing exactly, I guess in that string is enter the get string....

can you guide me please:)

If i open in browserver " http://192.168.2.66/text-to-send?"

The http:// part defines the protocol to use.

The 192.168.2.66 part defines the server to send the data to (presumably the Arduino).

The text-to-send part defines the script to run.

The ? part separates the data to supply to the script.

The data consists of one or more name-value pairs. If there is more than one, the pairs are separated by &s.

So, you are not making a valid request.

Try http://192.168.2.66?mess="the text you want to send".

I am not understanding what readString = String(30); //string is doing exactly

The String(30) part is calling the String constructor, with the integer value 30. The constructor expects an int that it converts to a string and stores in the String instance that it creates. Creating a String with the value "30" is just pointless.

String readString;

is what you want, if just absolutely must rely on crutches.

char clientRequest[80];
byte index = 0;

and learning to use strings would be far better.

Hi,

thank you for replay, will start reading about strings...

will be possible to call sms function with char parameter

void SendMessage(clientRequest)
{
  mySerial.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
  delay(1000);  // Delay of 1000 milli seconds or 1 second
  mySerial.println("AT+CMGS=\"+XXXXXX\"\r"); // Replace x with mobile number
  delay(1000);
  mySerial.println(clientRequest);// The SMS text you want to send
  delay(100);
   mySerial.println((char)26);// ASCII code of CTRL+Z
  delay(1000);
}

will be possible to call sms function with char parameter

Of course it will be. Well, with a char array (or char pointer) as the argument type.