Le code :
#include <Arduino.h>
#include <RF12.h>
#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>
#define CRC_POLY 0x31
#define MAX_SENSORS 8
#define DEBUG_OFF
//#define DEBUG
#define REQ_BUF_SZ 50 // taille du buffer utilisé pour capturer les requêtes HTTP
struct Sensor {
byte sensorId;
byte temp;
byte decimalTemp;
byte hygro;
byte resetFlag;
byte weakBatt;
};
Sensor sensors[MAX_SENSORS];
// Adresses du shield Ethernet
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x9D, 0xD2 }; // adresse MAC
IPAddress ip(192, 168, 5, 228); // adresse IP
EthernetServer server(80); // créé un serveur au port 80
File webFile; // le fichier de la page web sur la carte SD
char HTTP_req[REQ_BUF_SZ] = {0}; // buffered HTTP request stored as null terminated string
char req_index = 0; // index into HTTP_req buffer
/*------------------------------------------------------------------------------------SETUP----------------------------------------------------------------------------------*/
void setup()
{
Serial.begin(9600); // initialisation du moniteur série
pinMode(10, OUTPUT);
digitalWrite(10, HIGH);
Serial.println("Initialisation de la carte SD...");
if (!SD.begin(4)) {
Serial.println("ERREUR - Initialisation de la carte SD impossible!"); // initialisation ratée
return;
}
Serial.println("OK - Carte SD initialisee.");
Serial.println("");
Serial.println("SUCCESS - SD card initialized.");
// check for index.htm file
if (!SD.exists("index.htm")) {
Serial.println("ERROR - Can't find index.htm file!");
return; // can't find index file
}
Serial.println("SUCCESS - Found index.htm file.");
Ethernet.begin(mac, ip); // initialisation Ethernet
server.begin(); // start to listen for clients
// Overide settings for RFM01/IT+ compliance
rf12_initialize(1, RF12_868MHZ, 0xd4);
rf12_initialize_overide_ITP();
#ifdef DEBUG
Serial.println("Initialisation du RF12...");
Serial.println("OK - RF12 initialise.");
Serial.println("");
#endif
}
/*------------------------------------------------------------------------------------LOOP----------------------------------------------------------------------------------*/
void loop()
{
delay(500);
EthernetClient client = server.available(); // try to get client
if (client) { // got client?
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) { // client data available to read
char c = client.read(); // read 1 byte (character) from client
// buffer first part of HTTP request in HTTP_req array (string)
// leave last element in array as 0 to null terminate string (REQ_BUF_SZ - 1)
if (req_index < (REQ_BUF_SZ - 1)) {
HTTP_req[req_index] = c; // save HTTP request character
req_index++;
}
// last line of client request is blank and ends with \n
// respond to client only after last line received
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
// remainder of header follows below, depending on if
// web page or XML page is requested
// Ajax request - send XML file
if (StrContains(HTTP_req, "ajax_inputs")) {
// send rest of HTTP header
client.println("Content-Type: text/xml");
client.println("Connection: keep-alive");
client.println();
// send XML file containing input states
XML_response(client);
webFile = SD.open("index.htm");
}
else if (StrContains(HTTP_req, "GET /nuage.png")) {
webFile = SD.open("nuage.png");
if (webFile) {
client.println("HTTP/1.1 200 OK");
client.println();
}
else { // web page request
// send rest of HTTP header
client.println("Content-Type: text/html");
client.println("Connection: keep-alive");
client.println();
// send web page
webFile = SD.open("index.htm"); // open web page file
delay(1000);//debug
Serial.println (webFile);//debug
if (webFile) {
Serial.println ("index.htm ouvert");//debug
while(webFile.available()) {
client.write(webFile.read()); // send web page to client
}
webFile.close();
}
}
// display received HTTP request on serial port
Serial.print(HTTP_req);
// reset buffer index and all buffer elements to 0
req_index = 0;
StrClear(HTTP_req, REQ_BUF_SZ);
break;
}
// every line of text received from the client ends with \r\n
if (c == '\n') {
// last character on line of received text
// starting new line with next character read
currentLineIsBlank = true;
}
else if (c != '\r') {
// a text character was received from client
currentLineIsBlank = false;
}
} // end if (client.available())
} // end while (client.connected())
delay(1); // give the web browser time to receive the data
client.stop(); // close the connection
} // end if (client)
}
Et l'image de l'erreur Screenshot - a35dbd6eaa928a1d1e9b5d1d0b3e3d05 - Gyazo
Et Uzuma la librairie est bien installé comme je l'ai dis j'ai tout mis comme l'autre ordi ![]()