Hi Liebe FHEM-Community,
ich habe mir folgenden Sketch zusammengebastelt.
Dieser wertet ein paar Sensoren aus und soll diese per HTTP-GET an FHEM senden.
Die Sensoren lassen sich auch auswerten, nur das senden der Variabel an FHEM klappt nicht.
Ohne Variable (z.B. /fhem?cmd.Stehlampe=setreading%20Stehlampe%20state%20off) funktioniert einwandfrei.
Was mache ich falsch ?
Mfg
Philipp ;D
#include <Ethernet.h>
#include <SPI.h>
#include "Adafruit_Si7021.h"
Adafruit_Si7021 sensor = Adafruit_Si7021();
int trigger=7;
int echo=6;
long dauer=0;
long entfernung=0;
int bewegung=52;
int bewegungsstatus=0;
int gas=0;
int sound=0;
int helligkeit=0;
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 0, 30);
IPAddress myDns(192, 168, 0, 1);
EthernetClient client;
IPAddress server(192,168,0,220);
unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
const unsigned long postingInterval = 10L * 1000L; // delay between updates, in milliseconds
// the "L" is needed to use long type numbers
void setup()
{
Serial.begin (9600);
pinMode(trigger, OUTPUT);
pinMode(echo, INPUT);
pinMode(bewegung, INPUT);
delay(1000);
// start the Ethernet connection using a fixed IP address and DNS server:
Ethernet.begin(mac, ip, myDns);
// print the Ethernet board/shield's IP address:
Serial.print("My IP address: ");
Serial.println(Ethernet.localIP());
}
void loop()
{
digitalWrite(trigger, LOW);
delay(5);
digitalWrite(trigger, HIGH);
delay(10);
digitalWrite(trigger, LOW);
dauer = pulseIn(echo, HIGH);
entfernung = (dauer/2) * 0.03432;
if (entfernung >= 500 || entfernung <= 0)
{
Serial.println("Kein Messwert");
}
else
{
Serial.print(entfernung);
Serial.println(" cm");
}
delay(500);
bewegungsstatus=digitalRead(bewegung);
if (bewegungsstatus == HIGH)
{
Serial.println("Bewegung erkannt !");
}
else
{
Serial.println("Keine Bewegung erkannt !");
}
delay(500);
gas=analogRead(A0);
Serial.print("Luft-Messwert:");
Serial.println(gas);
delay(500);
sound=analogRead(A1);
Serial.print("Lautstaerke:");
Serial.println(sound);
delay(500);
helligkeit=analogRead(A2);
Serial.print("Helligkeit:");
Serial.println(helligkeit);
delay(500);
Serial.print("Humidity: "); Serial.print(sensor.readHumidity(), 2);
Serial.print("\tTemperature: "); Serial.println(sensor.readTemperature(), 2);
Serial.println("");
Serial.println("");
// if there's incoming data from the net connection.
// send it out the serial port. This is for debugging
// purposes only:
if (client.available()) {
char c = client.read();
Serial.write(c);
}
// if ten seconds have passed since your last connection,
// then connect again and send data:
if (millis() - lastConnectionTime > postingInterval) {
httpRequest();
}
}
// this method makes a HTTP connection to the server:
void httpRequest() {
// close any connection before send a new request.
// This will free the socket on the WiFi shield
client.stop();
// if there's a successful connection:
if (client.connect(server, 8083)) {
Serial.println("connecting...");
// send the HTTP GET request:
client.println("GET /fhem?cmd.Zimmersensor=setreading%20Zimmersensor%20brightness%20");
client.print(helligkeit);
client.print(" HTTP/1.0");
client.println("Host: 192.168.0.220");
client.println("User-Agent: arduino-ethernet");
client.println("Connection: close");
client.println();
// note the time that the connection was made:
lastConnectionTime = millis();
} else {
// if you couldn't make a connection:
Serial.println("connection failed");
}
}