Hello!
I want to use the GSM module along with an ethernet one. I have changed my gsm pins to 4,5 to avoid the collision of pin 2 used also by the eth module. My webserver has a form in which the user inserts the number and text for the SMS. I can successfully send the 1st sms but after that the gsm module becomes unresponsively. Any ideas why is that going ? Below is my sketch .
#include <SPI.h>
#include <Ethernet.h>
#include <NewSoftSerial.h>
#define maxLength 255
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192,168,5, 177 };
String receivedText = String(255);
Server server(80);
NewSoftSerial cell(4,5);
char incoming_char=0;
void setup()
{
Serial.begin(9600);
Ethernet.begin(mac, ip);
server.begin();
Serial.println("WebOn");
cell.begin(9600);
delay(35000);
cell.print("AT+CMGF=1");
}
void loop()
{
Client client = server.available();
if (client) {
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
if (receivedText.length() < maxLength) {
receivedText += c;
}
if (c == '\n' && currentLineIsBlank) {
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
client.print("<html><head><title>SMS Sender</title></head><body>");
client.println("<h1>SMS</h1>");
client.print("<form accept-charset=""ISO-8859-1"" method=get>Mesajul: <input type=text size=255 name=the_text> <input type=submit></form>");
client.println("</body></html>");
break;
}
if (c == '\n') {
currentLineIsBlank = true;
}
else if (c != '\r') {
currentLineIsBlank = false;
}
}
}
delay(1);
int firstPos = receivedText.indexOf("?");
if (firstPos > -1) {
int lastPos = receivedText.indexOf(" ", firstPos);
String mesaj = receivedText.substring(firstPos+20, lastPos);
String nr = receivedText.substring(firstPos+10, firstPos+20);
for(int i=0;i<mesaj.length();i++)if(mesaj[i]=='+')mesaj[i]=' ';
cell.print("AT+CMGS="); // now send message...
cell.print(34,BYTE); // ASCII equivalent of "
cell.print(nr);
cell.print(34,BYTE); // ASCII equivalent of "
delay(500); // give the module some thinking time
cell.print(mesaj); // our message to send
cell.println(26,BYTE); // ASCII equivalent of Ctrl-Z
delay(15000); // the SMS module needs time to return to OK status
}
receivedText = "";
client.stop();
}
}