#include <WiFi.h>
#include <Wire.h> // Inclure Bibliothèque Wire
#include <SPI.h> // Inclure Bibliothèque SPI
#include <SD.h> // Inclure Bibliothèque SD
char ssid[] = "dlink"; // le nom du réseau (SSID)
char pass[] = "sti2dsin"; // mot de passe du SSID
int status = WL_IDLE_STATUS; //écriture d'une variable qui met un statut "au repos"
WiFiServer server(80);
const int chipSelect = 4;
float valr =0;
int flghtm=0;
//Local ethernet setup
char rootFileName[] = "index.htm"; // Page de d'accueil
// Écouter si un client essaye de se connecter
WiFiClient client = server.available();
// Configuration de la card SD
Sd2Card card;
SdVolume volume;
SdFile root;
SdFile file;
#define error(s) error_P(PSTR(s))
#define BUFSIZ 48
void error_P(const char* str) {
PgmPrint("error: ");
SerialPrintln_P(str);
if (card.errorCode()) {
PgmPrint("SD error: ");
Serial.print(card.errorCode(), HEX);
Serial.print(',');
Serial.println(card.errorData(), HEX);
}
while(1);
}
void setup() {
//Initialisation en série et attends pour le port à ouvrir:
Serial.begin(9600);
// vérifie la presence du shield:
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield pas present");
// ne pas continuer:
while(true);
}
// tentative de connection au réseau wifi:
while ( status != WL_CONNECTED) {
Serial.print("tentative de connection au ssid: ");
Serial.println(ssid);
// connection au réseau.
status = WiFi.begin(ssid, pass);
// attends 10 secondes pour la connexion:
delay(10000);
}
server.begin();
// vous êtes connecté maintenant, affiche le statut:
printWifiStatus();
Wire.begin(); //Configure la carte Arduino pour utiliser les fonctions I2C
PgmPrint("Free RAM: ");
Serial.println(FreeRam());
// pinMode(10, OUTPUT);
// digitalWrite(10, HIGH);
if (!card.init(SPI_HALF_SPEED, 4)) error("card.init failed!");
if (!volume.init(&card)) error("vol.init failed!");
PgmPrint("Volume is FAT");
Serial.println(volume.fatType(),DEC);
Serial.println();
if (!root.openRoot(&volume)) error("openRoot failed");
PgmPrintln("Files found in root:");
root.ls(LS_DATE | LS_SIZE);
Serial.println();
PgmPrintln("Files found in all dirs:");
root.ls(LS_R);
Serial.println();
PgmPrintln("Done");
WiFi.begin(ssid,pass);
server.begin();
Serial.begin (9600);
}
//////////////////////////////////////
void loop()
{
int S = 0; // Variable pour le stockage de la valeur analogique
int PA0 = 0; //Numéro du port analogique sur lequel la son est mesurée
S = analogRead(PA0); //
int T = 0; // Variable pour le stockage de la valeur numerique
int PA9 = 0; //Numéro du port analogique sur lequel la température est mesurée
T = digitalRead(9);
T = 15, S = 10;
char clientline[BUFSIZ];
char *filename;
int image = 0;
int index = 0;
WiFiClient client = server.available();
if (client) {
boolean current_line_is_blank = true;
index = 0;
while (client.connected()) {
if (client.available()) {
char c = client.read();
if (c != '\n' && c != '\r') {
clientline[index] = c;
index++;
if (index >= BUFSIZ)
index = BUFSIZ -1;
continue;
}
clientline[index] = 0;
filename = 0;
Serial.println(clientline);
if (strstr(clientline, "GET / ") != 0) // si ligne de commande reçue contient "GET / "
{
filename = rootFileName; // on envoie le fichier index.htm
flghtm = 1;
}
else
{
flghtm = 0;
}
Serial.print("flghtm : ");
Serial.print(flghtm);
Serial.print(" ");
if (strstr(clientline, "GET /") != 0)
{
if (!filename) filename = clientline + 5;
(strstr(clientline, " HTTP"))[0] = 0;
Serial.println(filename);
if (! file.open(&root, filename, O_READ)) {
client.println("HTTP/1.1 404 Not Found");
client.println("Content-Type: text/html");
client.println();
client.println("<h2>Error 404</h2>");
client.println("<s2>The file does not exist.<s2>");
client.println("");
break;
}
Serial.println("Opened!");
//File types
client.println("HTTP/1.1 200 OK");
if (strstr(filename, ".htm") != 0)
client.println("Content-Type: text/html");
else if (strstr(filename, ".css") != 0)
client.println("Content-Type: text/css");
else if (strstr(filename, ".png") != 0)
client.println("Content-Type: image/png");
else if (strstr(filename, ".jpg") != 0)
client.println("Content-Type: image/jpeg");
else if (strstr(filename, ".gif") != 0)
client.println("Content-Type: image/gif");
else if (strstr(filename, ".3gp") != 0)
client.println("Content-Type: video/mpeg");
else if (strstr(filename, ".pdf") != 0)
client.println("Content-Type: application/pdf");
else if (strstr(filename, ".js") != 0)
client.println("Content-Type: application/x-javascript");
else if (strstr(filename, ".xml") != 0)
client.println("Content-Type: application/xml");
else
client.println("Content-Type: text");
client.println();
int16_t c;
while ((c = file.read()) >= 0) {
if ((c==0xff)&&(flghtm==1)) // Variable Analogique Son(15)
{client.print(S);
}
if ((c==0xfe)&&(flghtm==1)) // Variable Numerique Temperature(14)
{client.print(T);
}
else
{
//Serial.print((char)c); //Prints all HTML code to serial (For debuging)
client.print((char)c); //Prints all HTML code for web page
}
}
file.close();
}
else {
client.println("HTTP/1.1 404 Not Found");
client.println("Content-Type: text/html");
client.println();
client.println("<h2>Error 404</h2>");
client.println("");
}
break;
}
}
client.stop();
}
}
void printWifiStatus() {
// affiche le SSID du réseau auquel on est attaché
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// affiche l'adresse IP du wifi shield
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
// affiche la force du signal reçu:
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");
}
mais lorsque je charge avec mozilla l'adresse ip généré rien ne charge...
quelqu'un sais comment afficher cet page web ???
merci beaucoup d'avoir lu mon pavé ![]()