PS: dass du da in deinem Controllino 2 zweimal Alarm 4 schickst ist dir bewusst???
ich würde die ganzen Code-Duplikate wegschmeissen,
überhaupt nur einen Code warten wollen und nur vor dem kompilieren festlegen für welches Board das ganze sein soll.
ca so:
#include <Ethernet.h>
#include <SPI.h>
//#include <Controllino.h> // musst du wieder aktivieren
#ifndef CONTROLLINO_A1
#define CONTROLLINO_A1 5 // die brauche ich weil ich keinen Controllino habe
#endif
#ifndef CONTROLLINO_A2
#define CONTROLLINO_A2 6
#endif
#ifndef CONTROLLINO_A3
#define CONTROLLINO_A3 7
#endif
#define USE_BOARD 86 // <-- hier einstellen ob Board 2 oder 3 kompiliert werden soll
#if USE_BOARD == 86 // Einstellungen die für MEIN Board ziehen sollen
byte mac[] = { 0xE8, 0x2A, 0xEA, 0x4B, 0x1F, 0xC3 };
IPAddress localip(172, 18, 67, 86); // Set local IP
const char *message[] = {"Alarm 4", "Alarm 5", "Alarm 6"};
#endif
#if USE_BOARD == 2 // Einstellungen die für dein Board ziehen sollen
// Set MAC adress
byte mac[] = { 0xE8, 0x2A, 0xEA, 0x4B, 0x1F, 0xC3 };
// Set local IP
IPAddress localip(192, 168, 0, 192);
const char *message[] = {"Alarm 4", "Alarm 5", "Alarm 6"}; // Texte die je nach Ausgang versendet werden sollen
#endif
#if USE_BOARD == 3
byte mac[] = { 0xE8, 0x2A, 0xEA, 0x4B, 0x1F, 0xC4 };
IPAddress localip(192, 168, 0, 193); // Set local IP
const char *message[] = {"Alarm 7", "Alarm 8", "Alarm 9"};
#endif
// Set remote IP of server
//IPAddress server(192, 168, 0, 191);
IPAddress server(172, 18, 67, 98);
const uint32_t port = 80; // du 50001
const byte inputPin[] = {CONTROLLINO_A1, CONTROLLINO_A2, CONTROLLINO_A3};
const char *inputClear[] = {"A1", "A2", "A3"}; //Klartext Bezeichnung für die Pins
const byte pins = sizeof(inputPin) / sizeof(inputPin[0]);
EthernetClient client;
void setup() {
Serial.begin(115200);
for (byte current = 0; current < pins; current++)
{
pinMode(inputPin[current], INPUT);
Serial.println(inputPin[current]);
}
//initialize Ethernet
Ethernet.begin(mac, localip);
// Check for Ethernet hardware present
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
while (true) {
delay(1); // do nothing, no point running without Ethernet hardware
}
}
Serial.println(F("started"));
}
void loop() {
//handle local input
int success = 0;
int successP = 0;
for (byte current = 0; current < pins; current++)
{
if (digitalRead(inputPin[current]))
{
Serial.print(inputClear[current]); Serial.print(F(" PIN")); Serial.print(current); Serial.println(F(" == HIGH"));
//connect to server
success = client.connect(server, port);
delay(10);
if (success)
{
Serial.print(F("I: connected ")); Serial.println(success);
//send a message to server
successP = client.println(message[current]);
delay(10);
if (successP)
{
Serial.print(message[current]); Serial.print(F(" sent. ")); Serial.println(successP);
}
else
{
Serial.print(message[current]); Serial.print(F(" not sent. ")); Serial.println(successP);
}
}
else
{
Serial.print(F("E: not connected ")); Serial.println(success);
}
//close TCP connection
client.stop();
delay(1000);
}
}
}
Fehlerbehandlung ist noch keine drinnen, bzw. zeigt dir nur den Status an was passiert. Wenn klar ist was du wann machen willst, kannst du das ja dann ergänzen.
Aufpassen, ich musste ein paar Sachen für mich anpassen, IP-Adressen, Ports etc. sollte aber klar sein.