Hello! I use sim900 modules and ethernet shield to send sms to my server. I use code like:
IPAddress server(111,111,111,111);
int send_sms_status = 2;
EthernetClient client;
void setup() {
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
pinMode(SEND_LED, OUTPUT);
Serial.println("SMS Messages Sender");
// connection state
boolean notConnected = true;
while(notConnected)
{
if(gsmAccess.begin(PINNUMBER)==GSM_READY)
notConnected = false;
else
{
Serial.println("Not connected");
delay(1000);
}
}
Serial.println("GSM initialized");
if (notConnected==false)
{
Serial.println("\nCOMPLETE!\n");
}
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
for(;;)
;
}
delay(1000);
Serial.print("My IP address: ");
for (byte thisByte = 0; thisByte < 4; thisByte++) {
Serial.print(Ethernet.localIP()[thisByte], DEC);
Serial.print(".");
}
Serial.println();
}
void loop () {
char c;
Serial.println("Wait for sms...");
Serial.println(GetSms);
if (GetSms==true)
{
blink_diod (GET_SMS_LED, 400);
}
if (sms.available())
{
GetSms = true;
// Get remote number
sms.remoteNumber(senderNumber, 20);
// An example of message disposal
// Any messages starting with # should be discarded
if(sms.peek()=='#')
{
Serial.println("Discarded SMS");
sms.flush();
}
// analogWrite(LED, 250);
int o = 0;
// Read message bytes and print them
while(c=sms.read())
{
// Serial.print(c);
sms_text [o] = c;
o++;
}
Serial.println("\nEND OF MESSAGE");
// Delete message from modem memory
sms.flush();
Serial.println("MESSAGE DELETED");
Serial.println("Message received from:");
Serial.println(senderNumber);
Serial.println("With text:");
Serial.println(sms_text);
SmsText = sms_text;
TelNum = senderNumber;
//connectToServer("dfdf", "555");
Serial.println("connecting...");
send_sms_status = 1;
if (client.connect(server, 80))
{
Serial.println("connected");
PrevMillForSend = millis();
start_send_serv = true;
String temp = "data=5";
Serial.println("Sending to Server: ");
client.println("POST /get_sms.php HTTP/1.1");
Serial.print("POST /get_sms.php HTTP/1.1");
client.println("Host: mysite.com");
//client.print("Content-Length: ");
//client.println(temp.length());
client.println();
client.print(temp);
client.println();
}
else
Serial.println("connection failed");
}
delay(1000);
}
When i use only this code all is okey: i get message:"SMS Messages Sender", "GSM initialized"..... and get "My IP address:" and every second get "Wait for sms..." but on my server side i have
empty POST header.
I understand that it's happened because the lines
//client.print("Content-Length: ");
//client.println(temp.length());
are commented
BUT if i uncomment i have only "SMS Messages Sender" and nothing more.....
Maybe someone knows what could be the problem? I would be very grateful for the help!!!