Teste dies mal:
#include "ClickButton.h"
#include <SPI.h>
#include <Ethernet.h>
//ETHERNET-SETTINGS
byte mac[] = { 0x5D, 0xA2, 0xFA, 0x2D, 0x36, 0x7C }; // MAC-Adresse des Arduino
byte ip[] = { 192, 168, 178, 178 }; // IP-Adresse des Arduino
byte gateway[] = { 192, 168, 178, 1 }; // Gateway
byte subnet[] = { 255, 255, 255, 0 }; // SubNet
byte server[] = { 192, 168, 178, 2 }; // IP-Adresse des Servers
EthernetClient client;
char host[] = "192, 168, 178, 2 "; // Domain
// Variable für Rückgabe des Servers
// the LED
const int ledPin8 = 8;
const int ledPin9 = 9;
int ledState1 = 0;
int ledState2 = 0;
int ledState3 = 0;
int ledState4 = 0;
// the Button
const int buttonPin1 = 5;
ClickButton button1(buttonPin1, LOW, CLICKBTN_PULLUP);
const int buttonPin2 = 2;
ClickButton button2(buttonPin2, LOW, CLICKBTN_PULLUP);
const int buttonPin3 = 3;
ClickButton button3(buttonPin3, LOW, CLICKBTN_PULLUP);
const int buttonPin4 = 4;
ClickButton button4(buttonPin4, LOW, CLICKBTN_PULLUP);
// Arbitrary LED function
int LEDfunction = 0;
void setup()
{
Serial.begin(9600);
Serial.println("Ethernet initialisieren...");
Ethernet.begin(mac, ip);
pinMode(ledPin8,OUTPUT);
pinMode(ledPin9,OUTPUT);
// Setup button timers (all in milliseconds / ms)
// (These are default if not set, but changeable for convenience)
button1.debounceTime = 20; // Debounce timer in ms
button2.debounceTime = 20; // Debounce timer in ms
button3.debounceTime = 20; // Debounce timer in ms
button4.debounceTime = 20; // Debounce timer in ms
}
void loop()
{
// Update button state
button1.Update();
// Save click codes in LEDfunction, as click codes are reset at next Update()
if (button1.clicks != 0) LEDfunction = button1.clicks;
// Simply toggle LED on single clicks
// (Cant use LEDfunction like the others here,
// as it would toggle on and off all the time)
if(button1.clicks == 1)
{
ledState1 = !ledState1;
if (client.connect(server, 2110)) // Verbindung zum Server aufbauen
{
Serial.println("Verbunden, Sende Daten...");
if(ledState1 == 1) {
client.print("webtaster1=an");
Serial.print("webtaster1=an");
Serial.print(ledState1);
}
else {
client.print("webtaster1=aus");
Serial.print("webtaster1=aus");
Serial.print(ledState1);
}
}
client.stop();
}
if(button2.clicks == 1)
{
ledState2 = !ledState2;
}
if(button3.clicks == 1)
{
ledState3 = !ledState3;
}
if(button4.clicks == 1)
{
ledState4 = !ledState4;
}
// update the LED
digitalWrite(ledPin8,ledState1);
digitalWrite(ledPin9,ledState2);
}