vous l'avez acheté quand? si vous regardez leur documentation ça date de 2010... pas sûr que les libarairies actuelles soient prévues pour...
la carte "à jour" du moment c'est plutôt ARDUINO ETHERNET SHIELD 2

vous l'avez acheté quand? si vous regardez leur documentation ça date de 2010... pas sûr que les libarairies actuelles soient prévues pour...
la carte "à jour" du moment c'est plutôt ARDUINO ETHERNET SHIELD 2

bon je vais acheter une carte r2 et faire des tests
je relance la conversation dès que je la reçois
en tous cas merci pour l'aide
Pas sûr à 100% que ce soit votre soucis mais difficile à débogguer comme cela
éventuellemnt essaez en forçant à la main le HIGH et LOW sur les CS
j'ai acheté et tester avec le shield r2 que tu m'as indiqué mais meme en forcant les pattes à low
rien ne marche ![]()
par contre avec ce code j'affiche l'image sur une page web, mais comment alors ajouter le codage html permettant d'afficher mon tableau avec la valeur des capteurs ?
#include <SPI.h> //bibliothèqe pour SPI
#include <Ethernet2.h> //bibliothèque pour Ethernet
#include <SD.h>
byte mac[] = {0x90, 0xA2, 0xDA, 0x11, 0x1D, 0x60}; // tableau pour l'adresse MAC de votre carte
EthernetServer server(80);
String readString;
//////////////////////
void setup(){
Serial.begin(9600);
// disable w5100 while setting up SD
pinMode(10,OUTPUT);
digitalWrite(10,HIGH);
Serial.print("Starting SD..");
if(!SD.begin(4)) Serial.println("failed");
else Serial.println("ok");
Ethernet.begin(mac);
digitalWrite(10,HIGH);
//delay(2000);
server.begin();
Serial.println("Ready");
}
void loop(){
// Create a client connection
EthernetClient client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();
//read char by char HTTP request
if (readString.length() < 100) {
//store characters to string
readString += c;
//Serial.print(c);
}
//if HTTP request has ended
if (c == '\n') {
///////////////
Serial.println(readString); //print to serial monitor for debuging
client.println("HTTP/1.1 200 OK"); //send new page
client.println("Content-Type: image/jpeg");
client.println();
File myFile = SD.open("ruche.JPG");
if (myFile) {
//Serial.println("test.txt:");
// read from the file until there's nothing else in it:
while (myFile.available()) {
client.write(myFile.read());
}
// close the file:
myFile.close();
}
delay(1);
//stopping client
client.stop();
readString="";
//}
}
}
}
}
}
Donc ça fonctionne bien puisque ça lit sur la carte SD
Ce qui est sur la carte SD est statique donc si vous voulez injecter des données dynamiquement ensuite il faut passer par JavaScrip / AJAX
J’ai un début de tuto: techniques "avancées" de serveur web sur ESP8266, globalement ce que je décris fonctionnerait de la même façon avec une carte SD au lieu de lire dans le SPIFFS
Bon, alors j'ai lu pas mal de ressources dont celle que tu m'a indiquée.
j'ai donc bricolé deux codes un sur la carte sd et un sur l'arduino (mega car besoin de memoire)
l'idée c'est d'afficher une page avec
un dessin "ruche.jpg"
une photo "PIC00.jpg" qui s'actualise à chaque rechargement de la page
et l'état de trois capteurs analogiques
le problème est que sur les premières connexions je n'arrive à avoir que le dessin ruche (quelquefois l'état des capteurs) et une fois j'ai eu la photo prise par la caméra et au bout de quelques minutes la page plante
html code
<!DOCTYPE html>
<html>
<head>
<META HTTP-EQUIV=Refresh CONTENT=60>
<title>Arduino Web Page</title>
</META>
<script>
function GetSwitchState()
{
nocache = "&nocache=" + Math.random() * 1000000;
var request = new XMLHttpRequest();
request.onreadystatechange = function()
{
if (this.readyState == 4) {
if (this.status == 200) {
if (this.responseText != null) {
document.getElementById("switch_txt").innerHTML = this.responseText;
}
}
}
}
request.open("GET", "ajax_switch" + nocache, true);
request.send(null);
setTimeout('GetSwitchState()', 1000);
}
</script>
</head>
<body onload="GetSwitchState()">
<span style=font-family: Courier New,Courier,monospace;></span>
<table style=text-align: left; width: 1251px; height: 119px; border=1cellpadding=2 cellspacing=2>
<tbody>
<tr>
<td style=width: 30%; colspan=1 rowspan=3><img src="ruche.jpg" /></td>
</tr>
<tr>
<td id="switch_txt">Switch state: Not requested...</td>
<td style=width: 40%; colspan=1 rowspan=3><img src="PIC00.jpg" /></td>
</tr>
</tbody>
</table>
#include <SPI.h>
#include <arduino.h>
#include <Ethernet2.h>
#include <SD.h>
#define PIC_PKT_LEN 128 //data length of each read, dont set this too big because ram is limited
#define PIC_FMT_VGA 7
#define PIC_FMT_CIF 5
#define PIC_FMT_OCIF 3
#define CAM_ADDR 0
#define CAM_SERIAL Serial
#define PIC_FMT PIC_FMT_VGA
#define REQ_BUF_SZ 20
File myFile;
int n = 0;
const byte cameraAddr = (CAM_ADDR << 5);
unsigned long picTotalLen = 0;
int picNameNum = 0;
byte mac[] = {0x90, 0xA2, 0xDA, 0x11, 0x1D, 0x60};
EthernetServer server(80); // create a server at port 80
File webFile;
char HTTP_req[REQ_BUF_SZ] = {0}; // buffered HTTP request stored as null terminated string
char req_index = 0; // index into HTTP_req buffer
int temperature;
int masse;
int effectif;
void setup()
{
// disable Ethernet chip
pinMode(53, OUTPUT);
digitalWrite(53, HIGH);
Serial.begin(115200); // for debugging
// initialize SD card
Serial.println("Initializing SD card...");
if (!SD.begin(4)) {
Serial.println("ERROR - SD card initialization failed!");
return; // init failed
}
Serial.println(F("SUCCESS - SD card initialized."));
// check for index.htm file
if (!SD.exists("essai.htm")) {
Serial.println("ERROR - Can't find essai.htm file!");
return; // can't find index file
}
Serial.println("SUCCESS - Found essai.htm file.");
initialize();
Ethernet.begin(mac); // initialize Ethernet device
server.begin(); // start to listen for clients
Serial.println(Ethernet.localIP());
Serial.print(" Default Gateway: ");
Serial.println( Ethernet.gatewayIP());
Serial.print(" Subnet Mask: ");
Serial.println( Ethernet.subnetMask());
Serial.print(" DNS Server: ");
Serial.println( Ethernet.dnsServerIP());
pinMode(A0,INPUT);
pinMode(A1,INPUT);
pinMode(A2,INPUT);
}
void loop()
{
temperature = analogRead (A0);
masse = analogRead (A1);
effectif = analogRead (A2);
Serial.println("\r\nbegin to take picture");
delay(200);
if (n == 0) preCapture();
Capture();
GetData();
Serial.print("\r\nTaking pictures success ,number : ");
Serial.println(n);
n=n+1;
delay(50);
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) {
// open requested web page file
if (StrContains(HTTP_req, "GET / ")|| StrContains(HTTP_req, "GET /essai.htm")) {
client.println(F("HTTP/1.1 200 OK"));
client.println(F("Content-Type: text/html"));
client.println(F("Connnection: close"));
client.println();
webFile = SD.open(F("essai.htm")); // open web page file
}
if (StrContains(HTTP_req, "ajax_switch")) {
GetSwitchState(client);
}
else if (StrContains(HTTP_req, "GET /ruche.jpg")) {
webFile = SD.open("ruche.jpg");
if (webFile) {
client.println(F("HTTP/1.1 200 OK"));
client.println();
}
}
if (StrContains(HTTP_req, "GET /PIC00.jpg")) {
webFile = SD.open("PIC00.jpg");
if (webFile) {
client.println(F("HTTP/1.1 200 OK"));
client.println();
}
}
if (webFile) {
while(webFile.available()) {
client.write(webFile.read()); // send web page to client
}
webFile.close();
}
// 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)
delay(10000);
}
void GetSwitchState(EthernetClient c1)
{
c1.print("temperature: ");
c1.println(temperature);
c1.print("masse: ");
c1.println(masse);
c1.print("effectif: ");
c1.println(effectif);
}
// sets every element of str to 0 (clears array)
void StrClear(char *str, char length)
{
for (int i = 0; i < length; i++) {
str[i] = 0;
}
}
// searches for the string sfind in the string str
// returns 1 if string found
// returns 0 if string not found
char StrContains(char *str, char *sfind)
{
char found = 0;
char index = 0;
char len;
len = strlen(str);
if (strlen(sfind) > len) {
return 0;
}
while (index < len) {
if (str[index] == sfind[found]) {
found++;
if (strlen(sfind) == found) {
return 1;
}
}
else {
found = 0;
}
index++;
}
return 0;
}
void clearRxBuf()
{
while (Serial.available())
{
Serial.read();
}
}
/*********************************************************************/
void sendCmd(char cmd[], int cmd_len)
{
for (char i = 0; i < cmd_len; i++) Serial.print(cmd[i]);
}
/*********************************************************************/
void initialize()
{
char cmd[] = {0xaa,0x0d|cameraAddr,0x00,0x00,0x00,0x00} ;
unsigned char resp[6];
Serial.setTimeout(500);
while (1)
{
//clearRxBuf();
sendCmd(cmd,6);
if (Serial.readBytes((char *)resp, 6) != 6)
{
continue;
}
if (resp[0] == 0xaa && resp[1] == (0x0e | cameraAddr) && resp[2] == 0x0d && resp[4] == 0 && resp[5] == 0)
{
if (Serial.readBytes((char *)resp, 6) != 6) continue;
if (resp[0] == 0xaa && resp[1] == (0x0d | cameraAddr) && resp[2] == 0 && resp[3] == 0 && resp[4] == 0 && resp[5] == 0) break;
}
}
cmd[1] = 0x0e | cameraAddr;
cmd[2] = 0x0d;
sendCmd(cmd, 6);
Serial.println("\nCamera initialization done.");
}
}
/*********************************************************************/
void preCapture()
{
char cmd[] = { 0xaa, 0x01 | cameraAddr, 0x00, 0x07, 0x00, PIC_FMT };
unsigned char resp[6];
Serial.setTimeout(100);
while (1)
{
clearRxBuf();
sendCmd(cmd, 6);
if (Serial.readBytes((char *)resp, 6) != 6) continue;
if (resp[0] == 0xaa && resp[1] == (0x0e | cameraAddr) && resp[2] == 0x01 && resp[4] == 0 && resp[5] == 0) break;
}
}
void Capture()
{
char cmd[] = { 0xaa, 0x06 | cameraAddr, 0x08, PIC_PKT_LEN & 0xff, (PIC_PKT_LEN>>8) & 0xff ,0};
unsigned char resp[6];
Serial.setTimeout(100);
while (1)
{
clearRxBuf();
sendCmd(cmd, 6);
if (Serial.readBytes((char *)resp, 6) != 6) continue;
if (resp[0] == 0xaa && resp[1] == (0x0e | cameraAddr) && resp[2] == 0x06 && resp[4] == 0 && resp[5] == 0) break;
}
cmd[1] = 0x05 | cameraAddr;
cmd[2] = 0;
cmd[3] = 0;
cmd[4] = 0;
cmd[5] = 0;
while (1)
{
clearRxBuf();
sendCmd(cmd, 6);
if (Serial.readBytes((char *)resp, 6) != 6) continue;
if (resp[0] == 0xaa && resp[1] == (0x0e | cameraAddr) && resp[2] == 0x05 && resp[4] == 0 && resp[5] == 0) break;
}
cmd[1] = 0x04 | cameraAddr;
cmd[2] = 0x1;
while (1)
{
clearRxBuf();
sendCmd(cmd, 6);
if (Serial.readBytes((char *)resp, 6) != 6) continue;
if (resp[0] == 0xaa && resp[1] == (0x0e | cameraAddr) && resp[2] == 0x04 && resp[4] == 0 && resp[5] == 0)
{
Serial.setTimeout(1000);
if (Serial.readBytes((char *)resp, 6) != 6)
{
continue;
}
if (resp[0] == 0xaa && resp[1] == (0x0a | cameraAddr) && resp[2] == 0x01)
{
picTotalLen = (resp[3]) | (resp[4] << 8) | (resp[5] << 16);
Serial.print("picTotalLen:");
Serial.println(picTotalLen);
break;
}
}
}
}
/*********************************************************************/
void GetData()
{
unsigned int pktCnt = (picTotalLen) / (PIC_PKT_LEN - 6);
if ((picTotalLen % (PIC_PKT_LEN-6)) != 0) pktCnt += 1;
char cmd[] = { 0xaa, 0x0e | cameraAddr, 0x00, 0x00, 0x00, 0x00 };
unsigned char pkt[PIC_PKT_LEN];
char picName[] = "pic00.jpg";
if (SD.exists(picName))
{
SD.remove(picName);
}
myFile = SD.open(picName, FILE_WRITE);
if(!myFile){
Serial.println("myFile open fail...");
}
else{
Serial.setTimeout(1000);
for (unsigned int i = 0; i < pktCnt; i++)
{
cmd[4] = i & 0xff;
cmd[5] = (i >> 8) & 0xff;
int retry_cnt = 0;
retry:
delay(10);
clearRxBuf();
sendCmd(cmd, 6);
uint16_t cnt = Serial.readBytes((char *)pkt, PIC_PKT_LEN);
unsigned char sum = 0;
for (int y = 0; y < cnt - 2; y++)
{
sum += pkt[y];
}
if (sum != pkt[cnt-2])
{
if (++retry_cnt < 100) goto retry;
else break;
}
myFile.write((const uint8_t *)&pkt[4], cnt-6);
//if (cnt != PIC_PKT_LEN) break;
}
cmd[4] = 0xf0;
cmd[5] = 0xf0;
sendCmd(cmd, 6);
}
myFile.close();
picNameNum ++;
}