Anbindung eines Arduino Ethernet ans Netzwerk/Zugriff mit FHEM

Hallo liebe Community,

Ich bin absoluter Neuling bei der Programmierung mit Arduino. Daher hoffe ich gnädige Hilfe.

Im Moment arbeite ich an einem Projekt wo ich eine Regelung mittels FHEM und einem Raspberry-PI realisiere.

Für das Einlesen der Sensorwerte und zur Ansteuerung von Aktoren möchte ich einen Arduino verwenden, welcher ich mittels Ethernet an das Netzwerk anschließen möchte.

Das FHEM-Wiki liefert mir dazu ein vorgefertigtes, leider schlecht kommentiertes Code-Beispiel für einen Arduino Uno.

Ich besitze jedoch einen Arduino Ethernet. Demnach muss der Code entsprechen angepasst werden, welches mir aufgrund meiner (noch) nicht vorhanden Kenntnissen und schlechter Kommentierung einige Probleme bereitet.

Daher hoffe ich auf eure Hilfe. Wer weiß wie ich den Code anpassen muss?

// A web server to control the arduino via FHEM
#include “etherShield.h”
#include “ETHER_28J60.h”
#include <RCSwitch.h>

int outputPin = 5;
int inputPin = 8;
int sensorPin = A6;
int sensorValue = 0;
int sensorVal = 0;

static uint8_t mac[6] = {0x54, 0x55, 0x58, 0x10, 0x00, 0x24}; // this just needs to be unique for your network,
static uint8_t ip[4] = {192, 168, 178, 40}; // the IP address for your board. Check your home hub
// to find an IP address not in use and pick that
// this or 10.0.0.15 are likely formats for an address
// that will work.

static uint16_t port = 80; // Use port 80 - the standard for HTTP

// RCSwitch configuration
RCSwitch mySwitch = RCSwitch();
int RCTransmissionPin = 6;

ETHER_28J60 e;

void setup()
{
e.setup(mac, ip, port);
pinMode(RCTransmissionPin, OUTPUT);
pinMode(outputPin, OUTPUT);
pinMode(inputPin, INPUT);
pinMode(sensorPin, INPUT);
digitalWrite(outputPin, LOW);
mySwitch.enableTransmit( RCTransmissionPin );
mySwitch.setPulseLength(320);
}

void loop()
{
sensorVal = digitalRead(inputPin);
sensorValue = analogRead(sensorPin);
char* params;
if (params = e.serviceRequest())
{
if (strcmp(params, “?cmd=get_digital_values”) == 0)
{
e.print("1: “);
e.print(digitalRead(1));
e.print(” 2: “);
e.print(digitalRead(2));
e.print(” 3: “);
e.print(digitalRead(3));
e.print(” 4: “);
e.print(digitalRead(4));
e.print(” 5: “);
e.print(digitalRead(5));
e.print(” 6: ");
e.print(digitalRead(6));
}
else if (strcmp(params, “?cmd=get_analog_values”) == 0)
{
e.print("1: “);
e.print(analogRead(A1));
e.print(” 2: “);
e.print(analogRead(A2));
e.print(” 3: “);
e.print(analogRead(A3));
e.print(” 4: “);
e.print(analogRead(A4));
e.print(” 5: “);
e.print(analogRead(A5));
e.print(” 6: ");
e.print(analogRead(A6));
}
else if (strcmp(params, “?cmd=get_sensor_values_all”) == 0)
{
e.print("A1: “);
e.print(analogRead(A1));
e.print(” A2: “);
e.print(analogRead(A2));
e.print(” A3: “);
e.print(analogRead(A3));
e.print(” A4: “);
e.print(analogRead(A4));
e.print(” A5: “);
e.print(analogRead(A5));
e.print(” A6: “);
e.print(analogRead(A6));
e.print(” D1: “);
e.print(digitalRead(1));
e.print(” D2: “);
e.print(digitalRead(2));
e.print(” D3: “);
e.print(digitalRead(3));
e.print(” D4: “);
e.print(digitalRead(4));
e.print(” D5: “);
e.print(digitalRead(5));
e.print(” D6: “);
e.print(digitalRead(6));
e.print(” D7: “);
e.print(digitalRead(7));
e.print(” D8: ");
e.print(digitalRead(8));
}
else if (strcmp(params, “?cmd=set_D2_OFF”) == 0) // Modified
{
digitalWrite(2, LOW);
e.print(“D2:0”);
}
else if (strcmp(params, “?cmd=set_D2_ON”) == 0) // Modified
{
digitalWrite(2, HIGH);
e.print(“D2:1”);
}
else if (strcmp(params, “?cmd=set_D3_OFF”) == 0) // Modified
{
digitalWrite(3, LOW);
e.print(“D3:0”);
}
else if (strcmp(params, “?cmd=set_D3_ON”) == 0) // Modified
{
digitalWrite(3, HIGH);
e.print(“D3:1”);
}
else if (strcmp(params, “?cmd=set_D4_OFF”) == 0) // Modified
{
digitalWrite(4, LOW);
e.print(“D4:0”);
}
else if (strcmp(params, “?cmd=set_D4_ON”) == 0) // Modified
{
digitalWrite(4, HIGH);
e.print(“D4:1”);
}
else if (strcmp(params, “?cmd=set_D5_OFF”) == 0) // Modified
{
digitalWrite(outputPin, LOW);
e.print(“D5:0”);
}
else if (strcmp(params, “?cmd=set_D5_ON”) == 0) // Modified
{
digitalWrite(outputPin, HIGH);
e.print(“D5:1”);
}
else if (strcmp(params, “?cmd=set_D6_OFF”) == 0) // Modified
{
digitalWrite(6, LOW);
e.print(“D6:0”);
}
else if (strcmp(params, “?cmd=set_D6_ON”) == 0) // Modified
{
digitalWrite(6, HIGH);
e.print(“D6:1”);
}
else if (strcmp(params, “?cmd=set_D7_OFF”) == 0) // Modified
{
digitalWrite(7, LOW);
e.print(“D7:0”);
}
else if (strcmp(params, “?cmd=set_D7_ON”) == 0) // Modified
{
digitalWrite(7, HIGH);
e.print(“D7:1”);
}
else
{
e.print("

WebRemote


“);
e.print(params);
e.print(”
Sensorvalue D8: “);
e.print(sensorVal);
e.print(”
");
e.print("Sensorvalue A6: “);
e.print(sensorValue);
e.print(”
“);
if (strcmp(params, “?cmd=on”) == 0)
{
digitalWrite(outputPin, HIGH);
e.print(”
D5 ON
“);
e.print(“Turn off”);
}
else if (strcmp(params, “?cmd=off”) == 0) // Modified
{
digitalWrite(outputPin, LOW);
e.print(”
D5 OFF
“);
e.print(“Turn on”);
}
else if (strcmp(params, “?set_41_ON”) == 0) {
mySwitch.switchOn(1,1);
e.print(”
4,1 ON
“);
} else if (strcmp(params, “?set_41_OFF”) == 0) {
mySwitch.switchOff(1,1);
e.print(”
4,1 OFF
“);
} else if (strcmp(params, “?cmd=set_42_ON”) == 0) {
mySwitch.switchOn(4,2);
e.print(”
4,2 ON
“);
} else if (strcmp(params, “?cmd=set_42_OFF”) == 0) {
mySwitch.switchOff(4,2);
e.print(”
4,2 OFF
“);
}
else if (strcmp(params, “?set_43_ON”) == 0) {
mySwitch.switchOn(4,3);
e.print(”
4,3 ON
“);
} else if (strcmp(params, “?set_43_OFF”) == 0) {
mySwitch.switchOff(4,3);
e.print(”
4,3 OFF
“);
} else if (strcmp(params, “?cmd=set_44_ON”) == 0) {
mySwitch.switchOn(4,4);
e.print(”
4,4 ON
“);
} else if (strcmp(params, “?cmd=set_44_OFF”) == 0) {
mySwitch.switchOff(4,4);
e.print(”
4,4 OFF
");
}
else
{
e.print("Turn off
");
e.print(“Turn on”);
}
}
e.respond();
}
}

Arduino_FHEM.ino (6.19 KB)