Salve ragazzi sono dinuovo qui a chiedervi aiuto, devo unire i due sketch di seguito ho provato diverse volte ma non riesco a farli funzionare insieme.
Qualcuno puo' darmi un consiglio
grazie
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xBE };
byte ip[] = { 192 ,168 ,1 ,55 };
byte gateway[] = { 192 ,168 ,1 ,1 };
byte subnet[] = { 255 ,255 ,255 ,0 };
Server server(80);
String readString = String(30);
void setup(){
Ethernet.begin(mac, ip, gateway, subnet);
delay(1000);
pinMode(2, OUTPUT);
digitalWrite(2, HIGH);
pinMode(3, OUTPUT);
digitalWrite(3, HIGH);
pinMode(4, OUTPUT);
digitalWrite(4, HIGH);
pinMode(5, OUTPUT);
digitalWrite(5, HIGH);
pinMode(6, OUTPUT);
digitalWrite(6, HIGH);
pinMode(7, OUTPUT);
digitalWrite(7, HIGH);
pinMode(8, OUTPUT);
digitalWrite(8, HIGH);
pinMode(9, OUTPUT);
digitalWrite(9, HIGH);
Serial.begin(9600);
}
void loop(){
Client client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();
if (readString.length() < 30)
{
readString = readString + c;
}
if (c == '\n') {
Serial.print(readString);
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
if(readString.startsWith("GET /?out=2&status=1"))
{Serial.print("\n 2 HIGH LOW \n");
digitalWrite(2, LOW);
delay(100);
digitalWrite(2, HIGH);
client.print("{\"status\" : \"1\" , \"out\" : \"");
client.print(2);
client.print("\"}");
}
if(readString.startsWith("GET /?out=3&status=1"))
{Serial.print("\n 3 HIGH LOW \n");
digitalWrite(3, LOW);
delay(100);
digitalWrite(3, HIGH);
client.print("{\"status\" : \"1\" , \"out\" : \"");
client.print(3);
client.print("\"}");
}
if(readString.startsWith("GET /?out=4&status=1"))
{Serial.print("\n 4 HIGH LOW \n");
digitalWrite(4, LOW);
delay(100);
digitalWrite(4, HIGH);
client.print("{\"status\" : \"1\" , \"out\" : \"");
client.print(4);
client.print("\"}");
}
if(readString.startsWith("GET /?out=5&status=1"))
{Serial.print("\n 5 HIGH LOW \n");
digitalWrite(5, LOW);
delay(100);
digitalWrite(5, HIGH);
client.print("{\"status\" : \"1\" , \"out\" : \"");
client.print(5);
client.print("\"}");
}
if(readString.startsWith("GET /?out=6&status=1"))
{Serial.print("\n 6 HIGH LOW \n");
digitalWrite(6, LOW);
delay(100);
digitalWrite(6, HIGH);
client.print("{\"status\" : \"1\" , \"out\" : \"");
client.print(6);
client.print("\"}");
}
if(readString.startsWith("GET /?out=7&status=1"))
{Serial.print("\n 7 HIGH \n");
digitalWrite(7, HIGH);
client.print("{\"status\" : \"1\" , \"out\" : \"");
client.print(7);
client.print("\"}");
}
if(readString.startsWith("GET /?out=7&status=0"))
{Serial.print("\n 7 LOW \n");
digitalWrite(7, LOW);
client.print("{\"status\" : \"0\" , \"out\" : \"");
client.print(7);
client.print("\"}");
}
if(readString.startsWith("GET /?out=8&status=1"))
{Serial.print("\n 8 LOW HIGH \n");
digitalWrite(8, LOW);
delay(300);
digitalWrite(8, HIGH);
client.print("{\"status\" : \"1\" , \"out\" : \"");
client.print(8);
client.print("\"}");
}
if(readString.startsWith("GET /?out=9&status=1"))
{Serial.print("\n 9 HIGH LOW \n");
digitalWrite(9, LOW);
delay(100);
digitalWrite(9, HIGH);
client.print("{\"status\" : \"1\" , \"out\" : \"");
client.print(9);
client.print("\"}");
}
if(readString.startsWith("GET /?out=all"))
{
Serial.print("\n OUT ALL\n");
client.print("{\"ip\" : \"192.168.1.55\", ");
client.print("\"devices\" : ");
client.print("[{ \"type\" : \"gate\", \"name\" : \"Luci Sala Pc\", \"out\" : \"");
client.print("2");
client.print("\"}");
client.print(",{ \"type\" : \"gate\", \"name\" : \"Luci Sala 2\", \"out\" : \"");
client.print("3");
client.print("\"}");
client.print(",{ \"type\" : \"gate\", \"name\" : \"Luci Esterne 1\", \"out\" : \"");
client.print("4");
client.print("\"}");
client.print(",{ \"type\" : \"gate\", \"name\" : \"Luci Esterne 2\", \"out\" : \"");
client.print("5");
client.print("\"}");
client.print(",{ \"type\" : \"gate\", \"name\" : \"Luce Ingresso\", \"out\" : \"");
client.print("6");
client.print("\"}");
client.print(",{ \"type\" : \"plug\", \"name\" : \"Luce Scala\", \"out\" : \"");
client.print("7");
client.print("\"}");
client.print(",{ \"type\" : \"gate\", \"name\" : \"Cancello Automatico\", \"out\" : \"");
client.print("8");
client.print("\"}");
client.print(",{ \"type\" : \"door\", \"name\" : \"Cancello Pedonale\", \"out\" : \"");
client.print("9");
client.print("\"}");
client.print("]}");
}
readString="";
client.stop();
}
}
}
}
}
#include <dht11.h>
#include <SPI.h>
#include <Ethernet.h>
#include <dht11.h>
#define DHT11PIN 2 //dichiariamo ad arduino che il sensore è sul pin2
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xBE };
byte ip[] = { 192 ,168 ,1 ,55 };
byte gateway[] = { 192 ,168 ,1 ,1 };
byte subnet[] = { 255 ,255 ,255 ,0 };
Server server(80);
String readString = String(30);
dht11 DHT11; //dichiariamo l'oggetto
void setup(){
Ethernet.begin(mac, ip, gateway, subnet);
delay(1000);
Serial.begin(9600);
}
void loop(){
DHT11.read(DHT11PIN); //legge il valore del pin del sensore
Client client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();
if (readString.length() < 30)
{
readString = readString + c;
}
if (c == '\n') {
Serial.print(readString);
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
if(readString.startsWith("GET /?out=2&status=1"))
{
Serial.print("\n 2 DHT11 \n");
client.print("{\"status\" : \"ok\" , \"value\" : \"");
client.print(DHT11.temperature);
client.print("\"}");
}
if(readString.startsWith("GET /?out=all"))
{
Serial.print("\n OUT ALL\n");
client.print("{\"ip\" : \"192.168.1.55\", ");
client.print("\"devices\" : ");
client.print("[{ \"type\" : \"temperature\", \"name\" : \"temp interna\", \"out\" : \"");
client.print("2");
client.print("\"}");
client.print("]}");
}
readString="";
client.stop();
}
}
}
}
}