Hallo,
ich habe folgendes Setup:
Arduino Uno R3 + W5100 Ethernet Shield
4 Relais
2 DS18B20
folgenden Sketch:
#include <OneWire.h>
#include <SPI.h>
#include <Ethernet.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS_1 A0
#define ONE_WIRE_BUS_2 A1
//#define ONE_WIRE_BUS_3 A2
OneWire oneWire_1(ONE_WIRE_BUS_1);
OneWire oneWire_2(ONE_WIRE_BUS_2);
//OneWire oneWire_3(ONE_WIRE_BUS_3);
DallasTemperature temp1(&oneWire_1);
DallasTemperature temp2(&oneWire_2);
//DallasTemperature temp3(&oneWire_3);
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 2, 16 }; // IP address in LAN – need to change according to your Network address
byte gateway[] = { 192, 168, 2, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(80); //server port
String readString;
int relay1 = 2;
int relay2 = 3;
int relay3 = 5;
int relay4 = 6;
void setup(){
Serial.begin(9600);
temp1.begin();
temp2.begin();
//temp3.begin();
pinMode(relay1, OUTPUT);
pinMode(relay2, OUTPUT);
pinMode(relay3, OUTPUT);
pinMode(relay4, OUTPUT);
digitalWrite(relay1, HIGH);
digitalWrite(relay2, HIGH);
digitalWrite(relay3, HIGH);
digitalWrite(relay4, HIGH);
delay(750);
//start Ethernet
Ethernet.begin(mac, ip, gateway, subnet);
server.begin();
}
void loop(){
temp1.requestTemperatures();
temp2.requestTemperatures();
//temp3.requestTemperatures();
EthernetClient client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();
//read char by char HTTP request
if (readString.length() < 100) {
//store characters to string
readString += c;
}
//if HTTP request has ended– 0x0D is Carriage Return \n ASCII
if (c == 0x0D) {
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/xml");
client.println("Connnection: close");
client.println();
client.print("<status>");
client.print("<temp1>");
client.print(temp1.getTempCByIndex(0));
client.print("</temp1>");
client.print("<temp2>");
client.print(temp2.getTempCByIndex(0));
client.print("</temp2>");
//client.print("<temp3>");
//client.print(temp3.getTempCByIndex(0));
//client.print("</temp3>");
client.print("<relay1>");
if (digitalRead(relay1)) {
client.print("0");
}
else {
client.print("1");
}
client.print("</relay1>");
client.print("<relay2>");
if (digitalRead(relay2)) {
client.print("0");
}
else {
client.print("1");
}
client.print("</relay2>");
client.print("<relay3>");
if (digitalRead(relay3)) {
client.print("0");
}
else {
client.print("1");
}
client.print("</relay3>");
client.print("<relay4>");
if (digitalRead(relay4)) {
client.print("0");
}
else {
client.print("1");
}
client.print("</relay4>");
client.print("</status>");
delay(10);
client.stop();
// control arduino pin
if(readString.indexOf("?relay1on") > -1)
{
digitalWrite(relay1, LOW);
}
else{
if(readString.indexOf("?relay1off") > -1)
{
digitalWrite(relay1, HIGH);
}
}
if(readString.indexOf("?relay2on") > -1)
{
digitalWrite(relay2, LOW);
}
else{
if(readString.indexOf("?relay2off") > -1)
{
digitalWrite(relay2, HIGH);
}
}
if(readString.indexOf("?relay3on") > -1)
{
digitalWrite(relay3, LOW);
}
else{
if(readString.indexOf("?relay3off") > -1)
{
digitalWrite(relay3, HIGH);
}
}
if(readString.indexOf("?relay4on") > -1)
{
digitalWrite(relay4, LOW);
}
else{
if(readString.indexOf("?relay4off") > -1)
{
digitalWrite(relay4, HIGH);
}
}
//clearing string for next read
readString="";
}
}
}
}
}
gesteuert und protokolliert wird dann alles über OpenHAB2.
Jetzt habe ich folgendes Problem, nach ca 15 Schaltvorgängen der Relais friert der Arduino + W5100 ein und ich kann nicht mehr darauf zugreifen.
Hat jemand vielleicht ein Idee warum?
Viel Dank schon mal