Bon, j'ai changé quelques trucs, mais ca ne se compile pas et ça dépasse mes compétences!
Pas facile ce langage quand même!
Voici le code avec les modifs:
#include <SPI.h>
#include <EEPROM.h>
#include <Ethernet.h>
#include <EthernetUdp.h>
#include <LiquidCrystal.h>
#include "DHT.h"
#define DHTPIN A0
//#define DHTTYPE DHT11 // DHT 11
#define DHTTYPE DHT22 // DHT 22 (AM2302)
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
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);
EthernetUDP Udp;
// 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 }; //Adresse MAC de l'arduino
byte ip[] = { 192, 168, 0, 150 }; //Adresse ip de l'arduino
unsigned char gateway[] = { 192, 168, 0, 1 }; //Passerelle (Box FAI)
unsigned char mask[] = { 255, 255, 255, 0 }; //Masque de sous-réseau
byte serverdist[] = { 192, 168, 2, 17 };
EthernetServer server(80); //Port
EthernetClient 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";
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 (lient.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);
}
}
Et voici les erreurs:
couveuse:36: error: no matching function for call to 'EthernetClient::EthernetClient(byte [4], int)'
C:\Users\NouNours\Documents\arduino-1.0.3-windows\arduino-1.0.3\libraries\Ethernet/EthernetClient.h:12: note: candidates are: EthernetClient::EthernetClient(uint8_t)
C:\Users\NouNours\Documents\arduino-1.0.3-windows\arduino-1.0.3\libraries\Ethernet/EthernetClient.h:11: note: EthernetClient::EthernetClient()
C:\Users\NouNours\Documents\arduino-1.0.3-windows\arduino-1.0.3\libraries\Ethernet/EthernetClient.h:8: note: EthernetClient::EthernetClient(const EthernetClient&)
couveuse.ino: In function 'float readFloat(int)':
couveuse:70: error: incompatible types in assignment of 'uint8_t' to 'byte [4]'
couveuse.ino: In function 'void writeFloat(float, int)':
couveuse:83: error: invalid conversion from 'byte*' to 'uint8_t'
couveuse:83: error: initializing argument 2 of 'void EEPROMClass::write(int, uint8_t)'
couveuse.ino: In function 'void loop()':
couveuse:148: error: 'lient' was not declared in this scope
couveuse:171: error: 'class EthernetUDP' has no member named 'readPacket'
couveuse:174: error: 'class EthernetUDP' has no member named 'readPacket'
Voila où j'en suis, et même en cherchant sur internet, je ne trouve pas! J'ai modifié pas mal de truc et c'est le minimum d'erreur que j'arrive à avoir.