// Daten an PHP-Skript senden, anschliessend Email aus Skript// Datei:
Buch3_kap10_mailsenden_php
// Datum: 12.02.10/TB
#include <SPI.h>
#include <Ethernet.h>
// Ethernet Konfiguration
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 1, 199 };
byte gateway[] = { 192, 168, 1, 1 };
byte subnet[] = { 255, 255, 255, 0 };
// IP meines Servers
IPAddress server( 192, 168, 1, 100 );
EthernetClient client;
long updateTimer;
boolean clientConnected = false;
void setup()
{
Serial.begin(9600);
// E-Mailversand auslösen
SendenEmail();
// Status des E-Mail-Versands einlesen
checkEmailStatus();
}
void loop()
{
// Anweisungen
}
void SendenEmail()
{
if ((millis() - updateTimer) > 10000)
{
Ethernet.begin(mac, ip);
Serial.println("connecting...");
delay(1000);
if (client.connect(server, 80))
{
Serial.println("connected");
client.print("GET /mailsender.php");
client.println(" HTTP/1.0");
client.println("HOST:meinserver.com\n\n");
client.println();
client.println();
clientConnected = true;
}
else
{
Serial.println("connection failed");
}
updateTimer = millis();
}
}
void checkEmailStatus()
{
if (clientConnected)
{
if (client.available())
{
char c = client.read();
Serial.print(c);
}
if (!client.connected())
{
Serial.println();
Serial.println("disconnecting.");
client.stop();
clientConnected = false;
}
}
}
Lesezeichen