Couveuse pilotée par pc

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 :slight_smile:

#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); _
_
}_
_
}_
_
[/quote]*_