voila le pde, j'ai rajouté la détection de présence en cas d'éclosion, mais le bout de code n'y figure pas encore
#include <EEPROM.h>
#include <SPI.h> // needed for Arduino versions later than 0018
#include <Ethernet.h>
#include <Client.h>
#include <LiquidCrystal.h>
#include <Udp.h> // UDP library from:
bjoern@cs.stanford.edu 12/30/2008
#include "DHT.h"
#define DHTPIN A0
int ventilo = 8; // led
int resistance = 9; // led
const int buttonPin = A1; // the number of the pushbutton pin
const int ledPin = 12; // the number of the LED pin
long previousMillis = 0; // will store last time LED was updated
long interval = 10000; // interval at which to blink (milliseconds)
int i=0;
int buttonState = 0; // variable for reading the pushbutton status
LiquidCrystal lcd1(7, 6, 5, 4, 3, 2);
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = {
192,168,2,200 };
unsigned char gateway[] = {
192,168,2,2 };
unsigned char mask[] = {
255,255,255,0};
byte serverdist[] = { 192,168,2,17 };
Server server(80);
Client client(serverdist, 80);
unsigned int localPort = 80; // local port to listen on
float tempmini;
float tempmaxi;
// the next two variables are set when a packet is received
byte remoteIp[4]; // holds received packet's originating IP
unsigned int remotePort; // holds received packet's originating port
// buffers for receiving and sending data
char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet,
char packetBuffer1[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet,
char ReplyBuffer[] = "acknowledged"; // a string to send back
char ReplyBuffer1[] = "acknowledged"; // a string to send back
const char toto[]="123";
#define DHTTYPE DHT21 // DHT 21 (AM2301)
DHT dht(DHTPIN, DHTTYPE);
int address = 0;
byte value;
float tempminimem;
float tempmaximem;
// Utilities for writing and reading from the EEPROM
float readFloat(int address) {
union floatStore {
byte floatByte[4];
float floatVal;
}
floatOut;
for (int i = 0; i < 4; i++)
floatOut.floatByte
= EEPROM.read(address + i);
return floatOut.floatVal;
}
void writeFloat(float value, int address) {
union floatStore {
byte floatByte[4];
float floatVal;
}
floatIn;
floatIn.floatVal = value;
for (int i = 0; i < 4; i++)
EEPROM.write(address + i, floatIn.floatByte);
}
void setup() {
// start the Ethernet and UDP:
Ethernet.begin(mac, ip, gateway, mask);
Udp.begin(localPort);
dht.begin();
Serial.begin(9600);
pinMode(ventilo, OUTPUT);
pinMode(resistance, OUTPUT);
server.begin();
lcd1.begin(16, 2);
tempminimem = readFloat(address);
Serial.print("tempminimem :");
Serial.println(tempminimem);
tempmini=tempminimem;
tempmaximem = readFloat(address+4);
Serial.print("tempmaximem :");
Serial.println(tempmaximem);
tempmaxi=tempmaximem;
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}
void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
unsigned long currentMillis = millis();
// turn LED on:
digitalWrite(ledPin, HIGH);
Serial.println("intrusion");
i++;
Serial.println(i);
if(i>500){
digitalWrite(ledPin, HIGH);
}
}
else {
// turn LED off:
digitalWrite(ledPin, LOW);
}
if (i>520){i=0;}
float h = dht.readHumidity();
float t = dht.readTemperature();
t=t-1;
// if there's data available, read a packet
int packetSize = Udp.available(); // note that this includes the UDP header
if(packetSize)
{
if (client.connect()) {
delay(2000);
Serial.println("connected");
Serial.print(t);
client.print("GET /recup.php?temp=");
client.print(t);
client.print("&humid=");
client.print(h);
client.print("\n");
client.stop();
}
packetSize = packetSize - 8; // subtract the 8 byte header
Serial.print("Received packet of size ");
Serial.println(packetSize);
memset(packetBuffer, 0, UDP_TX_PACKET_MAX_SIZE);
memset(packetBuffer1, 0, UDP_TX_PACKET_MAX_SIZE);
// read the packet into packetBufffer and get the senders IP addr and port number
Udp.readPacket(packetBuffer,UDP_TX_PACKET_MAX_SIZE, remoteIp, remotePort);
Serial.println("Contents:");
Serial.println(packetBuffer);
Udp.readPacket(packetBuffer1,UDP_TX_PACKET_MAX_SIZE, remoteIp, remotePort);
Serial.println("Contents1:");
Serial.println(packetBuffer1);
//tempmini = float (atoi(packetBuffer));
//tempmaxi = float (atoi(packetBuffer1));
tempmini = atof(packetBuffer);
tempmaxi = atof(packetBuffer1);
writeFloat(tempmini,address);
writeFloat(tempmaxi,address+4);
Serial.print("tempmini : ");
Serial.println(tempmini);
Serial.print("tempmaxi : ");
Serial.println(tempmaxi);
analogWrite(11, atoi(packetBuffer)); //utiliser la valeur reçu pour allumer la led
analogWrite(12, atoi(packetBuffer1)); //utiliser la valeur reçu pour allumer la led
//Udp.sendPacket(ReplyBuffer1, IP, localPort);
//Udp.sendPacket(toto, remoteIp, localPort );
}
delay(2);
// float h = dht.readHumidity();
// float t = dht.readTemperature();
// t=t-1;
if (t < tempmini){
digitalWrite(ventilo,1);
digitalWrite(resistance,1);
}
else if(t > tempmaxi){
digitalWrite(ventilo,1);
digitalWrite(resistance,0);
}
else{
digitalWrite(ventilo,0);
digitalWrite(resistance,0);
}
if (isnan(t) || isnan(h)) {
Serial.println("Failed to read from DHT");
}
else {
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t);
Serial.println(" *C");
Serial.print("Tempmini: ");
Serial.print(tempmini);
Serial.println(" *C");
Serial.print("Tempmaxi: ");
Serial.print(tempmaxi);
Serial.println(" *C");
lcd1.setCursor(0, 0);
lcd1.print("H:");
lcd1.print(h);
lcd1.print("%");
lcd1.print("Mi:");
lcd1.print(tempmini);
;
lcd1.setCursor(0, 1);
lcd1.print("T:");
lcd1.print(t);
lcd1.print("C");
lcd1.print("Ma:");
lcd1.print(tempmaxi);
}
}