/*****
- COMPILARE CON ARDUINO 1.0 o successive
******/
#include <String.h>
#include <SPI.h>
#include <Ethernet.h>
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is plugged into pin 2 on the Arduino
#define ONE_WIRE_BUS 6
// Setup a oneWire instance to communicate with any OneWire devices
// (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
///////////////////////////////////////////////////////////////////
byte mac[] = {
0x00, 0xAA, 0xBB, 0xCC, 0xDA, 0x02 }; // mac address
byte ip[] = {
192,168,1,7 }; // ip arduino internet in
byte gateway[] = {
192,168,1,1 }; // internet access via router
byte subnet[] = {
255, 255, 255, 0 }; //subnet mask
EthernetServer server(80); //server port
//definizione attuatori
int outPin = 2; // pin attuatore cancello
int outPin2 = 3; // pin attuatore tenda su
int outPin3 = 4; // pin attuatore tenda giu
int outPin4 = 5; // pin attuatore tenda metà
int outPin5 = 7; // pin controllo canale
int C = 5; // Variabile canale
int X = 3;
int Z=0;
String readString; // legge int e assegna l'uscita
void setup()
{
Ethernet.begin(mac, ip, gateway, subnet);
pinMode(outPin, OUTPUT); //definisce che il pin e' un uscita
pinMode(outPin2, OUTPUT);
pinMode(outPin3, OUTPUT);
pinMode(outPin4, OUTPUT);
pinMode(outPin5, OUTPUT);
//Serial.begin(9600);
// start serial port
//Serial.begin(9600);
//Serial.println("Dallas Temperature IC Control Library Demo");
// Start up the library
sensors.begin();
}
void rele_ch()
{ digitalWrite(7,HIGH);
delay(500);
}
void rele_cd()
{ digitalWrite(7,LOW);
delay(500);
}
void loop()
{
Z=0;
// call sensors.requestTemperatures() to issue a global temperature
// request to all devices on the bus
//Serial.print(" Requesting temperatures...");
sensors.requestTemperatures(); // Send the command to get temperatures
//Serial.println("DONE");
//Serial.print("Temperature for Device 1 is: ");
sensors.getTempCByIndex(0); // Why "byIndex"?
// You can have more than one IC on the same bus.
// 0 refers to the first IC on the wire
/inizio client/
EthernetClient client = server.available();
if (client) {
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
readString.concat(c); //store characters to string
//if HTTP request has ended
if (c == '\n' && currentLineIsBlank) {
if(readString.indexOf("D=1") > 0)
{
C=1; // CONTROLLO CANALE
}
if(readString.indexOf("S=1") > 0)
{
C=2; // CONTROLLO CANALE
}
if(readString.indexOf("E=1") > 0)
{
C=6; // CONTROLLO CANALE
}
if(C==1) // Cambio del canale
{
rele_ch();
rele_cd();
rele_ch();
rele_cd();
C=7;
X=1;
Z=1;
}
if(C==2)
{
rele_ch();
rele_cd();
rele_ch();
rele_cd();
rele_ch();
rele_cd();
C=8;
X=2;
Z=1;
}
if(C==6)
{
if(X==1)
{
rele_ch();
rele_cd();
rele_ch();
rele_cd();
rele_ch();
rele_cd();
rele_ch();
rele_cd();
rele_ch();
rele_cd();
C=9;
X=3;
Z=1;
}
else
{
rele_ch();
rele_cd();
rele_ch();
rele_cd();
rele_ch();
rele_cd();
rele_ch();
rele_cd();
C=9;
X=3;
Z=1;
}
}
if(readString.indexOf("L=1") > 0)
{
digitalWrite(outPin, HIGH); // CONTROLLO CANCELLO
//Serial.println(outPin);
delay(1000);
digitalWrite(outPin, LOW);
Z=1;
}