SMS via SMS Gateway versenden?

Hallo,

kann mir jemand eine Tipp geben wie ich folgenden Request an eine Website sende bzw. wo das Problem liegt.
Das Programm soll eine SMS via SMS Gateway versenden. Der Befehl an das Gateway soll wie folgt aussehen:

http://gateway.sms77.de/?u=benutzer&p=passwort&to=0049160999999999&text=meine%20erste%20nachricht&type=quality&from=sms77.de

#include <SPI.h>
#include <Ethernet.h>

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress server(141,0,16,244); // sms77.de
//IPAddress server(209,85,229,94); // google.de

// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;

void setup() {
// start the serial library:
Serial.begin(9600);
// 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(;:wink:
;
}
// give the Ethernet shield a second to initialize:
delay(1000);
Serial.println("connecting...");

// if you get a connection, report back via serial:
if (client.connect(server, 80)) {
Serial.println("connected");
// Make a HTTP request:
client.println("GET /?u=benutzer&p=passwort&to=0049160999999999&text=meine%20erste%20nachricht&type=quality&from=sms77.de");
client.println();
}
else {
// kf you didn't get a connection to the server:
Serial.println("connection failed");
}
}

void loop()
{
// if there are incoming bytes available
// from the server, read them and print them:
if (client.available()) {
char c = client.read();
Serial.print(c);
}

// if the server's disconnected, stop the client:
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();

// do nothing forevermore:
for(;:wink:
;
}
}

Hallo,

leider schreibst Du nicht, was genau das Problem ist. Ich vermute mal, die SMS kommt nicht an?
Du verwendest das abgewandelte Beispiel der Ethernetlibrary zum Zählen der Arduino-Treffer via Google.
Hat denn das Google-Beispiel funkioniert? Das wäre wichtig um zu wissen, ob Dein Arduino überhaupt ins Internet kommt.
Gut wäre z.B. die per DHCP erhaltene IP Konfig über die serielle Konsole auszugeben.
Code sollte beim Posten auch immer in die entsprechenden Tags gepackt werden. Das vermeidet die zwar hübschen, aber leider etwas störenden Smilies im Text :relaxed:

Was mir auch noch auffällt ist, das Du zwar auf die IP Adresse von sms77.de verbindest, alleerdings beim HTTP-Request keine Hostnamen übermittelst. Je nach Konfiguration des Webservers der auf der 141.0.16.244 lauscht, kann es sein das dieser Deinen Request ignoriert.
Ergänze mal folgendes im Code:

  if (client.connect(server, 80)) {
    Serial.println("connected");
    // Make a HTTP request:
    client.println("GET /?u=benutzer&p=passwort&to=0049160999999999&text=meine%20erste%20nachricht&type=quality&from=sms77.de");
    client.println("Host: gateway.sms77.de");
    client.println();
  }

Laut Dokumentation ist "http://gateway.sms77.de/?u=benutzer&p=...." die korrekte URL. Nur auf IP des Servers zu verbinden bringt da leider noch nichts.

VG,
Mario.

Hallo,

das Problem ist das ich keinen positive Antwort vom Server bekommen, bzw. das die SMS nicht versendet wird.
Leider hat die Anpassung des Sketchs nichts gebracht. Hier die Rückmeldung aus dem Serial Monitor:

connecting...
connected

404 Not Found

Not Found

The requested URL / was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.


Apache/2.2.21 Server at *.sms77.de Port 80

disconnecting.

Ich erwarte eigentlich das er mir irgend eine Zahl xxx zurück meldet ähnlich als würde ich die kompletten Befehl in meinen Browser eingeben.

Hier nochmal der komplette Sketch ohne die auflockernden Smilies :wink:

#include <SPI.h>
#include <Ethernet.h>

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress server(141,0,16,244); // sms77.de

// Initialize the Ethernet client library
// with the IP address and port of the server 
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;

void setup() {
  // start the serial library:
  Serial.begin(9600);
  // 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(;;)
      ;
  }
  // give the Ethernet shield a second to initialize:
  delay(1000);
  Serial.println("connecting...");

  // if you get a connection, report back via serial:
  if (client.connect(server, 80)) {
    Serial.println("connected");
    // Make a HTTP request:
    client.println("GET /?u=benutzer&p=passwort&to=0049160999999999&text=meine%20erste%20nachricht&type=quality&from=sms77.de");
    client.println("Host: gateway.sms77.de");
    client.println();
  } 
  else {
    // kf you didn't get a connection to the server:
    Serial.println("connection failed");
  }
}

void loop()
{
  // if there are incoming bytes available 
  // from the server, read them and print them:
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }

  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();

    // do nothing forevermore:
    for(;;)
      ;
  }
}

MfG
Snoops

Ok, das hatte ich übersehen, es fehlt noch ein wichtiges Detail:

  if (client.connect(server, 80)) {
    Serial.println("connected");
    // Make a HTTP request:
    client.println("GET /?u=benutzer&p=passwort&to=0049160999999999&text=meine%20erste%20nachricht&type=quality&from=sms77.de HTTP/1.0");
    client.println("Host: gateway.sms77.de");
    client.println();

Siehe auch Hypertext Transfer Protocol – Wikipedia
Das "HTTP/1.0" am Ende ist wichtig, damit weiss der Webserver welche "HTTP-Variante" Du sprichst.

Um das Ganze zu testen, kann man sich sehr einfach mit dem guten alten telnet behelfen:

Mario-Kellers-Mac-mini:~ mario$ telnet gateway.sms77.de 80
Trying 141.0.16.244...
Connected to gateway.sms77.de.
Escape character is '^]'.
GET /?u=benutzer&p=passwort&to=0049160999999999&text=meine%20erste%20nachricht&type=quality&from=sms77.de

404 Not Found

Not Found

The requested URL / was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.


Apache/2.2.21 Server at *.sms77.de Port 80 Connection closed by foreign host. Mario-Kellers-Mac-mini:~ mario$ telnet gateway.sms77.de 80 Trying 141.0.16.244... Connected to gateway.sms77.de. Escape character is '^]'. GET /?u=benutzer&p=passwort&to=0049160999999999&text=meine%20erste%20nachricht&type=quality&from=sms77.de HTTP/1.0

HTTP/1.1 404 Not Found
Date: Wed, 11 Jan 2012 20:21:05 GMT
Server: Apache/2.2.21
Content-Length: 384
Connection: close
Content-Type: text/html; charset=iso-8859-1

404 Not Found

Not Found

The requested URL / was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.


Apache/2.2.21 Server at *.sms77.de Port 80 Connection closed by foreign host. Mario-Kellers-Mac-mini:~ mario$ telnet gateway.sms77.de 80 Trying 141.0.16.244... Connected to gateway.sms77.de. Escape character is '^]'. GET /?u=benutzer&p=passwort&to=0049160999999999&text=meine%20erste%20nachricht&type=quality&from=sms77.de HTTP/1.0 Host: gateway.sms77.de

HTTP/1.1 200 OK
Date: Wed, 11 Jan 2012 20:21:17 GMT
Server: Apache/2.2.21
X-Powered-By: PHP/5.2.13
Connection: close
Content-Type: text/html

900Connection closed by foreign host.

Hier habe ich alle 3 Varianten durchgespielt und erst der dritte und einzig vollständige Request mit HTTP-Version und Host-Namen funktioniert.
Und sorry für den quote-Spam :slight_smile:

Hallo,

Fein 100 RENNT SMS wurde erfolgreich verschickt :grin:

connecting...
connected
HTTP/1.1 200 OK
Date: Wed, 11 Jan 2012 21:18:08 GMT
Server: Apache/2.2.21
X-Powered-By: PHP/5.2.13
Connection: close
Content-Type: text/html

100
disconnecting.

Ein Frage habe ich noch. Wie muss die IPAddress server(?????) aussehen wenn ich nicht die IP habe sondern nur die URL bspw. www.sms77.de?
Hast du dafür ein Beispiel?

Gruß
Snoops

Hi,

leider nimmt die Ethernet-Library nur IP-Adressen.

IPAddress server(141,0,16,244); // sms77.de

Ist daher schon richtig.

Hier kannst du nachsehen welche Server-IP hinter einer Domain steht.

Es ist allerdings nicht unüblich, dass hinter einer IP mehrere Webseiten stecken.(Insbesondere bei günstigen Webhostern z.B.)
Daher ist es wichtig den anzusprechenden Host (also die Domain) mitzusenden.

   client.println("Host: gateway.sms77.de");

Da es ja jetzt zu laufen scheint, frag ich mal ganz neugierig:
Was hast denn du fürn Projekt? :slight_smile:
Mit SMS-Versenden klingt interessant..

Die DNS Auflösung scheint auch möglich zu sein, zumindest kann man das nach dem Thread hier denken:

Hi,

ich wollte das Programm noch erweitern und einen Nachricht an meine dBox senden wenn die SMS verschickt wurde.
Aber leider hängt sich das Programm schon beim initalisieren der DHCP Adresse auf :(.
Kann mir jemand sagen was am Code falsch ist?

#include <SPI.h>
#include <Ethernet.h>

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress SMSserver(141,0,16,244); // sms77.de
IPAddress dBox2(192,167,16,244); // ID Adresse dbox 

// Initialize the Ethernet client library
// with the IP address and port of the server 
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;

void setup() {
  // start the serial library:
  Serial.begin(9600);
  // 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(;;)
      ;
  }
  // give the Ethernet shield a second to initialize:
  delay(1000);
  Serial.println("connecting...");

  // if you get a connection, report back via serial:
  if (client.connect(SMSserver, 80)) {
    Serial.println("connected");
    // Make a HTTP request SMS versenden steht auf debug weil sonst jedesmal SMS versendet wird:
    client.println("GET /?u=benutzer&p=passwort&to=0049160999999999&text=meine%20erste%20nachricht&type=quality&from=sms77.de HTTP/1.0");
    client.println("Host: gateway.sms77.de");
    client.println();
  } 
  else {
    // kf you didn't get a connection to the server:
    Serial.println("connection failed");
  }
  
  if (client.connect(dBox2, 80)) {
    Serial.println("connected");
    // Make a HTTP request SMS versenden steht auf debug weil sonst jedesmal SMS versendet wird:
    client.println("GET /control/message?popup=SMS%20wurde%20versendet! HTTP/1.0");
    client.println("Host: 192.167.16.244");
    client.println();
  } 
  else {
    // kf you didn't get a connection to the server:
    Serial.println("connection failed");
  }
  
  
}

void loop()
{
  // if there are incoming bytes available 
  // from the server, read them and print them:
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }

  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();

    // do nothing forevermore:
    for(;;)
      ;
  }
}

Hi,

"Aber leider hängt sich das Programm schon beim initalisieren der DHCP Adresse auf "
damit meinst du sicher, dass "if(client.connect(dBox2, 80))" false zurückgibt und die Fehlermeldung "connection failed" auf dem Serial Monitor ausgegeben wird oder?

Ich vermute du musst nach dem SMS-Connect-Block erst "client.stop();" ausführen um eine neue Verbindung für den Dbox-Block aufzubauen.

Probier mal den Code:

#include <SPI.h>
#include <Ethernet.h>

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress SMSserver(141,0,16,244); // sms77.de
IPAddress dBox2(192,167,16,244); // ID Adresse dbox 

// Initialize the Ethernet client library
// with the IP address and port of the server 
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;

void setup() {
  // start the serial library:
  Serial.begin(9600);
  // 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(;;)
      ;
  }
  // give the Ethernet shield a second to initialize:
  delay(1000);
  Serial.println("connecting...");

  // if you get a connection, report back via serial:
  if (client.connect(SMSserver, 80)) {
    Serial.println("connected");
    // Make a HTTP request SMS versenden steht auf debug weil sonst jedesmal SMS versendet wird:
    client.println("GET /?u=benutzer&p=passwort&to=0049160999999999&text=meine%20erste%20nachricht&type=quality&from=sms77.de HTTP/1.0");
    client.println("Host: gateway.sms77.de");
    client.println();
  } 
  else {
    // kf you didn't get a connection to the server:
    Serial.println("connection failed");
  }
//#######################
      client.stop(); // ############# VERBINDUNG BEENDEN UM NEUE AUFZUBAUEN
//#######################
  if (client.connect(dBox2, 80)) {
    Serial.println("connected");
    // Make a HTTP request SMS versenden steht auf debug weil sonst jedesmal SMS versendet wird:
    client.println("GET /control/message?popup=SMS%20wurde%20versendet! HTTP/1.0");
    client.println("Host: 192.167.16.244");
    client.println();
  } 
  else {
    // kf you didn't get a connection to the server:
    Serial.println("connection failed");
  }
  
  
}

void loop()
{
  // if there are incoming bytes available 
  // from the server, read them and print them:
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }

  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();

    // do nothing forevermore:
    for(;;)
      ;
  }
}

Klappt das?

Hi,

ja danke für den Tipp. Jetzt klappt's! :grin: